From 30b4e6aad3c9c926681820a4836ec01db0cb013b Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Tue, 18 May 2021 14:19:43 +0200 Subject: [PATCH] relax volume lifecycle checks by default The recently introduced "still in use" check revealed a bug in Kubernetes (https://github.com/kubernetes/kubernetes/issues/101911). While the check itself is correct, enabling it would cause a lot of test flakes. Therefore the check has to be disabled until all Kubernetes versions that we test against are fixed. --- cmd/hostpathplugin/main.go | 1 + go.mod | 1 + pkg/hostpath/controllerserver.go | 13 +++++++++++-- pkg/hostpath/hostpath.go | 1 + vendor/modules.txt | 1 + 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cmd/hostpathplugin/main.go b/cmd/hostpathplugin/main.go index aeae01693..c5a2e33ac 100644 --- a/cmd/hostpathplugin/main.go +++ b/cmd/hostpathplugin/main.go @@ -52,6 +52,7 @@ func main() { flag.Int64Var(&cfg.MaxVolumesPerNode, "maxvolumespernode", 0, "limit of volumes per node") flag.Var(&cfg.Capacity, "capacity", "Simulate storage capacity. The parameter is = where is the value of a 'kind' storage class parameter and is the total amount of bytes for that kind. The flag may be used multiple times to configure different kinds.") flag.BoolVar(&cfg.EnableAttach, "enable-attach", false, "Enables RPC_PUBLISH_UNPUBLISH_VOLUME capability.") + flag.BoolVar(&cfg.CheckVolumeLifecycle, "check-volume-lifecycle", false, "Can be used to turn some violations of the volume lifecycle into warnings instead of failing the incorrect gRPC call. Disabled by default because of https://github.com/kubernetes/kubernetes/issues/101911.") flag.Int64Var(&cfg.MaxVolumeSize, "max-volume-size", 1024*1024*1024*1024, "maximum size of volumes in bytes (inclusive)") flag.BoolVar(&cfg.EnableTopology, "enable-topology", true, "Enables PluginCapability_Service_VOLUME_ACCESSIBILITY_CONSTRAINTS capability.") flag.BoolVar(&cfg.EnableVolumeExpansion, "node-expand-required", true, "Enables NodeServiceCapability_RPC_EXPAND_VOLUME capacity.") diff --git a/go.mod b/go.mod index 460c6b443..90a05e73b 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( google.golang.org/genproto v0.0.0-20201209185603-f92720507ed4 // indirect google.golang.org/grpc v1.34.0 k8s.io/apimachinery v0.21.0-alpha.0 + k8s.io/klog/v2 v2.4.0 k8s.io/kubernetes v1.20.0 k8s.io/mount-utils v0.20.0 // indirect k8s.io/utils v0.0.0-20201110183641-67b214c5f920 diff --git a/pkg/hostpath/controllerserver.go b/pkg/hostpath/controllerserver.go index a70ef1f32..7d87bbd96 100644 --- a/pkg/hostpath/controllerserver.go +++ b/pkg/hostpath/controllerserver.go @@ -33,6 +33,7 @@ import ( "google.golang.org/grpc/status" "github.com/container-storage-interface/spec/lib/go/csi" + "k8s.io/klog/v2" utilexec "k8s.io/utils/exec" "github.com/kubernetes-csi/csi-driver-host-path/pkg/state" @@ -204,8 +205,12 @@ func (hp *hostPath) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeReque } if vol.Attached || !vol.Published.Empty() || !vol.Staged.Empty() { - return nil, status.Errorf(codes.Internal, "Volume '%s' is still used (attached: %v, staged: %v, published: %v) by '%s' node", + msg := fmt.Sprintf("Volume '%s' is still used (attached: %v, staged: %v, published: %v) by '%s' node", vol.VolID, vol.Attached, vol.Staged, vol.Published, vol.NodeID) + if hp.config.CheckVolumeLifecycle { + return nil, status.Error(codes.Internal, msg) + } + klog.Warning(msg) } if err := hp.deleteVolume(volId); err != nil { @@ -340,8 +345,12 @@ func (hp *hostPath) ControllerUnpublishVolume(ctx context.Context, req *csi.Cont // Check to see if the volume is staged/published on a node if !vol.Published.Empty() || !vol.Staged.Empty() { - return nil, status.Errorf(codes.Internal, "Volume '%s' is still used (staged: %v, published: %v) by '%s' node", + msg := fmt.Sprintf("Volume '%s' is still used (staged: %v, published: %v) by '%s' node", vol.VolID, vol.Staged, vol.Published, vol.NodeID) + if hp.config.CheckVolumeLifecycle { + return nil, status.Error(codes.Internal, msg) + } + klog.Warning(msg) } vol.Attached = false diff --git a/pkg/hostpath/hostpath.go b/pkg/hostpath/hostpath.go index 6eeeb6543..c02dd188d 100644 --- a/pkg/hostpath/hostpath.go +++ b/pkg/hostpath/hostpath.go @@ -74,6 +74,7 @@ type Config struct { EnableAttach bool EnableTopology bool EnableVolumeExpansion bool + CheckVolumeLifecycle bool } var ( diff --git a/vendor/modules.txt b/vendor/modules.txt index 0f3e2899b..ef75d4be4 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -154,6 +154,7 @@ k8s.io/apiserver/pkg/util/feature # k8s.io/component-base v0.20.0 => k8s.io/component-base v0.20.0 k8s.io/component-base/featuregate # k8s.io/klog/v2 v2.4.0 +## explicit k8s.io/klog/v2 # k8s.io/kubernetes v1.20.0 ## explicit