Skip to content

Commit

Permalink
relax volume lifecycle checks by default
Browse files Browse the repository at this point in the history
The recently introduced "still in use" check revealed a bug in
Kubernetes (kubernetes/kubernetes#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.
  • Loading branch information
pohly committed May 18, 2021
1 parent 5c624fc commit 30b4e6a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/hostpathplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <kind>=<quantity> where <kind> is the value of a 'kind' storage class parameter and <quantity> 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.")
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions pkg/hostpath/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/hostpath/hostpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type Config struct {
EnableAttach bool
EnableTopology bool
EnableVolumeExpansion bool
CheckVolumeLifecycle bool
}

var (
Expand Down
1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 30b4e6a

Please sign in to comment.