@@ -113,6 +113,7 @@ import (
113
113
"k8s.io/kubernetes/pkg/util/mount"
114
114
nodeutil "k8s.io/kubernetes/pkg/util/node"
115
115
"k8s.io/kubernetes/pkg/util/oom"
116
+ "k8s.io/kubernetes/pkg/util/selinux"
116
117
"k8s.io/kubernetes/pkg/volume"
117
118
"k8s.io/kubernetes/pkg/volume/csi"
118
119
utilexec "k8s.io/utils/exec"
@@ -1225,6 +1226,8 @@ type Kubelet struct {
1225
1226
// 4. the pod-resources directory
1226
1227
func (kl * Kubelet ) setupDataDirs () error {
1227
1228
kl .rootDirectory = path .Clean (kl .rootDirectory )
1229
+ pluginRegistrationDir := kl .getPluginsRegistrationDir ()
1230
+ pluginsDir := kl .getPluginsDir ()
1228
1231
if err := os .MkdirAll (kl .getRootDir (), 0750 ); err != nil {
1229
1232
return fmt .Errorf ("error creating root directory: %v" , err )
1230
1233
}
@@ -1243,6 +1246,16 @@ func (kl *Kubelet) setupDataDirs() error {
1243
1246
if err := os .MkdirAll (kl .getPodResourcesDir (), 0750 ); err != nil {
1244
1247
return fmt .Errorf ("error creating podresources directory: %v" , err )
1245
1248
}
1249
+ if selinux .SELinuxEnabled () {
1250
+ err := selinux .SetFileLabel (pluginRegistrationDir , config .KubeletPluginsDirSELinuxLabel )
1251
+ if err != nil {
1252
+ klog .Warningf ("Unprivileged containerized plugins might not work. Could not set selinux context on %s: %v" , pluginRegistrationDir , err )
1253
+ }
1254
+ err = selinux .SetFileLabel (pluginsDir , config .KubeletPluginsDirSELinuxLabel )
1255
+ if err != nil {
1256
+ klog .Warningf ("Unprivileged containerized plugins might not work. Could not set selinux context on %s: %v" , pluginsDir , err )
1257
+ }
1258
+ }
1246
1259
return nil
1247
1260
}
1248
1261
0 commit comments