@@ -41,6 +41,7 @@ import (
41
41
"k8s.io/apimachinery/pkg/types"
42
42
"k8s.io/apimachinery/pkg/util/sets"
43
43
utilvalidation "k8s.io/apimachinery/pkg/util/validation"
44
+ "k8s.io/apimachinery/pkg/util/version"
44
45
utilfeature "k8s.io/apiserver/pkg/util/feature"
45
46
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
46
47
"k8s.io/klog/v2"
@@ -62,6 +63,7 @@ import (
62
63
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
63
64
"k8s.io/kubernetes/pkg/kubelet/util"
64
65
utilfs "k8s.io/kubernetes/pkg/util/filesystem"
66
+ utilkernel "k8s.io/kubernetes/pkg/util/kernel"
65
67
utilpod "k8s.io/kubernetes/pkg/util/pod"
66
68
volumeutil "k8s.io/kubernetes/pkg/volume/util"
67
69
"k8s.io/kubernetes/pkg/volume/util/hostutil"
@@ -130,6 +132,17 @@ func (kl *Kubelet) getKubeletMappings() (uint32, uint32, error) {
130
132
131
133
if ! utilfeature .DefaultFeatureGate .Enabled (features .UserNamespacesSupport ) {
132
134
return defaultFirstID , defaultLen , nil
135
+ } else {
136
+ kernelVersion , err := utilkernel .GetVersion ()
137
+ if err != nil {
138
+ return 0 , 0 , fmt .Errorf ("failed to get kernel version, unable to determine if feature %s can be supported : %w" ,
139
+ features .UserNamespacesSupport , err )
140
+ }
141
+ if kernelVersion != nil && ! kernelVersion .AtLeast (version .MustParseGeneric (utilkernel .UserNamespacesSupportKernelVersion )) {
142
+ return 0 , 0 , fmt .Errorf (
143
+ "the kernel version (%s) is incompatible with the %s feature gate, which needs %s as a minimum kernel version" ,
144
+ kernelVersion , features .UserNamespacesSupport , utilkernel .UserNamespacesSupportKernelVersion )
145
+ }
133
146
}
134
147
135
148
_ , err := user .Lookup (kubeletUser )
0 commit comments