Skip to content

Commit

Permalink
Addressing more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
berkayoz committed Jun 13, 2024
1 parent 3c12d0e commit 74aab38
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
15 changes: 7 additions & 8 deletions src/k8s/pkg/k8sd/features/calico/cleanup.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package calico

import (
"bytes"
"context"
"fmt"
"net"
Expand All @@ -24,7 +23,7 @@ func CleanupNetwork(ctx context.Context, snap snap.Snap) error {
// Find the interfaces created by Calico
for _, iface := range interfaces {
// Check if the interface name matches the regex pattern
match, err := regexp.MatchString("^vxlan[-v6]*.calico|cali[a-f0-9]*$", iface.Name)
match, err := regexp.MatchString("^vxlan[-v6]*.calico|cali[a-f0-9]*|tunl[0-9]*$", iface.Name)
if err != nil {
return fmt.Errorf("failed to match regex pattern: %w", err)
}
Expand Down Expand Up @@ -63,15 +62,15 @@ func CleanupNetwork(ctx context.Context, snap snap.Snap) error {
return fmt.Errorf("failed to read iptables rules: %w", err)
}

grep := exec.Command("grep", "-iv", "cali")
grep.Stdin = bytes.NewReader(out)
grepOut, err := grep.Output()
if err != nil {
return fmt.Errorf("failed to filter calico iptables rules: %w", err)
lines := strings.Split(string(out), "\n")
for i, line := range lines {
if strings.Contains(line, "cali") {
lines[i] = ""
}
}

restore := exec.Command(fmt.Sprintf("%s-restore", cmd))
restore.Stdin = bytes.NewReader(grepOut)
restore.Stdin = strings.NewReader(strings.Join(lines, "\n"))
if err := restore.Run(); err != nil {
return fmt.Errorf("failed to restore iptables rules: %w", err)
}
Expand Down
6 changes: 1 addition & 5 deletions src/k8s/pkg/k8sd/features/cilium/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ import (
)

func CleanupNetwork(ctx context.Context, snap snap.Snap) error {
if err := os.Remove("/var/run/cilium/cilium.pid"); err != nil {
return fmt.Errorf("failed to remove cilium pid file: %w", err)
}
os.Remove("/var/run/cilium/cilium.pid")

if _, err := os.Stat("/opt/cni/bin/cilium-dbg"); err == nil {
if err := exec.CommandContext(ctx, "/opt/cni/bin/cilium-dbg", "cleanup", "--all-state", "--force").Run(); err != nil {
return fmt.Errorf("cilium-dbg cleanup failed: %w", err)
}
} else {
return fmt.Errorf("cilium-dbg can't be accessed: %w", err)
}

return nil
Expand Down

0 comments on commit 74aab38

Please sign in to comment.