mirror of https://github.com/k3s-io/k3s
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 ```pull/6/head
commit
3b1b19a1e2
|
@ -53,7 +53,7 @@ func New(exec utilexec.Interface) Interface {
|
|||
|
||||
// EnsureVirtualServerAddressBind is part of Interface.
|
||||
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}
|
||||
out, err := runner.exec.Command(cmdIP, args...).CombinedOutput()
|
||||
if err != nil {
|
||||
|
@ -70,7 +70,7 @@ func (runner *runner) EnsureVirtualServerAddressBind(vs *VirtualServer, dummyDev
|
|||
|
||||
// UnbindVirtualServerAddress is part of Interface.
|
||||
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}
|
||||
out, err := runner.exec.Command(cmdIP, args...).CombinedOutput()
|
||||
if err != nil {
|
||||
|
|
|
@ -35,11 +35,20 @@ import (
|
|||
const dummyDevice = "kube-ipvs0"
|
||||
|
||||
func TestEnsureVirtualServerAddressBind(t *testing.T) {
|
||||
vs := &VirtualServer{
|
||||
tests := []VirtualServer{
|
||||
{
|
||||
Address: net.ParseIP("10.20.30.40"),
|
||||
Port: uint16(1234),
|
||||
Protocol: string("TCP"),
|
||||
},
|
||||
{
|
||||
Address: net.ParseIP("2012::beef"),
|
||||
Port: uint16(5678),
|
||||
Protocol: string("UDP"),
|
||||
},
|
||||
}
|
||||
for i := range tests {
|
||||
vs := &tests[i]
|
||||
fcmd := fakeexec.FakeCmd{
|
||||
CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{
|
||||
// Success.
|
||||
|
@ -66,7 +75,8 @@ func TestEnsureVirtualServerAddressBind(t *testing.T) {
|
|||
if fcmd.CombinedOutputCalls != 1 {
|
||||
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])
|
||||
}
|
||||
// Exists.
|
||||
|
@ -78,45 +88,65 @@ func TestEnsureVirtualServerAddressBind(t *testing.T) {
|
|||
t.Errorf("expected exists = true")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnbindVirtualServerAddress(t *testing.T) {
|
||||
svc := &VirtualServer{
|
||||
Address: net.ParseIP("10.20.30.41"),
|
||||
Port: uint16(80),
|
||||
tests := []VirtualServer{
|
||||
{
|
||||
Address: net.ParseIP("2012::beef"),
|
||||
Port: uint16(5678),
|
||||
Protocol: string("UDP"),
|
||||
},
|
||||
{
|
||||
Address: net.ParseIP("10.20.30.40"),
|
||||
Port: uint16(1234),
|
||||
Protocol: string("TCP"),
|
||||
},
|
||||
}
|
||||
for i := range tests {
|
||||
vs := &tests[i]
|
||||
fcmd := fakeexec.FakeCmd{
|
||||
CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{
|
||||
// Success.
|
||||
func() ([]byte, error) { return []byte{}, nil },
|
||||
func() ([]byte, error) {
|
||||
return []byte{}, nil
|
||||
},
|
||||
// Failure.
|
||||
func() ([]byte, error) { return nil, &fakeexec.FakeExitError{Status: 2} },
|
||||
func() ([]byte, error) {
|
||||
return nil, &fakeexec.FakeExitError{Status: 2}
|
||||
},
|
||||
},
|
||||
}
|
||||
fexec := fakeexec.FakeExec{
|
||||
CommandScript: []fakeexec.FakeCommandAction{
|
||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
|
||||
func(cmd string, args ...string) exec.Cmd {
|
||||
return fakeexec.InitFakeCmd(&fcmd, cmd, args...)
|
||||
},
|
||||
func(cmd string, args ...string) exec.Cmd {
|
||||
return fakeexec.InitFakeCmd(&fcmd, cmd, args...)
|
||||
},
|
||||
},
|
||||
}
|
||||
runner := New(&fexec)
|
||||
// Success.
|
||||
err := runner.UnbindVirtualServerAddress(svc, dummyDevice)
|
||||
err := runner.UnbindVirtualServerAddress(vs, dummyDevice)
|
||||
if err != nil {
|
||||
t.Errorf("expected success, got %v", err)
|
||||
}
|
||||
if fcmd.CombinedOutputCalls != 1 {
|
||||
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])
|
||||
}
|
||||
// Failure.
|
||||
err = runner.UnbindVirtualServerAddress(svc, dummyDevice)
|
||||
err = runner.UnbindVirtualServerAddress(vs, dummyDevice)
|
||||
if err == nil {
|
||||
t.Errorf("expected failure")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_toVirtualServer(t *testing.T) {
|
||||
Tests := []struct {
|
||||
|
|
|
@ -49,7 +49,7 @@ func NewFake() *FakeIPVS {
|
|||
|
||||
func toServiceKey(serv *utilipvs.VirtualServer) serviceKey {
|
||||
return serviceKey{
|
||||
IP: serv.Address.To4().String(),
|
||||
IP: serv.Address.String(),
|
||||
Port: serv.Port,
|
||||
Protocol: serv.Protocol,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue