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 75554c0
Show file tree
Hide file tree
Showing 3 changed files with 13 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
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

0 comments on commit 75554c0

Please sign in to comment.