@@ -17,6 +17,7 @@ limitations under the License.
17
17
package sysctl
18
18
19
19
import (
20
+ "context"
20
21
goruntime "runtime"
21
22
22
23
"k8s.io/apimachinery/pkg/util/version"
@@ -75,18 +76,19 @@ var safeSysctls = []sysctl{
75
76
// A sysctl is called safe iff
76
77
// - it is namespaced in the container or the pod
77
78
// - it is isolated, i.e. has no influence on any other pod on the same node.
78
- func SafeSysctlAllowlist () []string {
79
+ func SafeSysctlAllowlist (ctx context. Context ) []string {
79
80
if goruntime .GOOS != "linux" {
80
81
return nil
81
82
}
82
83
83
- return getSafeSysctlAllowlist (utilkernel .GetVersion )
84
+ return getSafeSysctlAllowlist (ctx , utilkernel .GetVersion )
84
85
}
85
86
86
- func getSafeSysctlAllowlist (getVersion func () (* version.Version , error )) []string {
87
+ func getSafeSysctlAllowlist (ctx context.Context , getVersion func () (* version.Version , error )) []string {
88
+ logger := klog .FromContext (ctx )
87
89
kernelVersion , err := getVersion ()
88
90
if err != nil {
89
- klog . ErrorS (err , "failed to get kernel version, unable to determine which sysctls are available" )
91
+ logger . Error (err , "failed to get kernel version, unable to determine which sysctls are available" )
90
92
}
91
93
92
94
var safeSysctlAllowlist []string
@@ -99,7 +101,7 @@ func getSafeSysctlAllowlist(getVersion func() (*version.Version, error)) []strin
99
101
if kernelVersion != nil && kernelVersion .AtLeast (version .MustParseGeneric (sc .kernel )) {
100
102
safeSysctlAllowlist = append (safeSysctlAllowlist , sc .name )
101
103
} else {
102
- klog . InfoS ("kernel version is too old, dropping the sysctl from safe sysctl list" , "kernelVersion" , kernelVersion , "sysctl" , sc .name )
104
+ logger . Info ("kernel version is too old, dropping the sysctl from safe sysctl list" , "kernelVersion" , kernelVersion , "sysctl" , sc .name )
103
105
}
104
106
}
105
107
return safeSysctlAllowlist
0 commit comments