-
Notifications
You must be signed in to change notification settings - Fork 176
fix(bypass): clean up stale iptables rules on daemon restart #1621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,7 +65,11 @@ func NewByPassController(client kubernetes.Interface) *Controller { | |
| } | ||
|
|
||
| if !shouldBypass(pod) { | ||
| // TODO: add delete iptables in case we missed skip bypass during kmesh restart | ||
| nspath, _ := ns.GetPodNSpath(pod) | ||
| if nspath != "" { | ||
| // during daemon restart, reconcile to ensure stale bypass rules are cleared | ||
| _ = deleteIptables(nspath) | ||
|
Comment on lines
67
to
+71
|
||
| } | ||
| return | ||
| } | ||
|
|
||
|
|
@@ -157,7 +161,7 @@ func addIptables(ns string) error { | |
| } | ||
| for _, args := range iptArgs { | ||
| if err := utils.Execute("iptables", args); err != nil { | ||
| return fmt.Errorf("failed to exec command: iptables %v\", err: %v", args, err) | ||
| return fmt.Errorf("failed to exec command: iptables %v, err: %v", args, err) | ||
| } | ||
| } | ||
| return nil | ||
|
|
@@ -178,7 +182,7 @@ func deleteIptables(ns string) error { | |
| log.Infof("Running delete iptables rule in namespace:%s", ns) | ||
| for _, args := range iptArgs { | ||
| if err := utils.Execute("iptables", args); err != nil { | ||
| err = fmt.Errorf("failed to exec command: iptables %v\", err: %v", args, err) | ||
| err = fmt.Errorf("failed to exec command: iptables %v, err: %v", args, err) | ||
| log.Error(err) | ||
| return err | ||
|
Comment on lines
183
to
187
|
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -150,4 +150,27 @@ func TestBypassController(t *testing.T) { | |||||
| wg.Wait() | ||||||
| assert.Equal(t, true, enabled.Load(), "unexpected value for enabled flag") | ||||||
| assert.Equal(t, false, disabled.Load(), "unexpected value for disabled flag") | ||||||
|
|
||||||
| enabled.Store(false) | ||||||
| disabled.Store(false) | ||||||
| // case 5: Pod with sidecar but no bypass label at creation | ||||||
| podWithSidecarButNoBypass := &corev1.Pod{ | ||||||
| ObjectMeta: metav1.ObjectMeta{ | ||||||
| Name: "test-pod-no-bypass", | ||||||
| Namespace: namespaceName, | ||||||
| Labels: map[string]string{}, // no bypass label | ||||||
| Annotations: map[string]string{ | ||||||
| "sidecar.istio.io/status": "placeholder", | ||||||
|
||||||
| "sidecar.istio.io/status": "placeholder", | |
| annotation.SidecarStatus.Name: "placeholder", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error returned by
deleteIptablesis ignored. This is inconsistent with other parts of the controller where errors fromaddIptablesanddeleteIptablesare logged. IfdeleteIptablesfails, it will fail silently, and stale iptables rules might not be cleaned up as intended, which undermines the goal of this change. The error should be logged to provide visibility into potential failures.