feat: improve firewall backend synchronization (#13645)

This commit is contained in:
ssongliu
2026-08-27 10:37:09 +08:00
committed by GitHub
parent 18428d108e
commit ddfb816ef1
2 changed files with 21 additions and 1 deletions

View File

@@ -215,7 +215,7 @@ func (m *Manager) Cleanup() error {
if err != nil {
return err
}
rules := dockerGuardLifecycleRules(output, false, chainDeclared(output, Chain))
rules := dockerGuardLifecycleRules(output, false, false)
if len(rules) == 0 {
continue
}

View File

@@ -189,6 +189,26 @@ func TestDockerGuardLifecycleRulesBatchCreateAndRebind(t *testing.T) {
}
}
func TestCleanupRemovesExistingChainWithoutRecreatingIt(t *testing.T) {
runner := &recordingRunner{}
manager := NewManagerWithRunner(runner)
if err := manager.Cleanup(); err != nil {
t.Fatal(err)
}
if len(runner.restoreCalls) != 1 {
t.Fatalf("restore calls = %d, want 1", len(runner.restoreCalls))
}
script := runner.restoreCalls[0].input
if strings.Contains(script, "-N "+Chain+"\n") {
t.Fatalf("cleanup must not recreate the existing chain:\n%s", script)
}
for _, want := range []string{"-F " + Chain + "\n", "-X " + Chain + "\n"} {
if !strings.Contains(script, want) {
t.Fatalf("cleanup restore is missing %q:\n%s", want, script)
}
}
}
func TestReconcileReturnsChainInspectionError(t *testing.T) {
manager := NewManagerWithRunner(&recordingRunner{runErr: errors.New("inspect failed")})
err := manager.Reconcile(nil)