Skip to content

Commit

Permalink
Merge pull request kubernetes#53120 from m1093782566/fake-ipv6
Browse files Browse the repository at this point in the history
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: kubernetes#51866


**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
  • Loading branch information
Kubernetes Submit Queue authored Oct 5, 2017
2 parents 86b23df + 074c846 commit 3b1b19a
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 73 deletions.
4 changes: 2 additions & 2 deletions pkg/util/ipvs/ipvs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
170 changes: 100 additions & 70 deletions pkg/util/ipvs/ipvs_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,86 +35,116 @@ import (
const dummyDevice = "kube-ipvs0"

func TestEnsureVirtualServerAddressBind(t *testing.T) {
vs := &VirtualServer{
Address: net.ParseIP("10.20.30.40"),
Port: uint16(1234),
Protocol: string("TCP"),
}
fcmd := fakeexec.FakeCmd{
CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{
// Success.
func() ([]byte, error) { return []byte{}, nil },
// Exists.
func() ([]byte, error) { return nil, &fakeexec.FakeExitError{Status: 2} },
tests := []VirtualServer{
{
Address: net.ParseIP("10.20.30.40"),
Port: uint16(1234),
Protocol: string("TCP"),
},
}
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...) },
{
Address: net.ParseIP("2012::beef"),
Port: uint16(5678),
Protocol: string("UDP"),
},
}
runner := New(&fexec)
// Success.
exists, err := runner.EnsureVirtualServerAddressBind(vs, dummyDevice)
if err != nil {
t.Errorf("expected success, got %v", err)
}
if exists {
t.Errorf("expected exists = false")
}
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") {
t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[0])
}
// Exists.
exists, err = runner.EnsureVirtualServerAddressBind(vs, dummyDevice)
if err != nil {
t.Errorf("expected success, got %v", err)
}
if !exists {
t.Errorf("expected exists = true")
for i := range tests {
vs := &tests[i]
fcmd := fakeexec.FakeCmd{
CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{
// Success.
func() ([]byte, error) { return []byte{}, nil },
// Exists.
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...) },
},
}
runner := New(&fexec)
// Success.
exists, err := runner.EnsureVirtualServerAddressBind(vs, dummyDevice)
if err != nil {
t.Errorf("expected success, got %v", err)
}
if exists {
t.Errorf("expected exists = false")
}
if fcmd.CombinedOutputCalls != 1 {
t.Errorf("expected 1 CombinedOutput() calls, got %d", fcmd.CombinedOutputCalls)
}
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.
exists, err = runner.EnsureVirtualServerAddressBind(vs, dummyDevice)
if err != nil {
t.Errorf("expected success, got %v", err)
}
if !exists {
t.Errorf("expected exists = true")
}
}
}

func TestUnbindVirtualServerAddress(t *testing.T) {
svc := &VirtualServer{
Address: net.ParseIP("10.20.30.41"),
Port: uint16(80),
Protocol: string("TCP"),
}
fcmd := fakeexec.FakeCmd{
CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{
// Success.
func() ([]byte, error) { return []byte{}, nil },
// Failure.
func() ([]byte, error) { return nil, &fakeexec.FakeExitError{Status: 2} },
tests := []VirtualServer{
{
Address: net.ParseIP("2012::beef"),
Port: uint16(5678),
Protocol: string("UDP"),
},
}
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...) },
{
Address: net.ParseIP("10.20.30.40"),
Port: uint16(1234),
Protocol: string("TCP"),
},
}
runner := New(&fexec)
// Success.
err := runner.UnbindVirtualServerAddress(svc, 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") {
t.Errorf("wrong CombinedOutput() log, got %s", fcmd.CombinedOutputLog[0])
}
// Failure.
err = runner.UnbindVirtualServerAddress(svc, dummyDevice)
if err == nil {
t.Errorf("expected failure")
for i := range tests {
vs := &tests[i]
fcmd := fakeexec.FakeCmd{
CombinedOutputScript: []fakeexec.FakeCombinedOutputAction{
// Success.
func() ([]byte, error) {
return []byte{}, nil
},
// Failure.
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...)
},
},
}
runner := New(&fexec)
// Success.
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)
}
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(vs, dummyDevice)
if err == nil {
t.Errorf("expected failure")
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/util/ipvs/testing/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit 3b1b19a

Please sign in to comment.