diff --git a/cmd/kubeadm/app/phases/controlplane/volumes.go b/cmd/kubeadm/app/phases/controlplane/volumes.go index 690cd01a0ef..35edc211187 100644 --- a/cmd/kubeadm/app/phases/controlplane/volumes.go +++ b/cmd/kubeadm/app/phases/controlplane/volumes.go @@ -72,7 +72,9 @@ func getHostPathVolumesForTheControlPlane(cfg *kubeadmapi.MasterConfiguration) c mounts.NewHostPathMount(kubeadmconstants.KubeControllerManager, kubeadmconstants.KubeConfigVolumeName, controllerManagerKubeConfigFile, controllerManagerKubeConfigFile, true, &hostPathFileOrCreate) // Mount for the flexvolume directory (/usr/libexec/kubernetes/kubelet-plugins/volume/exec) directory // Flexvolume dir must NOT be readonly as it is used for third-party plugins to integrate with their storage backends via unix domain socket. - mounts.NewHostPathMount(kubeadmconstants.KubeControllerManager, flexvolumeDirVolumeName, flexvolumeDirVolumePath, flexvolumeDirVolumePath, false, &hostPathDirectoryOrCreate) + if stat, err := os.Stat(flexvolumeDirVolumePath); err == nil && stat.IsDir() { + mounts.NewHostPathMount(kubeadmconstants.KubeControllerManager, flexvolumeDirVolumeName, flexvolumeDirVolumePath, flexvolumeDirVolumePath, false, &hostPathDirectoryOrCreate) + } // HostPath volumes for the scheduler // Read-only mount for the scheduler kubeconfig file diff --git a/cmd/kubeadm/app/phases/controlplane/volumes_test.go b/cmd/kubeadm/app/phases/controlplane/volumes_test.go index e0032bdafa0..b2cdacadbaa 100644 --- a/cmd/kubeadm/app/phases/controlplane/volumes_test.go +++ b/cmd/kubeadm/app/phases/controlplane/volumes_test.go @@ -306,15 +306,6 @@ func TestGetHostPathVolumesForTheControlPlane(t *testing.T) { }, }, } - volMap[kubeadmconstants.KubeControllerManager]["flexvolume-dir"] = v1.Volume{ - Name: "flexvolume-dir", - VolumeSource: v1.VolumeSource{ - HostPath: &v1.HostPathVolumeSource{ - Path: "/usr/libexec/kubernetes/kubelet-plugins/volume/exec", - Type: &hostPathDirectoryOrCreate, - }, - }, - } volMap[kubeadmconstants.KubeScheduler] = map[string]v1.Volume{} volMap[kubeadmconstants.KubeScheduler]["kubeconfig"] = v1.Volume{ Name: "kubeconfig", @@ -353,11 +344,6 @@ func TestGetHostPathVolumesForTheControlPlane(t *testing.T) { MountPath: "/etc/kubernetes/controller-manager.conf", ReadOnly: true, } - volMountMap[kubeadmconstants.KubeControllerManager]["flexvolume-dir"] = v1.VolumeMount{ - Name: "flexvolume-dir", - MountPath: "/usr/libexec/kubernetes/kubelet-plugins/volume/exec", - ReadOnly: false, - } volMountMap[kubeadmconstants.KubeScheduler] = map[string]v1.VolumeMount{} volMountMap[kubeadmconstants.KubeScheduler]["kubeconfig"] = v1.VolumeMount{ Name: "kubeconfig", @@ -431,15 +417,6 @@ func TestGetHostPathVolumesForTheControlPlane(t *testing.T) { }, }, } - volMap2[kubeadmconstants.KubeControllerManager]["flexvolume-dir"] = v1.Volume{ - Name: "flexvolume-dir", - VolumeSource: v1.VolumeSource{ - HostPath: &v1.HostPathVolumeSource{ - Path: "/usr/libexec/kubernetes/kubelet-plugins/volume/exec", - Type: &hostPathDirectoryOrCreate, - }, - }, - } volMap2[kubeadmconstants.KubeScheduler] = map[string]v1.Volume{} volMap2[kubeadmconstants.KubeScheduler]["kubeconfig"] = v1.Volume{ Name: "kubeconfig", @@ -488,11 +465,6 @@ func TestGetHostPathVolumesForTheControlPlane(t *testing.T) { MountPath: "/etc/kubernetes/controller-manager.conf", ReadOnly: true, } - volMountMap2[kubeadmconstants.KubeControllerManager]["flexvolume-dir"] = v1.VolumeMount{ - Name: "flexvolume-dir", - MountPath: "/usr/libexec/kubernetes/kubelet-plugins/volume/exec", - ReadOnly: false, - } volMountMap2[kubeadmconstants.KubeScheduler] = map[string]v1.VolumeMount{} volMountMap2[kubeadmconstants.KubeScheduler]["kubeconfig"] = v1.VolumeMount{ Name: "kubeconfig",