Skip to content

Commit

Permalink
cni: do not exit if the sysctl variable does not exist or can not be …
Browse files Browse the repository at this point in the history
…set (#4828)

Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian authored Dec 13, 2024
1 parent 3862907 commit e2e6dd7
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/cni/sysctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main

import (
"fmt"
"os"

"github.com/containernetworking/plugins/pkg/ns"
"github.com/containernetworking/plugins/pkg/utils/sysctl"
Expand All @@ -19,10 +20,18 @@ func sysctlEnableIPv6(nsPath string) error {
name := fmt.Sprintf("net.ipv6.conf.%s.disable_ipv6", conf)
value, err := sysctl.Sysctl(name)
if err != nil {
if os.IsNotExist(err) {
// The sysctl variable doesn't exist, so we can't set it
continue
}
return fmt.Errorf("failed to get sysctl variable %s: %w", name, err)
}
if value != "0" {
if _, err = sysctl.Sysctl(name, "0"); err != nil {
if os.IsPermission(err) {
// We don't have permission to set the sysctl variable, so we can't set it
continue
}
return fmt.Errorf("failed to set sysctl variable %s to 0: %w", name, err)
}
}
Expand Down

0 comments on commit e2e6dd7

Please sign in to comment.