diff --git a/cmd/kube-proxy/app/server_linux.go b/cmd/kube-proxy/app/server_linux.go index 19e5170d339..9cf782c1a3f 100644 --- a/cmd/kube-proxy/app/server_linux.go +++ b/cmd/kube-proxy/app/server_linux.go @@ -109,12 +109,10 @@ func isIPTablesBased(mode proxyconfigapi.ProxyMode) bool { // is not v1.IPFamilyUnknown then it will also separately return the interface for just // that family. func getIPTables(primaryFamily v1.IPFamily) ([2]utiliptables.Interface, utiliptables.Interface) { - execer := exec.New() - // Create iptables handlers for both families. Always ordered as IPv4, IPv6 ipt := [2]utiliptables.Interface{ - utiliptables.New(execer, utiliptables.ProtocolIPv4), - utiliptables.New(execer, utiliptables.ProtocolIPv6), + utiliptables.New(utiliptables.ProtocolIPv4), + utiliptables.New(utiliptables.ProtocolIPv6), } var iptInterface utiliptables.Interface diff --git a/pkg/kubelet/kubelet_network_linux.go b/pkg/kubelet/kubelet_network_linux.go index fce57689061..b814e9b829d 100644 --- a/pkg/kubelet/kubelet_network_linux.go +++ b/pkg/kubelet/kubelet_network_linux.go @@ -25,7 +25,6 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/klog/v2" utiliptables "k8s.io/kubernetes/pkg/util/iptables" - utilexec "k8s.io/utils/exec" ) const ( @@ -38,10 +37,9 @@ const ( ) func (kl *Kubelet) initNetworkUtil() { - exec := utilexec.New() iptClients := []utiliptables.Interface{ - utiliptables.New(exec, utiliptables.ProtocolIPv4), - utiliptables.New(exec, utiliptables.ProtocolIPv6), + utiliptables.New(utiliptables.ProtocolIPv4), + utiliptables.New(utiliptables.ProtocolIPv6), } for i := range iptClients { diff --git a/pkg/util/iptables/iptables.go b/pkg/util/iptables/iptables.go index c6c64e45f73..3181f3eb21b 100644 --- a/pkg/util/iptables/iptables.go +++ b/pkg/util/iptables/iptables.go @@ -246,8 +246,8 @@ func newInternal(exec utilexec.Interface, protocol Protocol, lockfilePath14x, lo } // New returns a new Interface which will exec iptables. -func New(exec utilexec.Interface, protocol Protocol) Interface { - return newInternal(exec, protocol, "", "") +func New(protocol Protocol) Interface { + return newInternal(utilexec.New(), protocol, "", "") } // EnsureChain is part of Interface. diff --git a/pkg/util/iptables/iptables_test.go b/pkg/util/iptables/iptables_test.go index 652b7786431..480ae98e827 100644 --- a/pkg/util/iptables/iptables_test.go +++ b/pkg/util/iptables/iptables_test.go @@ -61,7 +61,7 @@ func testIPTablesVersionCmds(t *testing.T, protocol Protocol) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - _ = New(fexec, protocol) + _ = newInternal(fexec, protocol, "", "") // Check that proper iptables version command was used during runner instantiation if !sets.New(fcmd.CombinedOutputLog[0]...).HasAll(iptablesCmd, "--version") { @@ -103,7 +103,7 @@ func testEnsureChain(t *testing.T, protocol Protocol) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - runner := New(fexec, protocol) + runner := newInternal(fexec, protocol, "", "") // Success. exists, err := runner.EnsureChain(TableNAT, Chain("FOOBAR")) if err != nil { @@ -160,7 +160,7 @@ func TestFlushChain(t *testing.T) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - runner := New(fexec, ProtocolIPv4) + runner := newInternal(fexec, ProtocolIPv4, "", "") // Success. err := runner.FlushChain(TableNAT, Chain("FOOBAR")) if err != nil { @@ -197,7 +197,7 @@ func TestDeleteChain(t *testing.T) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - runner := New(fexec, ProtocolIPv4) + runner := newInternal(fexec, ProtocolIPv4, "", "") // Success. err := runner.DeleteChain(TableNAT, Chain("FOOBAR")) if err != nil { @@ -233,7 +233,7 @@ func TestEnsureRuleAlreadyExists(t *testing.T) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - runner := New(fexec, ProtocolIPv4) + runner := newInternal(fexec, ProtocolIPv4, "", "") exists, err := runner.EnsureRule(Append, TableNAT, ChainOutput, "abc", "123") if err != nil { t.Errorf("expected success, got %v", err) @@ -269,7 +269,7 @@ func TestEnsureRuleNew(t *testing.T) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - runner := New(fexec, ProtocolIPv4) + runner := newInternal(fexec, ProtocolIPv4, "", "") exists, err := runner.EnsureRule(Append, TableNAT, ChainOutput, "abc", "123") if err != nil { t.Errorf("expected success, got %v", err) @@ -302,7 +302,7 @@ func TestEnsureRuleErrorChecking(t *testing.T) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - runner := New(fexec, ProtocolIPv4) + runner := newInternal(fexec, ProtocolIPv4, "", "") _, err := runner.EnsureRule(Append, TableNAT, ChainOutput, "abc", "123") if err == nil { t.Errorf("expected failure") @@ -332,7 +332,7 @@ func TestEnsureRuleErrorCreating(t *testing.T) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - runner := New(fexec, ProtocolIPv4) + runner := newInternal(fexec, ProtocolIPv4, "", "") _, err := runner.EnsureRule(Append, TableNAT, ChainOutput, "abc", "123") if err == nil { t.Errorf("expected failure") @@ -359,7 +359,7 @@ func TestDeleteRuleDoesNotExist(t *testing.T) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - runner := New(fexec, ProtocolIPv4) + runner := newInternal(fexec, ProtocolIPv4, "", "") err := runner.DeleteRule(TableNAT, ChainOutput, "abc", "123") if err != nil { t.Errorf("expected success, got %v", err) @@ -392,7 +392,7 @@ func TestDeleteRuleExists(t *testing.T) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - runner := New(fexec, ProtocolIPv4) + runner := newInternal(fexec, ProtocolIPv4, "", "") err := runner.DeleteRule(TableNAT, ChainOutput, "abc", "123") if err != nil { t.Errorf("expected success, got %v", err) @@ -422,7 +422,7 @@ func TestDeleteRuleErrorChecking(t *testing.T) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - runner := New(fexec, ProtocolIPv4) + runner := newInternal(fexec, ProtocolIPv4, "", "") err := runner.DeleteRule(TableNAT, ChainOutput, "abc", "123") if err == nil { t.Errorf("expected failure") @@ -452,7 +452,7 @@ func TestDeleteRuleErrorDeleting(t *testing.T) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - runner := New(fexec, ProtocolIPv4) + runner := newInternal(fexec, ProtocolIPv4, "", "") err := runner.DeleteRule(TableNAT, ChainOutput, "abc", "123") if err == nil { t.Errorf("expected failure") @@ -487,7 +487,7 @@ func TestGetIPTablesHasCheckCommand(t *testing.T) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - ipt := New(fexec, ProtocolIPv4) + ipt := newInternal(fexec, ProtocolIPv4, "", "") runner := ipt.(*runner) if testCase.Expected != runner.hasCheck { t.Errorf("Expected result: %v, Got result: %v", testCase.Expected, runner.hasCheck) @@ -648,7 +648,7 @@ func TestWaitFlagUnavailable(t *testing.T) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - runner := New(fexec, ProtocolIPv4) + runner := newInternal(fexec, ProtocolIPv4, "", "") err := runner.DeleteChain(TableNAT, Chain("FOOBAR")) if err != nil { t.Errorf("expected success, got %v", err) @@ -679,7 +679,7 @@ func TestWaitFlagOld(t *testing.T) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - runner := New(fexec, ProtocolIPv4) + runner := newInternal(fexec, ProtocolIPv4, "", "") err := runner.DeleteChain(TableNAT, Chain("FOOBAR")) if err != nil { t.Errorf("expected success, got %v", err) @@ -713,7 +713,7 @@ func TestWaitFlagNew(t *testing.T) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - runner := New(fexec, ProtocolIPv4) + runner := newInternal(fexec, ProtocolIPv4, "", "") err := runner.DeleteChain(TableNAT, Chain("FOOBAR")) if err != nil { t.Errorf("expected success, got %v", err) @@ -744,7 +744,7 @@ func TestWaitIntervalFlagNew(t *testing.T) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - runner := New(fexec, ProtocolIPv4) + runner := newInternal(fexec, ProtocolIPv4, "", "") err := runner.DeleteChain(TableNAT, Chain("FOOBAR")) if err != nil { t.Errorf("expected success, got %v", err) @@ -789,7 +789,7 @@ COMMIT func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - runner := New(fexec, protocol) + runner := newInternal(fexec, protocol, "", "") buffer := bytes.NewBuffer(nil) // Success. @@ -857,7 +857,7 @@ func testRestore(t *testing.T, protocol Protocol) { func(cmd string, args ...string) exec.Cmd { return fakeexec.InitFakeCmd(&fcmd, cmd, args...) }, }, } - runner := New(fexec, protocol) + runner := newInternal(fexec, protocol, "", "") // both flags true err := runner.Restore(TableNAT, []byte{}, FlushTables, RestoreCounters) diff --git a/pkg/util/iptables/monitor_test.go b/pkg/util/iptables/monitor_test.go index de522c59ef6..223fbaa04e0 100644 --- a/pkg/util/iptables/monitor_test.go +++ b/pkg/util/iptables/monitor_test.go @@ -191,7 +191,7 @@ func (mfc *monitorFakeCmd) Stop() { func TestIPTablesMonitor(t *testing.T) { mfe := newMonitorFakeExec() - ipt := New(mfe, ProtocolIPv4) + ipt := newInternal(mfe, ProtocolIPv4, "", "") var reloads uint32 stopCh := make(chan struct{})