mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
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.
This commit is contained in:
parent
36f5820ad1
commit
b5e9a8262e
@ -217,8 +217,7 @@ func (s *ProxyServer) createProxier(ctx context.Context, config *proxyconfigapi.
|
|||||||
return nil, fmt.Errorf("unable to create proxier: %v", err)
|
return nil, fmt.Errorf("unable to create proxier: %v", err)
|
||||||
}
|
}
|
||||||
} else if config.Mode == proxyconfigapi.ProxyModeIPVS {
|
} else if config.Mode == proxyconfigapi.ProxyModeIPVS {
|
||||||
execer := exec.New()
|
ipsetInterface := utilipset.New()
|
||||||
ipsetInterface := utilipset.New(execer)
|
|
||||||
ipvsInterface := utilipvs.New()
|
ipvsInterface := utilipvs.New()
|
||||||
if err := ipvs.CanUseIPVSProxier(ctx, ipvsInterface, ipsetInterface, config.IPVS.Scheduler); err != nil {
|
if err := ipvs.CanUseIPVSProxier(ctx, ipvsInterface, ipsetInterface, config.IPVS.Scheduler); err != nil {
|
||||||
return nil, fmt.Errorf("can't use the IPVS proxier: %v", err)
|
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
|
|||||||
// Clean up iptables and ipvs rules if switching to nftables, or if cleanupAndExit
|
// Clean up iptables and ipvs rules if switching to nftables, or if cleanupAndExit
|
||||||
if !isIPTablesBased(mode) || cleanupAndExit {
|
if !isIPTablesBased(mode) || cleanupAndExit {
|
||||||
ipts, _ := getIPTables(v1.IPFamilyUnknown)
|
ipts, _ := getIPTables(v1.IPFamilyUnknown)
|
||||||
execer := exec.New()
|
ipsetInterface := utilipset.New()
|
||||||
ipsetInterface := utilipset.New(execer)
|
|
||||||
ipvsInterface := utilipvs.New()
|
ipvsInterface := utilipvs.New()
|
||||||
|
|
||||||
for _, ipt := range ipts {
|
for _, ipt := range ipts {
|
||||||
|
@ -278,9 +278,9 @@ type runner struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new Interface which will exec ipset.
|
// New returns a new Interface which will exec ipset.
|
||||||
func New(exec utilexec.Interface) Interface {
|
func New() Interface {
|
||||||
return &runner{
|
return &runner{
|
||||||
exec: exec,
|
exec: utilexec.New(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,10 @@ import (
|
|||||||
fakeexec "k8s.io/utils/exec/testing"
|
fakeexec "k8s.io/utils/exec/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func newInternal(fexec *fakeexec.FakeExec) Interface {
|
||||||
|
return &runner{fexec}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCheckIPSetVersion(t *testing.T) {
|
func TestCheckIPSetVersion(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
vstring string
|
vstring string
|
||||||
@ -83,7 +87,7 @@ func TestFlushSet(t *testing.T) {
|
|||||||
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)
|
runner := newInternal(fexec)
|
||||||
// Success.
|
// Success.
|
||||||
err := runner.FlushSet("FOOBAR")
|
err := runner.FlushSet("FOOBAR")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -119,7 +123,7 @@ func TestDestroySet(t *testing.T) {
|
|||||||
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)
|
runner := newInternal(fexec)
|
||||||
// Success
|
// Success
|
||||||
err := runner.DestroySet("FOOBAR")
|
err := runner.DestroySet("FOOBAR")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -153,7 +157,7 @@ func TestDestroyAllSets(t *testing.T) {
|
|||||||
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)
|
runner := newInternal(fexec)
|
||||||
// Success
|
// Success
|
||||||
err := runner.DestroyAllSets()
|
err := runner.DestroyAllSets()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -198,7 +202,7 @@ func TestCreateSet(t *testing.T) {
|
|||||||
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)
|
runner := newInternal(fexec)
|
||||||
// Create with ignoreExistErr = false, expect success
|
// Create with ignoreExistErr = false, expect success
|
||||||
err := runner.CreateSet(&testSet, false)
|
err := runner.CreateSet(&testSet, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -388,7 +392,7 @@ func TestAddEntry(t *testing.T) {
|
|||||||
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)
|
runner := newInternal(fexec)
|
||||||
// Create with ignoreExistErr = false, expect success
|
// Create with ignoreExistErr = false, expect success
|
||||||
err := runner.AddEntry(testCases[i].entry.String(), testCases[i].set, false)
|
err := runner.AddEntry(testCases[i].entry.String(), testCases[i].set, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -437,7 +441,7 @@ func TestDelEntry(t *testing.T) {
|
|||||||
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)
|
runner := newInternal(fexec)
|
||||||
|
|
||||||
err := runner.DelEntry(testCases[i].entry.String(), testCases[i].set.Name)
|
err := runner.DelEntry(testCases[i].entry.String(), testCases[i].set.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -482,7 +486,7 @@ func TestTestEntry(t *testing.T) {
|
|||||||
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)
|
runner := newInternal(fexec)
|
||||||
// Success
|
// Success
|
||||||
ok, err := runner.TestEntry(testEntry.String(), setName)
|
ok, err := runner.TestEntry(testEntry.String(), setName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -530,7 +534,7 @@ func TestTestEntryIPv6(t *testing.T) {
|
|||||||
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)
|
runner := newInternal(fexec)
|
||||||
// Success
|
// Success
|
||||||
ok, err := runner.TestEntry(testEntry.String(), setName)
|
ok, err := runner.TestEntry(testEntry.String(), setName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -604,7 +608,7 @@ Members:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runner := New(fexec)
|
runner := newInternal(fexec)
|
||||||
// Success
|
// Success
|
||||||
entries, err := runner.ListEntries("foobar")
|
entries, err := runner.ListEntries("foobar")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -643,7 +647,7 @@ baz`
|
|||||||
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)
|
runner := newInternal(fexec)
|
||||||
// Success
|
// Success
|
||||||
list, err := runner.ListSets()
|
list, err := runner.ListSets()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user