diff --git a/pkg/api/pod/util.go b/pkg/api/pod/util.go index 787a238eaae..dd79c4831b9 100644 --- a/pkg/api/pod/util.go +++ b/pkg/api/pod/util.go @@ -447,12 +447,6 @@ func dropDisabledFields( } } - if !utilfeature.DefaultFeatureGate.Enabled(features.Sysctls) && !sysctlsInUse(oldPodSpec) { - if podSpec.SecurityContext != nil { - podSpec.SecurityContext.Sysctls = nil - } - } - if !utilfeature.DefaultFeatureGate.Enabled(features.LocalStorageCapacityIsolation) && !emptyDirSizeLimitInUse(oldPodSpec) { for i := range podSpec.Volumes { if podSpec.Volumes[i].EmptyDir != nil { @@ -648,16 +642,6 @@ func podPriorityInUse(podSpec *api.PodSpec) bool { return false } -func sysctlsInUse(podSpec *api.PodSpec) bool { - if podSpec == nil { - return false - } - if podSpec.SecurityContext != nil && podSpec.SecurityContext.Sysctls != nil { - return true - } - return false -} - // emptyDirSizeLimitInUse returns true if any pod's EmptyDir volumes use SizeLimit. func emptyDirSizeLimitInUse(podSpec *api.PodSpec) bool { if podSpec == nil { diff --git a/pkg/api/podsecuritypolicy/util.go b/pkg/api/podsecuritypolicy/util.go index 43de1b835c8..a0df4f83ac4 100644 --- a/pkg/api/podsecuritypolicy/util.go +++ b/pkg/api/podsecuritypolicy/util.go @@ -28,10 +28,6 @@ func DropDisabledFields(pspSpec, oldPSPSpec *policy.PodSecurityPolicySpec) { if !utilfeature.DefaultFeatureGate.Enabled(features.ProcMountType) && !allowedProcMountTypesInUse(oldPSPSpec) { pspSpec.AllowedProcMountTypes = nil } - if !utilfeature.DefaultFeatureGate.Enabled(features.Sysctls) && !sysctlsInUse(oldPSPSpec) { - pspSpec.AllowedUnsafeSysctls = nil - pspSpec.ForbiddenSysctls = nil - } if !utilfeature.DefaultFeatureGate.Enabled(features.CSIInlineVolume) { pspSpec.AllowedCSIDrivers = nil } @@ -49,13 +45,3 @@ func allowedProcMountTypesInUse(oldPSPSpec *policy.PodSecurityPolicySpec) bool { return false } - -func sysctlsInUse(oldPSPSpec *policy.PodSecurityPolicySpec) bool { - if oldPSPSpec == nil { - return false - } - if oldPSPSpec.AllowedUnsafeSysctls != nil || oldPSPSpec.ForbiddenSysctls != nil { - return true - } - return false -} diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 6513882d8e1..55b5f0ce62d 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -775,16 +775,14 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration, klet.evictionManager = evictionManager klet.admitHandlers.AddPodAdmitHandler(evictionAdmitHandler) - if utilfeature.DefaultFeatureGate.Enabled(features.Sysctls) { - // Safe, whitelisted sysctls can always be used as unsafe sysctls in the spec. - // Hence, we concatenate those two lists. - safeAndUnsafeSysctls := append(sysctlwhitelist.SafeSysctlWhitelist(), allowedUnsafeSysctls...) - sysctlsWhitelist, err := sysctl.NewWhitelist(safeAndUnsafeSysctls) - if err != nil { - return nil, err - } - klet.admitHandlers.AddPodAdmitHandler(sysctlsWhitelist) + // Safe, whitelisted sysctls can always be used as unsafe sysctls in the spec. + // Hence, we concatenate those two lists. + safeAndUnsafeSysctls := append(sysctlwhitelist.SafeSysctlWhitelist(), allowedUnsafeSysctls...) + sysctlsWhitelist, err := sysctl.NewWhitelist(safeAndUnsafeSysctls) + if err != nil { + return nil, err } + klet.admitHandlers.AddPodAdmitHandler(sysctlsWhitelist) // enable active deadline handler activeDeadlineHandler, err := newActiveDeadlineHandler(klet.statusManager, kubeDeps.Recorder, klet.clock) diff --git a/pkg/kubelet/kuberuntime/kuberuntime_sandbox.go b/pkg/kubelet/kuberuntime/kuberuntime_sandbox.go index b09edd08d7f..db0bdd7a0dc 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_sandbox.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_sandbox.go @@ -25,10 +25,8 @@ import ( v1 "k8s.io/api/core/v1" kubetypes "k8s.io/apimachinery/pkg/types" - utilfeature "k8s.io/apiserver/pkg/util/feature" runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" "k8s.io/klog/v2" - "k8s.io/kubernetes/pkg/features" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" "k8s.io/kubernetes/pkg/kubelet/types" "k8s.io/kubernetes/pkg/kubelet/util" @@ -166,11 +164,9 @@ func (m *kubeGenericRuntimeManager) generatePodSandboxLinuxConfig(pod *v1.Pod) ( } sysctls := make(map[string]string) - if utilfeature.DefaultFeatureGate.Enabled(features.Sysctls) { - if pod.Spec.SecurityContext != nil { - for _, c := range pod.Spec.SecurityContext.Sysctls { - sysctls[c.Name] = c.Value - } + if pod.Spec.SecurityContext != nil { + for _, c := range pod.Spec.SecurityContext.Sysctls { + sysctls[c.Name] = c.Value } }