From d0e4aecf5821bb34112c90c1b01e38a50eb638b1 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Fri, 30 Aug 2019 11:22:18 -0700 Subject: [PATCH] Fix CSI initialization conflict CSI is used by both the kubelet and kube-controller-manager. Both components will initialize the csiPlugin with different VolumeHost objects. The csiPlugin will then assign a global variable for the node info manager. It is then possible that the kubelet gets the credentials of the kube-controller-manager and that will cause CSI to fail. --- pkg/volume/csi/csi_plugin.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/volume/csi/csi_plugin.go b/pkg/volume/csi/csi_plugin.go index 59fa6245b7f..bf05b65d5a1 100644 --- a/pkg/volume/csi/csi_plugin.go +++ b/pkg/volume/csi/csi_plugin.go @@ -256,18 +256,22 @@ func (p *csiPlugin) Init(host volume.VolumeHost) error { } // Initializing the label management channels - nim = nodeinfomanager.NewNodeInfoManager(host.GetNodeName(), host, migratedPlugins) + localNim := nodeinfomanager.NewNodeInfoManager(host.GetNodeName(), host, migratedPlugins) // This function prevents Kubelet from posting Ready status until CSINode // is both installed and initialized - if err := initializeCSINode(host); err != nil { - return errors.New(log("failed to initialize CSINode: %v", err)) + if err := initializeCSINode(host, localNim); err != nil { + return errors.New(log("failed to initialize CSINodeInfo: %v", err)) + } + + if _, ok := host.(volume.KubeletVolumeHost); ok { + nim = localNim } return nil } -func initializeCSINode(host volume.VolumeHost) error { +func initializeCSINode(host volume.VolumeHost, nim nodeinfomanager.Interface) error { kvh, ok := host.(volume.KubeletVolumeHost) if !ok { klog.V(4).Info("Cast from VolumeHost to KubeletVolumeHost failed. Skipping CSINode initialization, not running on kubelet")