From eb2adaa32f9b9ce11beb6e495ec06e0aa11d9a5c Mon Sep 17 00:00:00 2001 From: Fabio Bertinatto Date: Mon, 31 Jan 2022 16:53:24 -0300 Subject: [PATCH] Fix panic in Kubelet Currently, the Kubelet panics when it's started with the `enable-controller-attach-detach=false` option set and a volume is attached to a node. This patch adds a check that prevents the Kubelet from trying to attach or detach CSI volumes and report a proper error warning the user that this use case is not supported. --- pkg/volume/csi/csi_attacher.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/volume/csi/csi_attacher.go b/pkg/volume/csi/csi_attacher.go index 0b027034773..621cd3ce894 100644 --- a/pkg/volume/csi/csi_attacher.go +++ b/pkg/volume/csi/csi_attacher.go @@ -66,6 +66,11 @@ var _ volume.Detacher = &csiAttacher{} var _ volume.DeviceMounter = &csiAttacher{} func (c *csiAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (string, error) { + _, ok := c.plugin.host.(volume.KubeletVolumeHost) + if ok { + return "", errors.New("attaching volumes from the kubelet is not supported") + } + if spec == nil { klog.Error(log("attacher.Attach missing volume.Spec")) return "", errors.New("missing spec") @@ -404,6 +409,11 @@ var _ volume.Detacher = &csiAttacher{} var _ volume.DeviceUnmounter = &csiAttacher{} func (c *csiAttacher) Detach(volumeName string, nodeName types.NodeName) error { + _, ok := c.plugin.host.(volume.KubeletVolumeHost) + if ok { + return errors.New("detaching volumes from the kubelet is not supported") + } + var attachID string var volID string