From 2ad0d93dbebb2499db0e239a5eb91ff5a3de33b1 Mon Sep 17 00:00:00 2001 From: Leela Venkaiah G Date: Fri, 19 Apr 2024 17:26:49 +0530 Subject: [PATCH] provider: avoid CSI secret name collisions provider sends the ceph client secret name to onboarded consumer as gRPC response, however if both provider & client operators running in same namespaces the secrets referred will collide. So, we'll send different secret names with same content to be created by client. Signed-off-by: Leela Venkaiah G --- services/provider/server/server.go | 105 ++++++++---------- services/provider/server/server_test.go | 90 +++++++-------- services/provider/server/storagerequest.go | 62 ++++++----- .../provider/server/storagerequest_test.go | 2 +- 4 files changed, 119 insertions(+), 140 deletions(-) diff --git a/services/provider/server/server.go b/services/provider/server/server.go index a7c64bae7e..b7e981824b 100644 --- a/services/provider/server/server.go +++ b/services/provider/server/server.go @@ -520,6 +520,10 @@ func (s *OCSProviderServer) RevokeStorageClaim(ctx context.Context, req *pb.Revo return &pb.RevokeStorageClaimResponse{}, nil } +func storageClaimCephCsiSecretName(secretType, suffix string) string { + return fmt.Sprintf("ceph-client-%s-%s", secretType, suffix) +} + // GetStorageClaim RPC call to get the ceph resources for the StorageClaim. func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.StorageClaimConfigRequest) (*pb.StorageClaimConfigResponse, error) { storageRequest, err := s.storageRequestManager.Get(ctx, req.StorageConsumerUUID, req.StorageClaimName) @@ -550,16 +554,15 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S } var extR []*pb.ExternalResource - var storageClassName string - storageClassData := map[string]string{} - + storageRequestHash := getStorageRequestHash(req.StorageConsumerUUID, req.StorageClaimName) for _, cephRes := range storageRequest.Status.CephResources { switch cephRes.Kind { case "CephClient": - clientSecretName, _, err := s.getCephClientInformation(ctx, cephRes.Name) + clientSecretName, clientUserType, err := s.getCephClientInformation(ctx, cephRes.Name) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } + extSecretName := storageClaimCephCsiSecretName(clientUserType, storageRequestHash) cephUserSecret := &v1.Secret{} err = s.client.Get(ctx, types.NamespacedName{Name: clientSecretName, Namespace: s.namespace}, cephUserSecret) @@ -574,10 +577,7 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S keyProp = "adminKey" } extR = append(extR, &pb.ExternalResource{ - // a common suffix '.csi' is being added to distinguish secrets that are created - // by ocs-client-operator vs rook-operator when both these operators are deployed in same namespace - // TODO: need to transform existing secrets during migration manually - Name: clientSecretName + ".csi", + Name: extSecretName, Kind: "Secret", Data: mustMarshal(map[string]string{ idProp: cephRes.Name, @@ -586,19 +586,6 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S }) case "CephBlockPoolRadosNamespace": - storageClassName = "ceph-rbd" - storageClassData["clusterID"] = s.namespace - storageClassData["radosnamespace"] = cephRes.Name - - nodeCephClientSecret, _, err := s.getCephClientInformation(ctx, cephRes.CephClients["node"]) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - - provisionerCephClientSecret, _, err := s.getCephClientInformation(ctx, cephRes.CephClients["provisioner"]) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } rns := &rookCephv1.CephBlockPoolRadosNamespace{} err = s.client.Get(ctx, types.NamespacedName{Name: cephRes.Name, Namespace: s.namespace}, rns) @@ -606,24 +593,36 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S return nil, status.Errorf(codes.Internal, "failed to get %s CephBlockPoolRadosNamespace. %v", cephRes.Name, err) } - storageClassData["pool"] = rns.Spec.BlockPoolName - storageClassData["imageFeatures"] = "layering,deep-flatten,exclusive-lock,object-map,fast-diff" - storageClassData["csi.storage.k8s.io/fstype"] = "ext4" - storageClassData["imageFormat"] = "2" - storageClassData["csi.storage.k8s.io/provisioner-secret-name"] = provisionerCephClientSecret - storageClassData["csi.storage.k8s.io/node-stage-secret-name"] = nodeCephClientSecret - storageClassData["csi.storage.k8s.io/controller-expand-secret-name"] = provisionerCephClientSecret + provisionerSecretName := storageClaimCephCsiSecretName("provisioner", storageRequestHash) + nodeSecretName := storageClaimCephCsiSecretName("node", storageRequestHash) + rbdStorageClassData := map[string]string{ + "clusterID": s.namespace, + "radosnamespace": cephRes.Name, + "pool": rns.Spec.BlockPoolName, + "imageFeatures": "layering,deep-flatten,exclusive-lock,object-map,fast-diff", + "csi.storage.k8s.io/fstype": "ext4", + "imageFormat": "2", + "csi.storage.k8s.io/provisioner-secret-name": provisionerSecretName, + "csi.storage.k8s.io/node-stage-secret-name": nodeSecretName, + "csi.storage.k8s.io/controller-expand-secret-name": provisionerSecretName, + } if storageRequest.Spec.EncryptionMethod != "" { - storageClassData["encrypted"] = "true" - storageClassData["encryptionKMSID"] = storageRequest.Spec.EncryptionMethod + rbdStorageClassData["encrypted"] = "true" + rbdStorageClassData["encryptionKMSID"] = storageRequest.Spec.EncryptionMethod } + extR = append(extR, &pb.ExternalResource{ + Name: "ceph-rbd", + Kind: "StorageClass", + Data: mustMarshal(rbdStorageClassData), + }) + extR = append(extR, &pb.ExternalResource{ Name: "ceph-rbd", Kind: "VolumeSnapshotClass", Data: mustMarshal(map[string]string{ - "clusterID": storageClassData["clusterID"], - "csi.storage.k8s.io/snapshotter-secret-name": provisionerCephClientSecret, + "clusterID": rbdStorageClassData["clusterID"], + "csi.storage.k8s.io/snapshotter-secret-name": provisionerSecretName, })}) case "CephFilesystemSubVolumeGroup": @@ -633,24 +632,23 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S return nil, status.Errorf(codes.Internal, "failed to get %s cephFilesystemSubVolumeGroup. %v", cephRes.Name, err) } - nodeCephClientSecret, _, err := s.getCephClientInformation(ctx, cephRes.CephClients["node"]) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - - provisionerCephClientSecret, _, err := s.getCephClientInformation(ctx, cephRes.CephClients["provisioner"]) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) + provisionerSecretName := storageClaimCephCsiSecretName("provisioner", storageRequestHash) + nodeSecretName := storageClaimCephCsiSecretName("node", storageRequestHash) + cephfsStorageClassData := map[string]string{ + "clusterID": getSubVolumeGroupClusterID(subVolumeGroup), + "subvolumegroupname": subVolumeGroup.Name, + "fsName": subVolumeGroup.Spec.FilesystemName, + "pool": subVolumeGroup.GetLabels()[v1alpha1.CephFileSystemDataPoolLabel], + "csi.storage.k8s.io/provisioner-secret-name": provisionerSecretName, + "csi.storage.k8s.io/node-stage-secret-name": nodeSecretName, + "csi.storage.k8s.io/controller-expand-secret-name": provisionerSecretName, } - storageClassName = "cephfs" - storageClassData["clusterID"] = getSubVolumeGroupClusterID(subVolumeGroup) - storageClassData["subvolumegroupname"] = subVolumeGroup.Name - storageClassData["fsName"] = subVolumeGroup.Spec.FilesystemName - storageClassData["pool"] = subVolumeGroup.GetLabels()[v1alpha1.CephFileSystemDataPoolLabel] - storageClassData["csi.storage.k8s.io/provisioner-secret-name"] = provisionerCephClientSecret - storageClassData["csi.storage.k8s.io/node-stage-secret-name"] = nodeCephClientSecret - storageClassData["csi.storage.k8s.io/controller-expand-secret-name"] = provisionerCephClientSecret + extR = append(extR, &pb.ExternalResource{ + Name: "cephfs", + Kind: "StorageClass", + Data: mustMarshal(cephfsStorageClassData), + }) extR = append(extR, &pb.ExternalResource{ Name: cephRes.Name, @@ -664,20 +662,11 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S Kind: "VolumeSnapshotClass", Data: mustMarshal(map[string]string{ "clusterID": getSubVolumeGroupClusterID(subVolumeGroup), - "csi.storage.k8s.io/snapshotter-secret-name": provisionerCephClientSecret, + "csi.storage.k8s.io/snapshotter-secret-name": provisionerSecretName, })}) } } - if storageClassName == "" { - return nil, status.Error(codes.Internal, "No StorageClass was defined") - } - extR = append(extR, &pb.ExternalResource{ - Name: storageClassName, - Kind: "StorageClass", - Data: mustMarshal(storageClassData), - }) - klog.Infof("successfully returned the storage class claim %q for %q", req.StorageClaimName, req.StorageConsumerUUID) return &pb.StorageClaimConfigResponse{ExternalResource: extR}, nil diff --git a/services/provider/server/server_test.go b/services/provider/server/server_test.go index b925499ebe..25f58c80b6 100644 --- a/services/provider/server/server_test.go +++ b/services/provider/server/server_test.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "strconv" - "strings" "testing" ocsv1alpha1 "github.com/red-hat-storage/ocs-operator/api/v4/v1alpha1" @@ -499,9 +498,9 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { "imageFeatures": "layering,deep-flatten,exclusive-lock,object-map,fast-diff", "csi.storage.k8s.io/fstype": "ext4", "imageFormat": "2", - "csi.storage.k8s.io/provisioner-secret-name": "rook-ceph-client-3de200d5c23524a4612bde1fdbeb717e", - "csi.storage.k8s.io/node-stage-secret-name": "rook-ceph-client-995e66248ad3e8642de868f461cdd827", - "csi.storage.k8s.io/controller-expand-secret-name": "rook-ceph-client-3de200d5c23524a4612bde1fdbeb717e", + "csi.storage.k8s.io/provisioner-secret-name": "ceph-client-provisioner-8d40b6be71600457b5dec219d2ce2d4c", + "csi.storage.k8s.io/node-stage-secret-name": "ceph-client-node-8d40b6be71600457b5dec219d2ce2d4c", + "csi.storage.k8s.io/controller-expand-secret-name": "ceph-client-provisioner-8d40b6be71600457b5dec219d2ce2d4c", }, }, "ceph-rbd-volumesnapshotclass": { @@ -509,19 +508,19 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { Kind: "VolumeSnapshotClass", Data: map[string]string{ "clusterID": serverNamespace, - "csi.storage.k8s.io/snapshotter-secret-name": "rook-ceph-client-3de200d5c23524a4612bde1fdbeb717e", + "csi.storage.k8s.io/snapshotter-secret-name": "ceph-client-provisioner-8d40b6be71600457b5dec219d2ce2d4c", }, }, - "rook-ceph-client-3de200d5c23524a4612bde1fdbeb717e": { - Name: "rook-ceph-client-3de200d5c23524a4612bde1fdbeb717e", + "ceph-client-provisioner-8d40b6be71600457b5dec219d2ce2d4c": { + Name: "ceph-client-provisioner-8d40b6be71600457b5dec219d2ce2d4c", Kind: "Secret", Data: map[string]string{ "userID": "3de200d5c23524a4612bde1fdbeb717e", "userKey": "AQADw/hhqBOcORAAJY3fKIvte++L/zYhASjYPQ==", }, }, - "rook-ceph-client-995e66248ad3e8642de868f461cdd827": { - Name: "rook-ceph-client-995e66248ad3e8642de868f461cdd827", + "ceph-client-node-8d40b6be71600457b5dec219d2ce2d4c": { + Name: "ceph-client-node-8d40b6be71600457b5dec219d2ce2d4c", Kind: "Secret", Data: map[string]string{ "userID": "995e66248ad3e8642de868f461cdd827", @@ -539,9 +538,9 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { "fsName": "myfs", "subvolumegroupname": "cephFilesystemSubVolumeGroup", "pool": "", - "csi.storage.k8s.io/provisioner-secret-name": "rook-ceph-client-4ffcb503ff8044c8699dac415f82d604", - "csi.storage.k8s.io/node-stage-secret-name": "rook-ceph-client-1b042fcc8812fe4203689eec38fdfbfa", - "csi.storage.k8s.io/controller-expand-secret-name": "rook-ceph-client-4ffcb503ff8044c8699dac415f82d604", + "csi.storage.k8s.io/provisioner-secret-name": "ceph-client-provisioner-0e8555e6556f70d23a61675af44e880c", + "csi.storage.k8s.io/node-stage-secret-name": "ceph-client-node-0e8555e6556f70d23a61675af44e880c", + "csi.storage.k8s.io/controller-expand-secret-name": "ceph-client-provisioner-0e8555e6556f70d23a61675af44e880c", }, }, "cephfs-volumesnapshotclass": { @@ -549,19 +548,19 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { Kind: "VolumeSnapshotClass", Data: map[string]string{ "clusterID": "8d26c7378c1b0ec9c2455d1c3601c4cd", - "csi.storage.k8s.io/snapshotter-secret-name": "rook-ceph-client-4ffcb503ff8044c8699dac415f82d604", + "csi.storage.k8s.io/snapshotter-secret-name": "ceph-client-provisioner-0e8555e6556f70d23a61675af44e880c", }, }, - "rook-ceph-client-4ffcb503ff8044c8699dac415f82d604": { - Name: "rook-ceph-client-4ffcb503ff8044c8699dac415f82d604", + "ceph-client-provisioner-0e8555e6556f70d23a61675af44e880c": { + Name: "ceph-client-provisioner-0e8555e6556f70d23a61675af44e880c", Kind: "Secret", Data: map[string]string{ "adminID": "4ffcb503ff8044c8699dac415f82d604", "adminKey": "AQADw/hhqBOcORAAJY3fKIvte++L/zYhASjYPQ==", }, }, - "rook-ceph-client-1b042fcc8812fe4203689eec38fdfbfa": { - Name: "rook-ceph-client-1b042fcc8812fe4203689eec38fdfbfa", + "ceph-client-node-0e8555e6556f70d23a61675af44e880c": { + Name: "ceph-client-node-0e8555e6556f70d23a61675af44e880c", Kind: "Secret", Data: map[string]string{ "adminID": "1b042fcc8812fe4203689eec38fdfbfa", @@ -708,14 +707,14 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { }, Status: &rookCephv1.CephClientStatus{ Info: map[string]string{ - "secretName": "rook-ceph-client-995e66248ad3e8642de868f461cdd827", + "secretName": "ceph-client-node-8d40b6be71600457b5dec219d2ce2d4c", }, }, } secret := &v1.Secret{ ObjectMeta: metav1.ObjectMeta{ - Name: "rook-ceph-client-995e66248ad3e8642de868f461cdd827", + Name: "ceph-client-node-8d40b6be71600457b5dec219d2ce2d4c", Namespace: server.namespace, }, Data: map[string][]byte{ @@ -738,14 +737,14 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { }, Status: &rookCephv1.CephClientStatus{ Info: map[string]string{ - "secretName": "rook-ceph-client-3de200d5c23524a4612bde1fdbeb717e", + "secretName": "ceph-client-provisioner-8d40b6be71600457b5dec219d2ce2d4c", }, }, } secret = &v1.Secret{ ObjectMeta: metav1.ObjectMeta{ - Name: "rook-ceph-client-3de200d5c23524a4612bde1fdbeb717e", + Name: "ceph-client-provisioner-8d40b6be71600457b5dec219d2ce2d4c", Namespace: server.namespace, }, Data: map[string][]byte{ @@ -768,14 +767,14 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { }, Status: &rookCephv1.CephClientStatus{ Info: map[string]string{ - "secretName": "rook-ceph-client-1b042fcc8812fe4203689eec38fdfbfa", + "secretName": "ceph-client-node-0e8555e6556f70d23a61675af44e880c", }, }, } secret = &v1.Secret{ ObjectMeta: metav1.ObjectMeta{ - Name: "rook-ceph-client-1b042fcc8812fe4203689eec38fdfbfa", + Name: "ceph-client-node-0e8555e6556f70d23a61675af44e880c", Namespace: server.namespace, }, Data: map[string][]byte{ @@ -798,14 +797,14 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { }, Status: &rookCephv1.CephClientStatus{ Info: map[string]string{ - "secretName": "rook-ceph-client-4ffcb503ff8044c8699dac415f82d604", + "secretName": "ceph-client-provisioner-0e8555e6556f70d23a61675af44e880c", }, }, } secret = &v1.Secret{ ObjectMeta: metav1.ObjectMeta{ - Name: "rook-ceph-client-4ffcb503ff8044c8699dac415f82d604", + Name: "ceph-client-provisioner-0e8555e6556f70d23a61675af44e880c", Namespace: server.namespace, }, Data: map[string][]byte{ @@ -854,10 +853,6 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { name = fmt.Sprintf("%s-volumesnapshotclass", name) } else if extResource.Kind == "StorageClass" { name = fmt.Sprintf("%s-storageclass", name) - } else if extResource.Kind == "Secret" { - var found bool - name, found = strings.CutSuffix(name, ".csi") - assert.True(t, found) } mockResoruce, ok := mockBlockPoolClaimExtR[name] assert.True(t, ok) @@ -866,12 +861,7 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { assert.NoError(t, err) assert.Equal(t, string(extResource.Data), string(data)) assert.Equal(t, extResource.Kind, mockResoruce.Kind) - if extResource.Kind == "Secret" { - name, _ := strings.CutSuffix(name, ".csi") - assert.Equal(t, name, mockResoruce.Name) - } else { - assert.Equal(t, extResource.Name, mockResoruce.Name) - } + assert.Equal(t, extResource.Name, mockResoruce.Name) } // get the storage class request config for share filesystem @@ -890,10 +880,6 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { name = fmt.Sprintf("%s-volumesnapshotclass", name) } else if extResource.Kind == "StorageClass" { name = fmt.Sprintf("%s-storageclass", name) - } else if extResource.Kind == "Secret" { - var found bool - name, found = strings.CutSuffix(name, ".csi") - assert.True(t, found) } mockResoruce, ok := mockShareFilesystemClaimExtR[name] assert.True(t, ok) @@ -902,24 +888,24 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { assert.NoError(t, err) assert.Equal(t, string(extResource.Data), string(data)) assert.Equal(t, extResource.Kind, mockResoruce.Kind) - if extResource.Kind == "Secret" { - name, _ := strings.CutSuffix(name, ".csi") - assert.Equal(t, name, mockResoruce.Name) - } else { - assert.Equal(t, extResource.Name, mockResoruce.Name) - } + assert.Equal(t, extResource.Name, mockResoruce.Name) } // When ceph resources is empty + scrNameHash := getStorageRequestHash(string(consumerResource.UID), shareFilesystemClaimName) for _, i := range sharedFilesystemClaimResource.Status.CephResources { - if i.Kind == "CephClient" { - cephClient, secret := createCephClientAndSecret(i.Name, server) - cephClient.Status = &rookCephv1.CephClientStatus{ - Info: map[string]string{ - "secretName": fmt.Sprintf("rook-ceph-client-%s", i.Name), - }, + if i.Kind == "CephFilesystemSubVolumeGroup" { + for cephClientUserType, cephClientName := range i.CephClients { + cephClient, secret := createCephClientAndSecret(cephClientName, server) + secret.Name = storageClaimCephCsiSecretName(cephClientUserType, scrNameHash) + cephClient.Status = &rookCephv1.CephClientStatus{ + Info: map[string]string{ + "secretName": secret.Name, + }, + } + assert.NoError(t, client.Delete(ctx, secret)) } - assert.NoError(t, client.Delete(ctx, secret)) + break } } diff --git a/services/provider/server/storagerequest.go b/services/provider/server/storagerequest.go index d40c4954da..b0e95a40b2 100644 --- a/services/provider/server/storagerequest.go +++ b/services/provider/server/storagerequest.go @@ -32,37 +32,42 @@ func newStorageRequestManager(cl client.Client, namespace string) (*storageReque }, nil } -// getStorageRequestName generates a name for a StorageRequest resource. -func getStorageRequestName(consumerUUID, storageRequestName string) string { - var s struct { +// getStorageRequestHash generates a hash for a StorageRequest based +// on the MD5 hash of the StorageClaim name and storageConsumer UUID. +func getStorageRequestHash(consumerUUID, storageClaimName string) string { + s := struct { StorageConsumerUUID string `json:"storageConsumerUUID"` - StorageRequestName string `json:"storageRequestName"` + StorageClaimName string `json:"storageClaimName"` + }{ + consumerUUID, + storageClaimName, } - s.StorageConsumerUUID = consumerUUID - s.StorageRequestName = storageRequestName requestName, err := json.Marshal(s) if err != nil { klog.Errorf("failed to marshal a name for a storage class request based on %v. %v", s, err) panic("failed to marshal storage class request name") } - name := md5.Sum([]byte(requestName)) - // The name of the StorageRequest is the MD5 hash of the JSON - // representation of the StorageRequest name and storageConsumer UUID. - return fmt.Sprintf("storagerequest-%s", hex.EncodeToString(name[:16])) + md5Sum := md5.Sum(requestName) + return hex.EncodeToString(md5Sum[:16]) +} + +// getStorageRequestName generates a name for a StorageRequest resource. +func getStorageRequestName(consumerUUID, storageClaimName string) string { + return fmt.Sprintf("storagerequest-%s", getStorageRequestHash(consumerUUID, storageClaimName)) } // Create creates a new StorageRequest resource and returns the StorageRequest ID. func (s *storageRequestManager) Create( ctx context.Context, consumer *ocsv1alpha1.StorageConsumer, - storageRequestName, + storageClaimName, requestType, encryptionMethod, storageProfile string, ) error { consumerUUID := string(consumer.GetUID()) - generatedRequestName := getStorageRequestName(consumerUUID, storageRequestName) + generatedRequestName := getStorageRequestName(consumerUUID, storageClaimName) storageRequestObj := &ocsv1alpha1.StorageRequest{ ObjectMeta: metav1.ObjectMeta{ @@ -70,7 +75,7 @@ func (s *storageRequestManager) Create( Namespace: s.namespace, Labels: map[string]string{ controllers.ConsumerUUIDLabel: consumerUUID, - storageRequestNameLabel: storageRequestName, + storageRequestNameLabel: storageClaimName, }, }, Spec: ocsv1alpha1.StorageRequestSpec{ @@ -101,35 +106,35 @@ func (s *storageRequestManager) Create( err = s.client.Create(ctx, storageRequestObj) if err != nil { if !kerrors.IsAlreadyExists(err) { - return fmt.Errorf("failed to create a StorageRequest named %q for consumer %q and request %q. %w", generatedRequestName, consumerUUID, storageRequestName, err) + return fmt.Errorf("failed to create a StorageRequest named %q for consumer %q and request %q. %w", generatedRequestName, consumerUUID, storageClaimName, err) } newStorageRequestObj := &ocsv1alpha1.StorageRequest{} getErr := s.client.Get(ctx, client.ObjectKey{Name: generatedRequestName, Namespace: s.namespace}, newStorageRequestObj) if getErr != nil { - klog.Errorf("failed to get a StorageRequest named %q for consumer %q and request %q. %v", generatedRequestName, consumerUUID, storageRequestName, getErr) + klog.Errorf("failed to get a StorageRequest named %q for consumer %q and request %q. %v", generatedRequestName, consumerUUID, storageClaimName, getErr) return err } // check if the StorageRequest is getting deleted. if newStorageRequestObj.DeletionTimestamp != nil { - klog.Warningf("StorageRequest named %q for consumer %q and request %q is already created but is getting deleted", generatedRequestName, consumerUUID, storageRequestName) + klog.Warningf("StorageRequest named %q for consumer %q and request %q is already created but is getting deleted", generatedRequestName, consumerUUID, storageClaimName) return err } // check if the input is different if !reflect.DeepEqual(storageRequestObj.Spec, newStorageRequestObj.Spec) { - klog.Errorf("StorageRequest named %q for consumer %q and request %q is already exists with different spec (%v) but requested spec (%v)", generatedRequestName, consumerUUID, storageRequestName, storageRequestObj.Spec, newStorageRequestObj.Spec) + klog.Errorf("StorageRequest named %q for consumer %q and request %q is already exists with different spec (%v) but requested spec (%v)", generatedRequestName, consumerUUID, storageClaimName, storageRequestObj.Spec, newStorageRequestObj.Spec) return err } } - klog.Infof("successfully created a StorageRequest resource %q for consumer %q and request %q", generatedRequestName, consumerUUID, storageRequestName) + klog.Infof("successfully created a StorageRequest resource %q for consumer %q and request %q", generatedRequestName, consumerUUID, storageClaimName) return nil } -// Delete deletes the storagerequest resource using storageRequestName +// Delete deletes the storagerequest resource using storageClaimName // and consumerUUID. -func (s *storageRequestManager) Delete(ctx context.Context, consumerUUID, storageRequestName string) error { - generatedRequestName := getStorageRequestName(consumerUUID, storageRequestName) +func (s *storageRequestManager) Delete(ctx context.Context, consumerUUID, storageClaimName string) error { + generatedRequestName := getStorageRequestName(consumerUUID, storageClaimName) storageRequestObj := &ocsv1alpha1.StorageRequest{ ObjectMeta: metav1.ObjectMeta{ Name: generatedRequestName, @@ -143,25 +148,24 @@ func (s *storageRequestManager) Delete(ctx context.Context, consumerUUID, storag } if err := s.client.Delete(ctx, storageRequestObj, &deleteOption); err != nil { if kerrors.IsNotFound(err) { - klog.Warningf("StorageRequest %q not found for consumer %q and request %q", generatedRequestName, consumerUUID, storageRequestName) + klog.Warningf("StorageRequest %q not found for consumer %q and request %q", generatedRequestName, consumerUUID, storageClaimName) return nil } - return fmt.Errorf("failed to delete StorageRequest %q for consumer %q and request %q. %v", generatedRequestName, consumerUUID, storageRequestName, err) + return fmt.Errorf("failed to delete StorageRequest %q for consumer %q and request %q. %v", generatedRequestName, consumerUUID, storageClaimName, err) } - klog.Infof("successfully deleted StorageRequest %q for consumer %q and request %q", generatedRequestName, consumerUUID, storageRequestName) + klog.Infof("successfully deleted StorageRequest %q for consumer %q and request %q", generatedRequestName, consumerUUID, storageClaimName) return nil } -// Get returns the StorageRequest resource using storageRequestName -// and consumerUUID. -func (s *storageRequestManager) Get(ctx context.Context, consumerUUID, storageRequestName string) (*ocsv1alpha1.StorageRequest, error) { - generatedRequestName := getStorageRequestName(consumerUUID, storageRequestName) +// Get returns the StorageRequest resource using storageClaimName and consumerUUID. +func (s *storageRequestManager) Get(ctx context.Context, consumerUUID, storageClaimName string) (*ocsv1alpha1.StorageRequest, error) { + generatedRequestName := getStorageRequestName(consumerUUID, storageClaimName) storageRequestObj := &ocsv1alpha1.StorageRequest{} err := s.client.Get(ctx, types.NamespacedName{Name: generatedRequestName, Namespace: s.namespace}, storageRequestObj) if err != nil { - klog.Errorf("failed to get a StorageRequest named %q for consumer %q and request %q. %v", generatedRequestName, consumerUUID, storageRequestName, err) + klog.Errorf("failed to get a StorageRequest named %q for consumer %q and request %q. %v", generatedRequestName, consumerUUID, storageClaimName, err) return nil, err } diff --git a/services/provider/server/storagerequest_test.go b/services/provider/server/storagerequest_test.go index bf661f18d6..dc56a03a26 100644 --- a/services/provider/server/storagerequest_test.go +++ b/services/provider/server/storagerequest_test.go @@ -22,7 +22,7 @@ func Test_getStorageRequestsName(t *testing.T) { consumerUUID: "consumer-uuid", storageRequestName: "storage-class-request-name", }, - want: "storagerequest-fe41c72dae7cc263c394330a94f9081e", + want: "storagerequest-b0e8b1cae6add3a6b331f955874302ce", }, }