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.
This commit is contained in:
Fabio Bertinatto 2022-01-31 16:53:24 -03:00
parent 7c2e612569
commit eb2adaa32f

View File

@ -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