mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/1Panel-dev/1Panel.git
synced 2026-09-20 08:03:55 +08:00
feat: improve firewall backend synchronization (#13645)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user