Skip to content

Commit b1a89bc

Browse files
CON-4285: Issues restoring Velero backups
Applying the fix from master branch to v3.0.0 branch Signed-off-by: Rohit Balakrishna <rohit.balakrishna@hpe.com>
1 parent f0cc8b1 commit b1a89bc

File tree

5 files changed

+50
-36
lines changed

5 files changed

+50
-36
lines changed

pkg/driver/constants.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ const (
9696
hostEncryptionSecretNamespaceKey = "hostEncryptionSecretNamespace"
9797
hostEncryptionPassphraseKey = "hostEncryptionPassphrase"
9898

99-
//PVC attributes propogated to the CSI
100-
pvcNameAttribute = "csi.storage.k8s.io/pvc/name"
101-
pvcNamespaceAttribute = "csi.storage.k8s.io/pvc/namespace"
102-
10399
// POD attributes propogated to the CSI
104100
csiEphemeralPodName = "csi.storage.k8s.io/pod.name"
105101
csiEphemeralPodNamespace = "csi.storage.k8s.io/pod.namespace"

pkg/driver/node_server.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,14 @@ func (driver *Driver) stageVolume(
517517
// Store mount info in the staging device
518518
stagingDevice.MountInfo = mountInfo
519519

520-
// CON-3010
521-
// Get the PVC details to identify the datasource of PVC
522-
if volumeContext[pvcNameAttribute] != "" && volumeContext[pvcNamespaceAttribute] != "" {
523-
pvc, err := driver.flavor.GetPVCByName(volumeContext[pvcNameAttribute], volumeContext[pvcNamespaceAttribute])
520+
// Retrieve PVC spec for dataSource inspection for regular PVCs
521+
if isEphemeral(volumeContext) == false {
522+
pvc, err := driver.flavor.GetPVCByVolumeID(volumeID)
523+
524524
if err != nil {
525-
return nil, status.Error(codes.Internal, fmt.Sprintf("Error getting pvc data source for volume %v, %v", volumeID, err))
525+
return nil, status.Error(codes.Internal, fmt.Sprintf("Error getting PVC from volumeID %v, %v", volumeID, err))
526526
}
527+
527528
if pvc.Spec.DataSource != nil {
528529

529530
// If the DataSource is a VolumeSnapshot
@@ -533,31 +534,30 @@ func (driver *Driver) stageVolume(
533534
IsVolumeClone = true
534535
}
535536
}
536-
}
537537

538-
// Check whether volume is created from snapshot then only we need resize
539-
if IsVolumeClone {
540-
// Initialize resizeFs
541-
r := mountutil.NewResizeFs(exec.New())
538+
// Check whether volume is created from snapshot then only we need resize
539+
if IsVolumeClone {
540+
// Initialize resizeFs
541+
r := mountutil.NewResizeFs(exec.New())
542542

543-
log.Infof("Verify whether resize required for device path %v ", device.AltFullPathName)
543+
log.Infof("Verify whether resize required for device path %v ", device.AltFullPathName)
544544

545-
// check whether we need resize for file system
546-
needResize, err := r.NeedResize(device.AltFullPathName, stagingMountPoint)
547-
if err != nil {
548-
return nil, status.Errorf(codes.Internal, "Could not determine if volume %q need to be resized, error: %v", volumeID, err)
549-
}
550-
log.Infof("Need resize for filesystem: %v", needResize)
545+
// check whether we need resize for file system
546+
needResize, err := r.NeedResize(device.AltFullPathName, stagingMountPoint)
547+
if err != nil {
548+
return nil, status.Errorf(codes.Internal, "Could not determine if volume %q need to be resized, error: %v", volumeID, err)
549+
}
550+
log.Infof("Need resize for filesystem: %v", needResize)
551551

552-
if needResize {
553-
log.Infof("Resize of target path %s is required ", device.AltFullPathName)
554-
if _, err := r.Resize(device.AltFullPathName, stagingMountPoint); err != nil {
555-
return nil, status.Errorf(codes.Internal, "Could not resize volume %q, error : %v", volumeID, err)
552+
if needResize {
553+
log.Infof("Resize of target path %s is required ", device.AltFullPathName)
554+
if _, err := r.Resize(device.AltFullPathName, stagingMountPoint); err != nil {
555+
return nil, status.Errorf(codes.Internal, "Could not resize volume %q, error : %v", volumeID, err)
556+
}
557+
log.Infof("Resize of target path %s is successful", device.AltFullPathName)
556558
}
557-
log.Infof("Resize of target path %s is successful", device.AltFullPathName)
558559
}
559560
}
560-
// CON-3010
561561

562562
return stagingDevice, nil
563563
}

pkg/flavor/kubernetes/flavor.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -690,18 +690,36 @@ func (flavor *Flavor) getPodByName(name string, namespace string) (*v1.Pod, erro
690690
return pod, nil
691691
}
692692

693-
// GetPVCByName to get the PVC details for given PVC name
694-
func (flavor *Flavor) GetPVCByName(name string, namespace string) (*v1.PersistentVolumeClaim, error) {
695-
log.Tracef(">>>>> GetPVCByName, name: %s, namespace: %s", name, namespace)
696-
defer log.Trace("<<<<< GetPVCByName")
693+
// GetPVCByVolumeID to get the PVC details for given volumeID
694+
func (flavor *Flavor) GetPVCByVolumeID(id string) (*v1.PersistentVolumeClaim, error) {
695+
log.Tracef(">>>>> GetPVCByVolumeID, id: %s", id)
696+
defer log.Trace("<<<<< GetPVCByVolumeID")
697+
698+
pv, err := flavor.kubeClient.CoreV1().PersistentVolumes().Get(context.Background(), id, meta_v1.GetOptions{})
697699

698-
pvc, err := flavor.kubeClient.CoreV1().PersistentVolumeClaims(namespace).Get(context.Background(), name, meta_v1.GetOptions{})
699700
if err != nil {
700-
log.Errorf("Error retrieving the pvc %s/%s, err: %v", namespace, name, err.Error())
701+
log.Errorf("Error retrieving the ID %s, err: %v", id, err.Error())
701702
return nil, err
702703
}
703704

704-
return pvc, nil
705+
if pv.Spec.ClaimRef != nil {
706+
707+
namespace := pv.Spec.ClaimRef.Namespace
708+
name := pv.Spec.ClaimRef.Name
709+
710+
pvc, err := flavor.kubeClient.CoreV1().PersistentVolumeClaims(namespace).Get(context.Background(), name, meta_v1.GetOptions{})
711+
if err != nil {
712+
log.Errorf("Error retrieving the PVC name %s in Namespace %s from claimRef of PV %s, error: %v", name, namespace, id, err.Error())
713+
return nil, err
714+
}
715+
716+
return pvc, nil
717+
718+
} else {
719+
err := fmt.Errorf("Error retrieving the claimRef of %s", id)
720+
log.Errorf("%v", err.Error())
721+
return nil, err
722+
}
705723
}
706724

707725
// makeVolumeHandle returns csi-<sha256(podUID,volSourceSpecName)>

pkg/flavor/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ type Flavor interface {
4545
ListVolumeAttachments() (*storage_v1.VolumeAttachmentList, error)
4646
GetChapCredentials(volumeContext map[string]string) (*model.ChapInfo, error)
4747
CheckConnection() bool
48-
GetPVCByName(name string, namespace string) (*v1.PersistentVolumeClaim, error)
48+
GetPVCByVolumeID(id string) (*v1.PersistentVolumeClaim, error)
4949
HandleFileNodePublish(request *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error)
5050
}

pkg/flavor/vanilla/flavor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (flavor *Flavor) CheckConnection() bool {
155155
}
156156

157157
//nolint:revive
158-
func (flavor *Flavor) GetPVCByName(name string, namespace string) (*v1.PersistentVolumeClaim, error) {
158+
func (flavor *Flavor) GetPVCByVolumeID(id string) (*v1.PersistentVolumeClaim, error) {
159159
return nil, nil
160160
}
161161

0 commit comments

Comments
 (0)