mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-24 03:18:57 +00:00
Encapsulate sysctl test and log
This commit is contained in:
@@ -12,6 +12,7 @@ go_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//pkg/apis/core/v1/helper:go_default_library",
|
||||
"//pkg/util/sysctl:go_default_library",
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/rand:go_default_library",
|
||||
|
@@ -29,6 +29,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/client-go/tools/record"
|
||||
helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
|
||||
utilsysctl "k8s.io/kubernetes/pkg/util/sysctl"
|
||||
utilnet "k8s.io/utils/net"
|
||||
|
||||
"k8s.io/klog"
|
||||
@@ -288,3 +289,14 @@ func ShuffleStrings(s []string) []string {
|
||||
}
|
||||
return shuffled
|
||||
}
|
||||
|
||||
// EnsureSysctl sets a kernel sysctl to a given numeric value.
|
||||
func EnsureSysctl(sysctl utilsysctl.Interface, name string, newVal int) error {
|
||||
if oldVal, _ := sysctl.GetSysctl(name); oldVal != newVal {
|
||||
if err := sysctl.SetSysctl(name, newVal); err != nil {
|
||||
return fmt.Errorf("can't set sysctl %s to %d: %v", name, newVal, err)
|
||||
}
|
||||
klog.V(1).Infof("Changed sysctl %q: %d -> %d", name, oldVal, newVal)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user