diff --git a/pkg/csi/cinder/controllerserver.go b/pkg/csi/cinder/controllerserver.go index 6c646889d0..b3dc2f95fe 100644 --- a/pkg/csi/cinder/controllerserver.go +++ b/pkg/csi/cinder/controllerserver.go @@ -365,7 +365,10 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS properties := map[string]string{cinderCSIClusterIDKey: cs.Driver.cluster} // see https://github.com/kubernetes-csi/external-snapshotter/pull/375/ - for _, mKey := range []string{"csi.storage.k8s.io/volumesnapshot/name", "csi.storage.k8s.io/volumesnapshot/namespace", "csi.storage.k8s.io/volumesnapshotcontent/name"} { + // Also, we don't want to tag every param but we still want to send the + // 'force-create' flag to openstack layer so that we will honor the + // force create functions + for _, mKey := range []string{"csi.storage.k8s.io/volumesnapshot/name", "csi.storage.k8s.io/volumesnapshot/namespace", "csi.storage.k8s.io/volumesnapshotcontent/name", openstack.SnapshotForceCreate} { if v, ok := req.Parameters[mKey]; ok { properties[mKey] = v } diff --git a/pkg/csi/cinder/controllerserver_test.go b/pkg/csi/cinder/controllerserver_test.go index c3585bca7c..91241af16f 100644 --- a/pkg/csi/cinder/controllerserver_test.go +++ b/pkg/csi/cinder/controllerserver_test.go @@ -494,6 +494,7 @@ func TestCreateSnapshotWithExtraMetadata(t *testing.T) { "csi.storage.k8s.io/volumesnapshot/name": FakeSnapshotName, "csi.storage.k8s.io/volumesnapshotcontent/name": FakeSnapshotContentName, "csi.storage.k8s.io/volumesnapshot/namespace": FakeSnapshotNamespace, + openstack.SnapshotForceCreate: "true", } osmock.On("CreateSnapshot", FakeSnapshotName, FakeVolID, &properties).Return(&FakeSnapshotRes, nil) @@ -511,6 +512,7 @@ func TestCreateSnapshotWithExtraMetadata(t *testing.T) { "csi.storage.k8s.io/volumesnapshot/name": FakeSnapshotName, "csi.storage.k8s.io/volumesnapshotcontent/name": FakeSnapshotContentName, "csi.storage.k8s.io/volumesnapshot/namespace": FakeSnapshotNamespace, + openstack.SnapshotForceCreate: "true", }, } diff --git a/pkg/csi/cinder/openstack/openstack_snapshots.go b/pkg/csi/cinder/openstack/openstack_snapshots.go index 478b5bfde4..1e1a54ac28 100644 --- a/pkg/csi/cinder/openstack/openstack_snapshots.go +++ b/pkg/csi/cinder/openstack/openstack_snapshots.go @@ -37,7 +37,7 @@ const ( snapReadySteps = 10 snapshotDescription = "Created by OpenStack Cinder CSI driver" - snapshotForceCreate = "force-create" + SnapshotForceCreate = "force-create" ) // CreateSnapshot issues a request to take a Snapshot of the specified Volume with the corresponding ID and @@ -47,14 +47,14 @@ func (os *OpenStack) CreateSnapshot(name, volID string, tags *map[string]string) force := false // if no flag given, then force will be false by default // if flag it given , check it - if item, ok := (*tags)[snapshotForceCreate]; ok { + if item, ok := (*tags)[SnapshotForceCreate]; ok { var err error force, err = strconv.ParseBool(item) if err != nil { klog.V(5).Infof("Make force create flag to false due to: %v", err) } - delete(*tags, snapshotForceCreate) + delete(*tags, SnapshotForceCreate) } // Force the creation of snapshot even the Volume is in in-use state opts := &snapshots.CreateOpts{