Skip to content

Commit 7ca794d

Browse files
authored
Merge pull request #293 from pohly/relax-volume-lifecycle-check
relax volume lifecycle checks by default
2 parents ac10b91 + 30b4e6a commit 7ca794d

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

cmd/hostpathplugin/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func main() {
5252
flag.Int64Var(&cfg.MaxVolumesPerNode, "maxvolumespernode", 0, "limit of volumes per node")
5353
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.")
5454
flag.BoolVar(&cfg.EnableAttach, "enable-attach", false, "Enables RPC_PUBLISH_UNPUBLISH_VOLUME capability.")
55+
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.")
5556
flag.Int64Var(&cfg.MaxVolumeSize, "max-volume-size", 1024*1024*1024*1024, "maximum size of volumes in bytes (inclusive)")
5657
flag.BoolVar(&cfg.EnableTopology, "enable-topology", true, "Enables PluginCapability_Service_VOLUME_ACCESSIBILITY_CONSTRAINTS capability.")
5758
flag.BoolVar(&cfg.EnableVolumeExpansion, "node-expand-required", true, "Enables NodeServiceCapability_RPC_EXPAND_VOLUME capacity.")

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
google.golang.org/genproto v0.0.0-20201209185603-f92720507ed4 // indirect
1616
google.golang.org/grpc v1.34.0
1717
k8s.io/apimachinery v0.21.0-alpha.0
18+
k8s.io/klog/v2 v2.4.0
1819
k8s.io/kubernetes v1.20.0
1920
k8s.io/mount-utils v0.20.0 // indirect
2021
k8s.io/utils v0.0.0-20201110183641-67b214c5f920

pkg/hostpath/controllerserver.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"google.golang.org/grpc/status"
3434

3535
"github.com/container-storage-interface/spec/lib/go/csi"
36+
"k8s.io/klog/v2"
3637
utilexec "k8s.io/utils/exec"
3738

3839
"github.com/kubernetes-csi/csi-driver-host-path/pkg/state"
@@ -204,8 +205,12 @@ func (hp *hostPath) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeReque
204205
}
205206

206207
if vol.Attached || !vol.Published.Empty() || !vol.Staged.Empty() {
207-
return nil, status.Errorf(codes.Internal, "Volume '%s' is still used (attached: %v, staged: %v, published: %v) by '%s' node",
208+
msg := fmt.Sprintf("Volume '%s' is still used (attached: %v, staged: %v, published: %v) by '%s' node",
208209
vol.VolID, vol.Attached, vol.Staged, vol.Published, vol.NodeID)
210+
if hp.config.CheckVolumeLifecycle {
211+
return nil, status.Error(codes.Internal, msg)
212+
}
213+
klog.Warning(msg)
209214
}
210215

211216
if err := hp.deleteVolume(volId); err != nil {
@@ -340,8 +345,12 @@ func (hp *hostPath) ControllerUnpublishVolume(ctx context.Context, req *csi.Cont
340345

341346
// Check to see if the volume is staged/published on a node
342347
if !vol.Published.Empty() || !vol.Staged.Empty() {
343-
return nil, status.Errorf(codes.Internal, "Volume '%s' is still used (staged: %v, published: %v) by '%s' node",
348+
msg := fmt.Sprintf("Volume '%s' is still used (staged: %v, published: %v) by '%s' node",
344349
vol.VolID, vol.Staged, vol.Published, vol.NodeID)
350+
if hp.config.CheckVolumeLifecycle {
351+
return nil, status.Error(codes.Internal, msg)
352+
}
353+
klog.Warning(msg)
345354
}
346355

347356
vol.Attached = false

pkg/hostpath/hostpath.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ type Config struct {
7474
EnableAttach bool
7575
EnableTopology bool
7676
EnableVolumeExpansion bool
77+
CheckVolumeLifecycle bool
7778
}
7879

7980
var (

vendor/modules.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ k8s.io/apiserver/pkg/util/feature
154154
# k8s.io/component-base v0.20.0 => k8s.io/component-base v0.20.0
155155
k8s.io/component-base/featuregate
156156
# k8s.io/klog/v2 v2.4.0
157+
## explicit
157158
k8s.io/klog/v2
158159
# k8s.io/kubernetes v1.20.0
159160
## explicit

0 commit comments

Comments
 (0)