Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 66 additions & 66 deletions npm/pkg/dataplane/policies/chain-management_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ func TestDetectIptablesVersion(t *testing.T) {
ExitCode: 1,
},
{
Cmd: []string{"iptables", "-w", "60", "-L", "KUBE-IPTABLES-HINT", "-t", "mangle", "-n"},
Cmd: []string{"iptables-legacy", "-w", "60", "-L", "KUBE-IPTABLES-HINT", "-t", "mangle", "-n"},
ExitCode: 0,
},
},
Expand All @@ -954,11 +954,11 @@ func TestDetectIptablesVersion(t *testing.T) {
ExitCode: 1,
},
{
Cmd: []string{"iptables", "-w", "60", "-L", "KUBE-IPTABLES-HINT", "-t", "mangle", "-n"},
Cmd: []string{"iptables-legacy", "-w", "60", "-L", "KUBE-IPTABLES-HINT", "-t", "mangle", "-n"},
ExitCode: 1,
},
{
Cmd: []string{"iptables", "-w", "60", "-L", "KUBE-KUBELET-CANARY", "-t", "mangle", "-n"},
Cmd: []string{"iptables-legacy", "-w", "60", "-L", "KUBE-KUBELET-CANARY", "-t", "mangle", "-n"},
ExitCode: 1,
},
},
Expand All @@ -976,11 +976,11 @@ func TestDetectIptablesVersion(t *testing.T) {
ExitCode: 2,
},
{
Cmd: []string{"iptables", "-w", "60", "-L", "KUBE-IPTABLES-HINT", "-t", "mangle", "-n"},
Cmd: []string{"iptables-legacy", "-w", "60", "-L", "KUBE-IPTABLES-HINT", "-t", "mangle", "-n"},
ExitCode: 2,
},
{
Cmd: []string{"iptables", "-w", "60", "-L", "KUBE-KUBELET-CANARY", "-t", "mangle", "-n"},
Cmd: []string{"iptables-legacy", "-w", "60", "-L", "KUBE-KUBELET-CANARY", "-t", "mangle", "-n"},
ExitCode: 2,
},
},
Expand Down Expand Up @@ -1027,12 +1027,12 @@ func TestCleanupOtherChains(t *testing.T) {
name: "cleanup legacy jump no chains",
startWithNft: true,
calls: []testutils.TestCmd{
{Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"}}, // deprecated rule existed
{Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"}}, // deprecated rule existed
{
Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"},
Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"},
ExitCode: 1,
},
{Cmd: []string{"iptables", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true},
{Cmd: []string{"iptables-legacy", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true},
{
Cmd: []string{"grep", "Chain AZURE-NPM"},
ExitCode: 1,
Expand All @@ -1044,19 +1044,19 @@ func TestCleanupOtherChains(t *testing.T) {
name: "cleanup legacy jump and chains",
startWithNft: true,
calls: []testutils.TestCmd{
{Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"}}, // deprecated rule existed
{Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"}}, // deprecated rule existed
{
Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"},
Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"},
ExitCode: 1,
},
{Cmd: []string{"iptables", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true},
{Cmd: []string{"iptables-legacy", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true},
{
Cmd: []string{"grep", "Chain AZURE-NPM"},
Stdout: grepOutputTwoAzureChains,
},
{Cmd: []string{"iptables-restore", "-w", "60", "-T", "filter", "--noflush"}},
{Cmd: []string{"iptables", "-w", "60", "-X", "AZURE-NPM"}},
{Cmd: []string{"iptables", "-w", "60", "-X", "AZURE-NPM-INGRESS"}},
{Cmd: []string{"iptables-legacy-restore", "-w", "60", "-T", "filter", "--noflush"}},
{Cmd: []string{"iptables-legacy", "-w", "60", "-X", "AZURE-NPM"}},
{Cmd: []string{"iptables-legacy", "-w", "60", "-X", "AZURE-NPM-INGRESS"}},
},
expectedErr: false,
},
Expand All @@ -1065,30 +1065,30 @@ func TestCleanupOtherChains(t *testing.T) {
startWithNft: true,
calls: []testutils.TestCmd{
{
Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"},
Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"},
ExitCode: 1,
},
{
Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"},
Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"},
ExitCode: 1,
},
{Cmd: []string{"iptables", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true},
{Cmd: []string{"iptables-legacy", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true},
{
Cmd: []string{"grep", "Chain AZURE-NPM"},
Stdout: grepOutputTwoAzureChains,
},
{
Cmd: []string{"iptables-restore", "-w", "60", "-T", "filter", "--noflush"},
Cmd: []string{"iptables-legacy-restore", "-w", "60", "-T", "filter", "--noflush"},
ExitCode: 1,
},
{
Cmd: []string{"iptables-restore", "-w", "60", "-T", "filter", "--noflush"},
Cmd: []string{"iptables-legacy-restore", "-w", "60", "-T", "filter", "--noflush"},
ExitCode: 1,
},
{Cmd: []string{"iptables", "-w", "60", "-F", "AZURE-NPM"}},
{Cmd: []string{"iptables", "-w", "60", "-F", "AZURE-NPM-INGRESS"}},
{Cmd: []string{"iptables", "-w", "60", "-X", "AZURE-NPM"}},
{Cmd: []string{"iptables", "-w", "60", "-X", "AZURE-NPM-INGRESS"}},
{Cmd: []string{"iptables-legacy", "-w", "60", "-F", "AZURE-NPM"}},
{Cmd: []string{"iptables-legacy", "-w", "60", "-F", "AZURE-NPM-INGRESS"}},
{Cmd: []string{"iptables-legacy", "-w", "60", "-X", "AZURE-NPM"}},
{Cmd: []string{"iptables-legacy", "-w", "60", "-X", "AZURE-NPM-INGRESS"}},
},
expectedErr: false,
},
Expand All @@ -1097,28 +1097,28 @@ func TestCleanupOtherChains(t *testing.T) {
startWithNft: true,
calls: []testutils.TestCmd{
{
Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"},
Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"},
ExitCode: 1,
},
{
Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"},
Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"},
ExitCode: 1,
},
{Cmd: []string{"iptables", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true},
{Cmd: []string{"iptables-legacy", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true},
{
Cmd: []string{"grep", "Chain AZURE-NPM"},
Stdout: grepOutputTwoAzureChains,
},
{
Cmd: []string{"iptables-restore", "-w", "60", "-T", "filter", "--noflush"},
Cmd: []string{"iptables-legacy-restore", "-w", "60", "-T", "filter", "--noflush"},
ExitCode: 1,
},
{
Cmd: []string{"iptables-restore", "-w", "60", "-T", "filter", "--noflush"},
Cmd: []string{"iptables-legacy-restore", "-w", "60", "-T", "filter", "--noflush"},
ExitCode: 1,
},
{
Cmd: []string{"iptables", "-w", "60", "-F", "AZURE-NPM"},
Cmd: []string{"iptables-legacy", "-w", "60", "-F", "AZURE-NPM"},
ExitCode: 1,
},
},
Expand All @@ -1129,28 +1129,28 @@ func TestCleanupOtherChains(t *testing.T) {
startWithNft: true,
calls: []testutils.TestCmd{
{
Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"},
Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"},
ExitCode: 1,
},
{
Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"},
Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"},
ExitCode: 1,
},
{Cmd: []string{"iptables", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true},
{Cmd: []string{"iptables-legacy", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true},
{
Cmd: []string{"grep", "Chain AZURE-NPM"},
Stdout: "Chain AZURE-NPM-INGRESS (1 references)\n",
},
{
Cmd: []string{"iptables-restore", "-w", "60", "-T", "filter", "--noflush"},
Cmd: []string{"iptables-legacy-restore", "-w", "60", "-T", "filter", "--noflush"},
ExitCode: 1,
},
{
Cmd: []string{"iptables-restore", "-w", "60", "-T", "filter", "--noflush"},
Cmd: []string{"iptables-legacy-restore", "-w", "60", "-T", "filter", "--noflush"},
ExitCode: 1,
},
{Cmd: []string{"iptables", "-w", "60", "-F", "AZURE-NPM-INGRESS"}},
{Cmd: []string{"iptables", "-w", "60", "-X", "AZURE-NPM-INGRESS"}},
{Cmd: []string{"iptables-legacy", "-w", "60", "-F", "AZURE-NPM-INGRESS"}},
{Cmd: []string{"iptables-legacy", "-w", "60", "-X", "AZURE-NPM-INGRESS"}},
},
expectedErr: false,
},
Expand All @@ -1159,37 +1159,37 @@ func TestCleanupOtherChains(t *testing.T) {
startWithNft: true,
calls: []testutils.TestCmd{
{
Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"},
Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"},
ExitCode: 1,
},
{Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"}},
{Cmd: []string{"iptables", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true},
{Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"}},
{Cmd: []string{"iptables-legacy", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true},
{
Cmd: []string{"grep", "Chain AZURE-NPM"},
Stdout: grepOutputTwoAzureChains,
},
{
Cmd: []string{"iptables-restore", "-w", "60", "-T", "filter", "--noflush"},
Cmd: []string{"iptables-legacy-restore", "-w", "60", "-T", "filter", "--noflush"},
ExitCode: 1,
},
{
Cmd: []string{"iptables-restore", "-w", "60", "-T", "filter", "--noflush"},
Cmd: []string{"iptables-legacy-restore", "-w", "60", "-T", "filter", "--noflush"},
ExitCode: 1,
},
{
Cmd: []string{"iptables", "-w", "60", "-F", "AZURE-NPM"},
Cmd: []string{"iptables-legacy", "-w", "60", "-F", "AZURE-NPM"},
ExitCode: 1,
},
{
Cmd: []string{"iptables", "-w", "60", "-F", "AZURE-NPM-INGRESS"},
Cmd: []string{"iptables-legacy", "-w", "60", "-F", "AZURE-NPM-INGRESS"},
ExitCode: 1,
},
{
Cmd: []string{"iptables", "-w", "60", "-X", "AZURE-NPM"},
Cmd: []string{"iptables-legacy", "-w", "60", "-X", "AZURE-NPM"},
ExitCode: 1,
},
{
Cmd: []string{"iptables", "-w", "60", "-X", "AZURE-NPM-INGRESS"},
Cmd: []string{"iptables-legacy", "-w", "60", "-X", "AZURE-NPM-INGRESS"},
ExitCode: 1,
},
},
Expand All @@ -1199,38 +1199,38 @@ func TestCleanupOtherChains(t *testing.T) {
name: "cleanup legacy errors ok if deleted jump (deprecated)",
startWithNft: true,
calls: []testutils.TestCmd{
{Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"}},
{Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"}},
{
Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"},
Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"},
ExitCode: 1,
},
{Cmd: []string{"iptables", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true},
{Cmd: []string{"iptables-legacy", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true},
{
Cmd: []string{"grep", "Chain AZURE-NPM"},
Stdout: grepOutputTwoAzureChains,
},
{
Cmd: []string{"iptables-restore", "-w", "60", "-T", "filter", "--noflush"},
Cmd: []string{"iptables-legacy-restore", "-w", "60", "-T", "filter", "--noflush"},
ExitCode: 1,
},
{
Cmd: []string{"iptables-restore", "-w", "60", "-T", "filter", "--noflush"},
Cmd: []string{"iptables-legacy-restore", "-w", "60", "-T", "filter", "--noflush"},
ExitCode: 1,
},
{
Cmd: []string{"iptables", "-w", "60", "-F", "AZURE-NPM"},
Cmd: []string{"iptables-legacy", "-w", "60", "-F", "AZURE-NPM"},
ExitCode: 2,
},
{
Cmd: []string{"iptables", "-w", "60", "-F", "AZURE-NPM-INGRESS"},
Cmd: []string{"iptables-legacy", "-w", "60", "-F", "AZURE-NPM-INGRESS"},
ExitCode: 2,
},
{
Cmd: []string{"iptables", "-w", "60", "-X", "AZURE-NPM"},
Cmd: []string{"iptables-legacy", "-w", "60", "-X", "AZURE-NPM"},
ExitCode: 2,
},
{
Cmd: []string{"iptables", "-w", "60", "-X", "AZURE-NPM-INGRESS"},
Cmd: []string{"iptables-legacy", "-w", "60", "-X", "AZURE-NPM-INGRESS"},
ExitCode: 2,
},
},
Expand All @@ -1240,35 +1240,35 @@ func TestCleanupOtherChains(t *testing.T) {
name: "cleanup legacy other flush errors ok",
startWithNft: true,
calls: []testutils.TestCmd{
{Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"}},
{Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"}},
{
Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"},
Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"},
ExitCode: 1,
},
{
Cmd: []string{"iptables", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true,
Cmd: []string{"iptables-legacy", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true,
ExitCode: 1,
},
{
Cmd: []string{"grep", "Chain AZURE-NPM"},
Stdout: grepOutputTwoAzureChains,
},
{
Cmd: []string{"iptables-restore", "-w", "60", "-T", "filter", "--noflush"},
Cmd: []string{"iptables-legacy-restore", "-w", "60", "-T", "filter", "--noflush"},
ExitCode: 1,
},
{
Cmd: []string{"iptables-restore", "-w", "60", "-T", "filter", "--noflush"},
Cmd: []string{"iptables-legacy-restore", "-w", "60", "-T", "filter", "--noflush"},
ExitCode: 1,
},
{Cmd: []string{"iptables", "-w", "60", "-F", "AZURE-NPM"}},
{Cmd: []string{"iptables-legacy", "-w", "60", "-F", "AZURE-NPM"}},
{
Cmd: []string{"iptables", "-w", "60", "-F", "AZURE-NPM-INGRESS"},
Cmd: []string{"iptables-legacy", "-w", "60", "-F", "AZURE-NPM-INGRESS"},
ExitCode: 1,
},
{Cmd: []string{"iptables", "-w", "60", "-X", "AZURE-NPM"}},
{Cmd: []string{"iptables-legacy", "-w", "60", "-X", "AZURE-NPM"}},
{
Cmd: []string{"iptables", "-w", "60", "-X", "AZURE-NPM-INGRESS"},
Cmd: []string{"iptables-legacy", "-w", "60", "-X", "AZURE-NPM-INGRESS"},
ExitCode: 1,
},
},
Expand All @@ -1279,15 +1279,15 @@ func TestCleanupOtherChains(t *testing.T) {
startWithNft: true,
calls: []testutils.TestCmd{
{
Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"},
Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM"},
ExitCode: 1,
},
{
Cmd: []string{"iptables", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"},
Cmd: []string{"iptables-legacy", "-w", "60", "-D", "FORWARD", "-j", "AZURE-NPM", "-m", "conntrack", "--ctstate", "NEW"},
ExitCode: 1,
},
{
Cmd: []string{"iptables", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true, HasStartError: true,
Cmd: []string{"iptables-legacy", "-w", "60", "-t", "filter", "-n", "-L"}, PipedToCommand: true, HasStartError: true,
ExitCode: 1,
},
{Cmd: []string{"grep", "Chain AZURE-NPM"}},
Expand Down
6 changes: 3 additions & 3 deletions npm/util/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ const (
Ip6tablesLegacy string = "ip6tables" //nolint (avoid warning to capitalize this p)
IptablesSaveNft string = "iptables-nft-save"
IptablesRestoreNft string = "iptables-nft-restore"
IptablesLegacy string = "iptables"
IptablesSaveLegacy string = "iptables-save"
IptablesRestoreLegacy string = "iptables-restore"
IptablesLegacy string = "iptables-legacy"
IptablesSaveLegacy string = "iptables-legacy-save"
IptablesRestoreLegacy string = "iptables-legacy-restore"
IptablesRestoreNoFlushFlag string = "--noflush"
IptablesRestoreTableFlag string = "-T"
IptablesRestoreCommit string = "COMMIT"
Expand Down
Loading