mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
Merge pull request #53120 from m1093782566/fake-ipv6
Automatic merge from submit-queue (batch tested with PRs 53227, 53120). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. remove ipv4 in pkg/util/ipvs **What this PR does / why we need it**: remove ipv4 in util/ipvs **Which issue this PR fixes**: xref: #51866 **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
3b1b19a1e2
@ -53,7 +53,7 @@ func New(exec utilexec.Interface) Interface {
|
|||||||
|
|
||||||
// EnsureVirtualServerAddressBind is part of Interface.
|
// EnsureVirtualServerAddressBind is part of Interface.
|
||||||
func (runner *runner) EnsureVirtualServerAddressBind(vs *VirtualServer, dummyDev string) (exist bool, err error) {
|
func (runner *runner) EnsureVirtualServerAddressBind(vs *VirtualServer, dummyDev string) (exist bool, err error) {
|
||||||
addr := vs.Address.String() + "/32"
|
addr := vs.Address.String()
|
||||||
args := []string{"addr", "add", addr, "dev", dummyDev}
|
args := []string{"addr", "add", addr, "dev", dummyDev}
|
||||||
out, err := runner.exec.Command(cmdIP, args...).CombinedOutput()
|
out, err := runner.exec.Command(cmdIP, args...).CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -70,7 +70,7 @@ func (runner *runner) EnsureVirtualServerAddressBind(vs *VirtualServer, dummyDev
|
|||||||
|
|
||||||
// UnbindVirtualServerAddress is part of Interface.
|
// UnbindVirtualServerAddress is part of Interface.
|
||||||
func (runner *runner) UnbindVirtualServerAddress(vs *VirtualServer, dummyDev string) error {
|
func (runner *runner) UnbindVirtualServerAddress(vs *VirtualServer, dummyDev string) error {
|
||||||
addr := vs.Address.String() + "/32"
|
addr := vs.Address.String()
|
||||||
args := []string{"addr", "del", addr, "dev", dummyDev}
|
args := []string{"addr", "del", addr, "dev", dummyDev}
|
||||||
out, err := runner.exec.Command(cmdIP, args...).CombinedOutput()
|
out, err := runner.exec.Command(cmdIP, args...).CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -35,11 +35,20 @@ import (
|
|||||||
const dummyDevice = "kube-ipvs0"
|
const dummyDevice = "kube-ipvs0"
|
||||||
|
|
||||||
func TestEnsureVirtualServerAddressBind(t *testing.T) {
|
func TestEnsureVirtualServerAddressBind(t *testing.T) {
|
||||||
vs := &VirtualServer{
|
tests := []VirtualServer{
|
||||||
|
{
|
||||||
Address: net.ParseIP("10.20.30.40"),
|
Address: net.ParseIP("10.20.30.40"),
|
||||||
Port: uint16(1234),
|
Port: uint16(1234),
|
||||||
Protocol: string("TCP"),
|
Protocol: string("TCP"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Address: net.ParseIP("2012::beef"),
|
||||||
|
Port: uint16(5678),
|
||||||
|
Protocol: string("UDP"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
for i := range tests {
|
||||||
|
vs := &tests[i]
|
||||||
fcmd := fakeexec.FakeCmd{
|
fcmd := fakeexec.FakeCmd{
|
||||||
CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{
|
CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{
|
||||||
// Success.
|
// Success.
|
||||||
@ -66,7 +75,8 @@ func TestEnsureVirtualServerAddressBind(t *testing.T) {
|
|||||||
if fcmd.CombinedOutputCalls != 1 {
|
if fcmd.CombinedOutputCalls != 1 {
|
||||||
t.Errorf("expected 1 CombinedOutput() calls, got %d", fcmd.CombinedOutputCalls)
|
t.Errorf("expected 1 CombinedOutput() calls, got %d", fcmd.CombinedOutputCalls)
|
||||||
}
|
}
|
||||||
if !sets.NewString(fcmd.CombinedOutputLog[0]...).HasAll("ip", "addr", "add", "10.20.30.40/32", "dev", "kube-ipvs0") {
|
IP := tests[i].Address.String()
|
||||||
|
if !sets.NewString(fcmd.CombinedOutputLog[0]...).HasAll("ip", "addr", "add", IP, "dev", dummyDevice) {
|
||||||
t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[0])
|
t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[0])
|
||||||
}
|
}
|
||||||
// Exists.
|
// Exists.
|
||||||
@ -78,45 +88,65 @@ func TestEnsureVirtualServerAddressBind(t *testing.T) {
|
|||||||
t.Errorf("expected exists = true")
|
t.Errorf("expected exists = true")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestUnbindVirtualServerAddress(t *testing.T) {
|
func TestUnbindVirtualServerAddress(t *testing.T) {
|
||||||
svc := &VirtualServer{
|
tests := []VirtualServer{
|
||||||
Address: net.ParseIP("10.20.30.41"),
|
{
|
||||||
Port: uint16(80),
|
Address: net.ParseIP("2012::beef"),
|
||||||
|
Port: uint16(5678),
|
||||||
|
Protocol: string("UDP"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Address: net.ParseIP("10.20.30.40"),
|
||||||
|
Port: uint16(1234),
|
||||||
Protocol: string("TCP"),
|
Protocol: string("TCP"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
for i := range tests {
|
||||||
|
vs := &tests[i]
|
||||||
fcmd := fakeexec.FakeCmd{
|
fcmd := fakeexec.FakeCmd{
|
||||||
CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{
|
CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{
|
||||||
// Success.
|
// Success.
|
||||||
func() ([]byte, error) { return []byte{}, nil },
|
func() ([]byte, error) {
|
||||||
|
return []byte{}, nil
|
||||||
|
},
|
||||||
// Failure.
|
// Failure.
|
||||||
func() ([]byte, error) { return nil, &fakeexec.FakeExitError{Status: 2} },
|
func() ([]byte, error) {
|
||||||
|
return nil, &fakeexec.FakeExitError{Status: 2}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
fexec := fakeexec.FakeExec{
|
fexec := fakeexec.FakeExec{
|
||||||
CommandScript: []fakeexec.FakeCommandAction{
|
CommandScript: []fakeexec.FakeCommandAction{
|
||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
func(cmd string, args ...string) exec.Cmd {
|
||||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
return fakeexec.InitFakeCmd(&fcmd, cmd, args...)
|
||||||
|
},
|
||||||
|
func(cmd string, args ...string) exec.Cmd {
|
||||||
|
return fakeexec.InitFakeCmd(&fcmd, cmd, args...)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := New(&fexec)
|
runner := New(&fexec)
|
||||||
// Success.
|
// Success.
|
||||||
err := runner.UnbindVirtualServerAddress(svc, dummyDevice)
|
err := runner.UnbindVirtualServerAddress(vs, dummyDevice)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expected success, got %v", err)
|
t.Errorf("expected success, got %v", err)
|
||||||
}
|
}
|
||||||
if fcmd.CombinedOutputCalls != 1 {
|
if fcmd.CombinedOutputCalls != 1 {
|
||||||
t.Errorf("expected 1 CombinedOutput() calls, got %d", fcmd.CombinedOutputCalls)
|
t.Errorf("expected 1 CombinedOutput() calls, got %d", fcmd.CombinedOutputCalls)
|
||||||
}
|
}
|
||||||
if !sets.NewString(fcmd.CombinedOutputLog[0]...).HasAll("ip", "addr", "del", "10.20.30.41/32", "dev", "kube-ipvs0") {
|
IP := tests[i].Address.String()
|
||||||
|
if !sets.NewString(fcmd.CombinedOutputLog[0]...).HasAll("ip", "addr", "del", IP, "dev", dummyDevice) {
|
||||||
t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[0])
|
t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[0])
|
||||||
}
|
}
|
||||||
// Failure.
|
// Failure.
|
||||||
err = runner.UnbindVirtualServerAddress(svc, dummyDevice)
|
err = runner.UnbindVirtualServerAddress(vs, dummyDevice)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("expected failure")
|
t.Errorf("expected failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Test_toVirtualServer(t *testing.T) {
|
func Test_toVirtualServer(t *testing.T) {
|
||||||
Tests := []struct {
|
Tests := []struct {
|
||||||
|
@ -49,7 +49,7 @@ func NewFake() *FakeIPVS {
|
|||||||
|
|
||||||
func toServiceKey(serv *utilipvs.VirtualServer) serviceKey {
|
func toServiceKey(serv *utilipvs.VirtualServer) serviceKey {
|
||||||
return serviceKey{
|
return serviceKey{
|
||||||
IP: serv.Address.To4().String(),
|
IP: serv.Address.String(),
|
||||||
Port: serv.Port,
|
Port: serv.Port,
|
||||||
Protocol: serv.Protocol,
|
Protocol: serv.Protocol,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user