Skip to content

Commit b5e9a82

Browse files
committed
Remove exec arg from utilipset.New
Historically it took an exec argument so you could pass a FakeExec to mock its behavior in unit tests, but it has a fake implementation now that is much more useful for unit tests than trying to use the real implementation with a fake exec. (The unit tests still use fake execs, but they don't need to use a public constructor.) So remove the exec args from the public constructors.
1 parent 36f5820 commit b5e9a82

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

cmd/kube-proxy/app/server_linux.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ func (s *ProxyServer) createProxier(ctx context.Context, config *proxyconfigapi.
217217
return nil, fmt.Errorf("unable to create proxier: %v", err)
218218
}
219219
} else if config.Mode == proxyconfigapi.ProxyModeIPVS {
220-
execer := exec.New()
221-
ipsetInterface := utilipset.New(execer)
220+
ipsetInterface := utilipset.New()
222221
ipvsInterface := utilipvs.New()
223222
if err := ipvs.CanUseIPVSProxier(ctx, ipvsInterface, ipsetInterface, config.IPVS.Scheduler); err != nil {
224223
return nil, fmt.Errorf("can't use the IPVS proxier: %v", err)
@@ -511,8 +510,7 @@ func platformCleanup(ctx context.Context, mode proxyconfigapi.ProxyMode, cleanup
511510
// Clean up iptables and ipvs rules if switching to nftables, or if cleanupAndExit
512511
if !isIPTablesBased(mode) || cleanupAndExit {
513512
ipts, _ := getIPTables(v1.IPFamilyUnknown)
514-
execer := exec.New()
515-
ipsetInterface := utilipset.New(execer)
513+
ipsetInterface := utilipset.New()
516514
ipvsInterface := utilipvs.New()
517515

518516
for _, ipt := range ipts {

pkg/proxy/ipvs/ipset/ipset.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ type runner struct {
278278
}
279279

280280
// New returns a new Interface which will exec ipset.
281-
func New(exec utilexec.Interface) Interface {
281+
func New() Interface {
282282
return &runner{
283-
exec: exec,
283+
exec: utilexec.New(),
284284
}
285285
}
286286

pkg/proxy/ipvs/ipset/ipset_test.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ import (
2828
fakeexec "k8s.io/utils/exec/testing"
2929
)
3030

31+
func newInternal(fexec *fakeexec.FakeExec) Interface {
32+
return &runner{fexec}
33+
}
34+
3135
func TestCheckIPSetVersion(t *testing.T) {
3236
testCases := []struct {
3337
vstring string
@@ -83,7 +87,7 @@ func TestFlushSet(t *testing.T) {
8387
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
8488
},
8589
}
86-
runner := New(fexec)
90+
runner := newInternal(fexec)
8791
// Success.
8892
err := runner.FlushSet("FOOBAR")
8993
if err != nil {
@@ -119,7 +123,7 @@ func TestDestroySet(t *testing.T) {
119123
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
120124
},
121125
}
122-
runner := New(fexec)
126+
runner := newInternal(fexec)
123127
// Success
124128
err := runner.DestroySet("FOOBAR")
125129
if err != nil {
@@ -153,7 +157,7 @@ func TestDestroyAllSets(t *testing.T) {
153157
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
154158
},
155159
}
156-
runner := New(fexec)
160+
runner := newInternal(fexec)
157161
// Success
158162
err := runner.DestroyAllSets()
159163
if err != nil {
@@ -198,7 +202,7 @@ func TestCreateSet(t *testing.T) {
198202
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
199203
},
200204
}
201-
runner := New(fexec)
205+
runner := newInternal(fexec)
202206
// Create with ignoreExistErr = false, expect success
203207
err := runner.CreateSet(&testSet, false)
204208
if err != nil {
@@ -388,7 +392,7 @@ func TestAddEntry(t *testing.T) {
388392
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
389393
},
390394
}
391-
runner := New(fexec)
395+
runner := newInternal(fexec)
392396
// Create with ignoreExistErr = false, expect success
393397
err := runner.AddEntry(testCases[i].entry.String(), testCases[i].set, false)
394398
if err != nil {
@@ -437,7 +441,7 @@ func TestDelEntry(t *testing.T) {
437441
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
438442
},
439443
}
440-
runner := New(fexec)
444+
runner := newInternal(fexec)
441445

442446
err := runner.DelEntry(testCases[i].entry.String(), testCases[i].set.Name)
443447
if err != nil {
@@ -482,7 +486,7 @@ func TestTestEntry(t *testing.T) {
482486
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
483487
},
484488
}
485-
runner := New(fexec)
489+
runner := newInternal(fexec)
486490
// Success
487491
ok, err := runner.TestEntry(testEntry.String(), setName)
488492
if err != nil {
@@ -530,7 +534,7 @@ func TestTestEntryIPv6(t *testing.T) {
530534
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
531535
},
532536
}
533-
runner := New(fexec)
537+
runner := newInternal(fexec)
534538
// Success
535539
ok, err := runner.TestEntry(testEntry.String(), setName)
536540
if err != nil {
@@ -604,7 +608,7 @@ Members:
604608
},
605609
},
606610
}
607-
runner := New(fexec)
611+
runner := newInternal(fexec)
608612
// Success
609613
entries, err := runner.ListEntries("foobar")
610614
if err != nil {
@@ -643,7 +647,7 @@ baz`
643647
func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) },
644648
},
645649
}
646-
runner := New(fexec)
650+
runner := newInternal(fexec)
647651
// Success
648652
list, err := runner.ListSets()
649653
if err != nil {

0 commit comments

Comments
 (0)