Skip to content

Commit

Permalink
add skip-cleanup arg
Browse files Browse the repository at this point in the history
  • Loading branch information
leosarra committed May 16, 2024
1 parent 0ceea78 commit 03cc823
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tools/istio-iptables/pkg/capture/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ func (cfg *IptablesConfigurator) executeCommands(iptVer, ipt6Ver *dep.IptablesVe
residueFound, applyRequired := cfg.VerifyRerunStatus(iptVer, ipt6Ver)

// Cleanup Step
if (residueFound && applyRequired) || cfg.cfg.CleanupOnly {
if (residueFound && applyRequired && !cfg.cfg.SkipCleanup) || cfg.cfg.CleanupOnly {
// Apply safety guardrails if not there
if residueFound {
log.Info("Setting up guardrails")
Expand Down
12 changes: 10 additions & 2 deletions tools/istio-iptables/pkg/capture/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ func TestIdempotentEquivalentRerun(t *testing.T) {
defer func() {
// Final Cleanup
cfg.CleanupOnly = true
cfg.SkipCleanup = false
iptConfigurator := NewIptablesConfigurator(cfg, ext)
assert.NoError(t, iptConfigurator.Run())
residueFound, applyRequired := iptConfigurator.VerifyRerunStatus(&iptVer, &ipt6Ver)
Expand All @@ -392,6 +393,7 @@ func TestIdempotentEquivalentRerun(t *testing.T) {
}()

// First Pass
cfg.SkipCleanup = true
iptConfigurator := NewIptablesConfigurator(cfg, ext)
assert.NoError(t, iptConfigurator.Run())
residueFound, applyRequired := iptConfigurator.VerifyRerunStatus(&iptVer, &ipt6Ver)
Expand Down Expand Up @@ -438,6 +440,7 @@ func TestIdempotentUnequaledRerun(t *testing.T) {
defer func() {
// Final Cleanup
cfg.CleanupOnly = true
cfg.SkipCleanup = false
iptConfigurator := NewIptablesConfigurator(cfg, ext)
assert.NoError(t, iptConfigurator.Run())
residueFound, applyRequired := iptConfigurator.VerifyRerunStatus(&iptVer, &ipt6Ver)
Expand Down Expand Up @@ -466,10 +469,15 @@ func TestIdempotentUnequaledRerun(t *testing.T) {
assert.Equal(t, residueFound, true)
assert.Equal(t, applyRequired, true)

// Second pass
// Fail is expected if cleanup is skipped
cfg.SkipCleanup = true
iptConfigurator = NewIptablesConfigurator(cfg, ext)
assert.NoError(t, iptConfigurator.Run())
assert.Error(t, iptConfigurator.Run())

// Second pass with cleanup
cfg.SkipCleanup = false
iptConfigurator = NewIptablesConfigurator(cfg, ext)
assert.NoError(t, iptConfigurator.Run())
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions tools/istio-iptables/pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ func bindCmdlineFlags(cfg *config.Config, cmd *cobra.Command) {

flag.BindEnv(fs, constants.CNIMode, "", "Whether to run as CNI plugin.", &cfg.CNIMode)

flag.BindEnv(fs, constants.SkipCleanup, "", "Skip cleanup of pre-existing and incompatible iptables rules", &cfg.SkipCleanup)

flag.BindEnv(fs, constants.CleanupOnly, "", "Perform a forced cleanup without creating new iptables chains or rules.",
&cfg.CleanupOnly)
}
Expand Down
1 change: 1 addition & 0 deletions tools/istio-iptables/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type Config struct {
DualStack bool `json:"DUAL_STACK"`
HostIP netip.Addr `json:"HOST_IP"`
HostIPv4LoopbackCidr string `json:"HOST_IPV4_LOOPBACK_CIDR"`
SkipCleanup bool `json:"SKIP_CLEANUP"`
CleanupOnly bool `json:"CLEANUP_ONLY"`
}

Expand Down
1 change: 1 addition & 0 deletions tools/istio-iptables/pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const (
CaptureAllDNS = "capture-all-dns"
NetworkNamespace = "network-namespace"
CNIMode = "cni-mode"
SkipCleanup = "skip-cleanup"
CleanupOnly = "cleanup-only"
)

Expand Down

0 comments on commit 03cc823

Please sign in to comment.