Skip to content

Commit 221b1a3

Browse files
committed
cni: do not exit if the sysctl variable does not exist or can not be set (#4828)
Signed-off-by: zhangzujian <[email protected]>
1 parent e465410 commit 221b1a3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

cmd/cni/sysctl.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package main
55

66
import (
77
"fmt"
8+
"os"
89

910
"github.com/containernetworking/plugins/pkg/ns"
1011
"github.com/containernetworking/plugins/pkg/utils/sysctl"
@@ -19,10 +20,18 @@ func sysctlEnableIPv6(nsPath string) error {
1920
name := fmt.Sprintf("net.ipv6.conf.%s.disable_ipv6", conf)
2021
value, err := sysctl.Sysctl(name)
2122
if err != nil {
23+
if os.IsNotExist(err) {
24+
// The sysctl variable doesn't exist, so we can't set it
25+
continue
26+
}
2227
return fmt.Errorf("failed to get sysctl variable %s: %w", name, err)
2328
}
2429
if value != "0" {
2530
if _, err = sysctl.Sysctl(name, "0"); err != nil {
31+
if os.IsPermission(err) {
32+
// We don't have permission to set the sysctl variable, so we can't set it
33+
continue
34+
}
2635
return fmt.Errorf("failed to set sysctl variable %s to 0: %w", name, err)
2736
}
2837
}

0 commit comments

Comments
 (0)