From 5f9e92afb9a2ceba3d9c8d5abb1db0591bdef3a8 Mon Sep 17 00:00:00 2001 From: Adam Krpan Date: Thu, 13 Jun 2024 20:01:24 +0000 Subject: [PATCH] PWX-37650: Supports adding the pod name as a locator label for clone/snap restore Signed-off-by: Adam Krpan --- api/api.go | 8 ++++++++ api/server/sdk/volume_ops.go | 6 ++++-- csi/controller.go | 9 ++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/api/api.go b/api/api.go index 978d0f400..e8ad01563 100644 --- a/api/api.go +++ b/api/api.go @@ -1332,6 +1332,14 @@ func (v *VolumeSpec) IsNFSProxyVolume() bool { return v.GetProxySpec() != nil && v.GetProxySpec().NfsSpec != nil } +// GetFADAPodName returns the FlashArray Pod name specified in the Pure Block spec, or empty if any fields are unspecified +func (v *VolumeSpec) GetFADAPodName() string { + if v.GetProxySpec() != nil && v.GetProxySpec().PureBlockSpec != nil { + return v.GetProxySpec().PureBlockSpec.PodName + } + return "" +} + // GetCloneCreatorOwnership returns the appropriate ownership for the // new snapshot and if an update is required func (v *VolumeSpec) GetCloneCreatorOwnership(ctx context.Context) (*Ownership, bool) { diff --git a/api/server/sdk/volume_ops.go b/api/server/sdk/volume_ops.go index cb2f84593..ba99d91d0 100644 --- a/api/server/sdk/volume_ops.go +++ b/api/server/sdk/volume_ops.go @@ -172,7 +172,8 @@ func (s *VolumeServer) create( // Create a snapshot from the parent id, err = s.driver(ctx).Snapshot(ctx, parent.GetId(), false, &api.VolumeLocator{ - Name: volName, + Name: volName, + VolumeLabels: locator.GetVolumeLabels(), }, false) if err != nil { if err == kvdb.ErrNotFound { @@ -335,7 +336,8 @@ func (s *VolumeServer) Clone( } locator := &api.VolumeLocator{ - Name: req.GetName(), + Name: req.GetName(), + VolumeLabels: req.GetAdditionalLabels(), } source := &api.Source{ Parent: req.GetParentId(), diff --git a/csi/controller.go b/csi/controller.go index a9a3aa75f..65a8700aa 100644 --- a/csi/controller.go +++ b/csi/controller.go @@ -60,6 +60,9 @@ const ( csiPVCNameKey = "csi.storage.k8s.io/pvc/name" csiPVCNamespaceKey = "csi.storage.k8s.io/pvc/namespace" + // FADAPodLabelKey is a label added to volume locators in the case of FADA volume clone/snap restore + FADAPodLabelKey = "pure-pod-name" // Used to plumb in the pod name for volume cloning + volumeCapabilityMessageMultinodeVolume = "Volume is a multinode volume" volumeCapabilityMessageNotMultinodeVolume = "Volume is not a multinode volume" volumeCapabilityMessageReadOnlyVolume = "Volume is read only" @@ -614,10 +617,14 @@ func (s *OsdCsiServer) CreateVolume( } newVolumeId = createResp.VolumeId } else { + clonedMetadata := getClonedPVCMetadata(locator) + if spec.GetFADAPodName() != "" { + clonedMetadata[FADAPodLabelKey] = spec.GetFADAPodName() + } cloneResp, err := volumes.Clone(ctx, &api.SdkVolumeCloneRequest{ Name: req.GetName(), ParentId: source.Parent, - AdditionalLabels: getClonedPVCMetadata(locator), + AdditionalLabels: clonedMetadata, }) if err != nil { return nil, err