Skip to content

Commit 7fa571b

Browse files
committed
kubeadm: always add a flex volume path for the controller-manager
Checking if the path exists before creating the volume is problematic because the path will be created regardless after the initial call to "kubeadm init" and once the CM Pod is running. Then on subsequent calls to "kubeadm init" or the "control-plane" phase the manifest for the CM will be different. Always mount this path, but also consider the user provided flag override from ClusterConfiguration.
1 parent a822007 commit 7fa571b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

cmd/kubeadm/app/phases/controlplane/volumes.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ import (
2222
"path/filepath"
2323
"strings"
2424

25-
"k8s.io/api/core/v1"
25+
v1 "k8s.io/api/core/v1"
2626
"k8s.io/apimachinery/pkg/util/sets"
2727
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
2828
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
2929
staticpodutil "k8s.io/kubernetes/cmd/kubeadm/app/util/staticpod"
3030
)
3131

3232
const (
33-
caCertsVolumeName = "ca-certs"
34-
caCertsVolumePath = "/etc/ssl/certs"
35-
flexvolumeDirVolumeName = "flexvolume-dir"
36-
flexvolumeDirVolumePath = "/usr/libexec/kubernetes/kubelet-plugins/volume/exec"
33+
caCertsVolumeName = "ca-certs"
34+
caCertsVolumePath = "/etc/ssl/certs"
35+
flexvolumeDirVolumeName = "flexvolume-dir"
36+
defaultFlexvolumeDirVolumePath = "/usr/libexec/kubernetes/kubelet-plugins/volume/exec"
3737
)
3838

3939
// caCertsExtraVolumePaths specifies the paths that can be conditionally mounted into the apiserver and controller-manager containers
@@ -69,11 +69,13 @@ func getHostPathVolumesForTheControlPlane(cfg *kubeadmapi.ClusterConfiguration)
6969
// Read-only mount for the controller manager kubeconfig file
7070
controllerManagerKubeConfigFile := filepath.Join(kubeadmconstants.KubernetesDir, kubeadmconstants.ControllerManagerKubeConfigFileName)
7171
mounts.NewHostPathMount(kubeadmconstants.KubeControllerManager, kubeadmconstants.KubeConfigVolumeName, controllerManagerKubeConfigFile, controllerManagerKubeConfigFile, true, &hostPathFileOrCreate)
72-
// Mount for the flexvolume directory (/usr/libexec/kubernetes/kubelet-plugins/volume/exec) directory
72+
// Mount for the flexvolume directory (/usr/libexec/kubernetes/kubelet-plugins/volume/exec by default)
7373
// Flexvolume dir must NOT be readonly as it is used for third-party plugins to integrate with their storage backends via unix domain socket.
74-
if stat, err := os.Stat(flexvolumeDirVolumePath); err == nil && stat.IsDir() {
75-
mounts.NewHostPathMount(kubeadmconstants.KubeControllerManager, flexvolumeDirVolumeName, flexvolumeDirVolumePath, flexvolumeDirVolumePath, false, &hostPathDirectoryOrCreate)
74+
flexvolumeDirVolumePath, ok := cfg.ControllerManager.ExtraArgs["flex-volume-plugin-dir"]
75+
if !ok {
76+
flexvolumeDirVolumePath = defaultFlexvolumeDirVolumePath
7677
}
78+
mounts.NewHostPathMount(kubeadmconstants.KubeControllerManager, flexvolumeDirVolumeName, flexvolumeDirVolumePath, flexvolumeDirVolumePath, false, &hostPathDirectoryOrCreate)
7779

7880
// HostPath volumes for the scheduler
7981
// Read-only mount for the scheduler kubeconfig file

0 commit comments

Comments
 (0)