From bd925f6d8166a2fa7210cdb7d9cd7578a58c3a90 Mon Sep 17 00:00:00 2001 From: Pallav Date: Mon, 6 May 2024 20:47:04 +0000 Subject: [PATCH 1/2] vendor stork changes for PB-6903 --- go.mod | 2 +- go.sum | 4 +- .../stork/drivers/volume/volume.go | 28 +++++++++++++ .../controllers/applicationbackup.go | 41 +++++++++++++++++-- .../controllers/applicationrestore.go | 25 ++++++++--- .../pkg/resourcecollector/persistentvolume.go | 2 +- vendor/modules.txt | 2 +- 7 files changed, 90 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index d827333c1..1cec07a22 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/hashicorp/go-version v1.6.0 github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 github.com/kubernetes-incubator/external-storage v0.20.4-openstorage-rc7 - github.com/libopenstorage/stork v1.4.1-0.20240502172400-885982c36058 + github.com/libopenstorage/stork v1.4.1-0.20240506185157-275e4369d062 github.com/portworx/pxc v0.33.0 github.com/portworx/sched-ops v1.20.4-rc1.0.20240424153814-f3083bdb4578 github.com/sirupsen/logrus v1.9.3 diff --git a/go.sum b/go.sum index 781d94120..fc8ff9d46 100644 --- a/go.sum +++ b/go.sum @@ -3362,8 +3362,8 @@ github.com/libopenstorage/stork v1.4.1-0.20230502135851-9cacb19e1df5/go.mod h1:R github.com/libopenstorage/stork v1.4.1-0.20230519043154-cbc10dffaf19/go.mod h1:Xm4DHoViynFXMQKBXGj3IkA77LY2RBFkNtv6vbo3wNw= github.com/libopenstorage/stork v1.4.1-0.20230601053837-5dd68f026569/go.mod h1:+mKPMCPNhS/XOF2RPcNFijkr67CCCWp0o8OXVG6xxAk= github.com/libopenstorage/stork v1.4.1-0.20230610103146-72cf75320066/go.mod h1:Yst+fnOYjWk6SA5pXZBKm19wtiinjxQ/vgYTXI3k80Q= -github.com/libopenstorage/stork v1.4.1-0.20240502172400-885982c36058 h1:bjV6pxioNGTmK900pwF9UQ2Te5ov1lsoH+1jha9dFWg= -github.com/libopenstorage/stork v1.4.1-0.20240502172400-885982c36058/go.mod h1:kp5qtpq+BgjL5WqiOpDvbPH1WGReO5AaqXDbb+XpvzM= +github.com/libopenstorage/stork v1.4.1-0.20240506185157-275e4369d062 h1:wTiDcrROzCHYsyYfromjatlOwT4UWZSeKqjOcg/SlKY= +github.com/libopenstorage/stork v1.4.1-0.20240506185157-275e4369d062/go.mod h1:kp5qtpq+BgjL5WqiOpDvbPH1WGReO5AaqXDbb+XpvzM= github.com/libopenstorage/systemutils v0.0.0-20160208220149-44ac83be3ce1/go.mod h1:xwNGC7xiz/BQ/wbMkvHujL8Gjgseg+x41xMek7sKRRQ= github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0= github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE= diff --git a/vendor/github.com/libopenstorage/stork/drivers/volume/volume.go b/vendor/github.com/libopenstorage/stork/drivers/volume/volume.go index 5bd4b310d..acbfd2f6d 100644 --- a/vendor/github.com/libopenstorage/stork/drivers/volume/volume.go +++ b/vendor/github.com/libopenstorage/stork/drivers/volume/volume.go @@ -67,6 +67,16 @@ var ( CSIDriverName, KDMPDriverName, } + + orderedListOfDriversForRestore = []string{ + PortworxDriverName, + AWSDriverName, + AzureDriverName, + GCEDriverName, + LinstorDriverName, + CSIDriverName, + KDMPDriverName, + } ) // Driver defines an external volume driver interface. @@ -399,6 +409,24 @@ func GetPVDriver(pv *v1.PersistentVolume) (string, error) { } } +// GetPVDriverForRestore gets the driver associated with a PV. Returns ErrNotFound if the PV is +// not owned by any available driver +func GetPVDriverForRestore(pv *v1.PersistentVolume) (string, error) { + for _, driverName := range orderedListOfDriversForRestore { + driverInst, ok := volDrivers[driverName] + if !ok { + continue + } + if driverInst.OwnsPV(pv) { + return driverName, nil + } + } + return "", &errors.ErrNotSupported{ + Feature: "VolumeDriver", + Reason: fmt.Sprintf("PV %v provisioned using unsupported driver", pv.Name), + } +} + // ClusterPairNotSupported to be used by drivers that don't support pairing type ClusterPairNotSupported struct{} diff --git a/vendor/github.com/libopenstorage/stork/pkg/applicationmanager/controllers/applicationbackup.go b/vendor/github.com/libopenstorage/stork/pkg/applicationmanager/controllers/applicationbackup.go index d119c9d03..3da6b4452 100644 --- a/vendor/github.com/libopenstorage/stork/pkg/applicationmanager/controllers/applicationbackup.go +++ b/vendor/github.com/libopenstorage/stork/pkg/applicationmanager/controllers/applicationbackup.go @@ -439,6 +439,32 @@ func (a *ApplicationBackupController) handle(ctx context.Context, backup *stork_ return nil } + // if stork got restarted we would have got IncludeResource Memory map cleaned up. + // Hence re-create memory map of it. + if IsBackupObjectTypeVirtualMachine(backup) && + backup.Status.Stage != stork_api.ApplicationBackupStageInitial && + backup.Status.Stage != stork_api.ApplicationBackupStageImportResource && + (len(a.vmIncludeResource[string(backup.UID)]) == 0 || len(a.vmIncludeResourceMap[string(backup.UID)]) == 0) { + logrus.Infof("Stork seems restarted, repopulating VM resource Map for backup %v", backup.Name) + // First VMs from various filters provided. + vmList, objectMap, err := resourcecollector.GetVMIncludeListFromBackup(backup) + if err != nil { + logrus.Debugf("failed to import VM resources, after stork reboot. returning for retry") + return err + } + nsMap := make(map[string]bool) + // Second fetch VM resources from the list of filtered VMs and freeze/thaw rule for each of them. + // also set SkipVmAutoExecRules to true as we dont need to recreate it at this stage. + skipVmAutoRuleCommands := true + vmIncludeResources, objectMap, _, _ := resourcecollector.GetVMIncludeResourceInfoList(vmList, + objectMap, nsMap, skipVmAutoRuleCommands) + + // update in memory data structure for later use. + a.vmIncludeResourceMap[string(backup.UID)] = objectMap + a.vmIncludeResource[string(backup.UID)] = vmIncludeResources + a.vmNsListMap[string(backup.UID)] = nsMap + } + switch backup.Status.Stage { case stork_api.ApplicationBackupStageInitial: // Validate parameters @@ -750,6 +776,12 @@ func (a *ApplicationBackupController) backupVolumes(backup *stork_api.Applicatio var objectMap map[stork_api.ObjectInfo]bool if IsBackupObjectTypeVirtualMachine(backup) { objectMap = a.vmIncludeResourceMap[string(backup.UID)] + if len(objectMap) == 0 { + // for debugging purpose only. + // Its possible that will have empty rsources to backup during schedule backups due + // to vm or namespace being deleted. + logrus.Warnf("found empty includeResources for VM backup during volumeBakup stage") + } } else { objectMap = stork_api.CreateObjectsMap(backup.Spec.IncludeResources) } @@ -1559,7 +1591,6 @@ func (a *ApplicationBackupController) uploadObject( if err != nil { return err } - _, err = writer.Write(data) if err != nil { closeErr := writer.Close() @@ -1776,10 +1807,15 @@ func (a *ApplicationBackupController) backupResources( var objectMap map[stork_api.ObjectInfo]bool if IsBackupObjectTypeVirtualMachine(backup) { objectMap = a.vmIncludeResourceMap[string(backup.UID)] + if len(objectMap) == 0 { + // for debugging purpose + // its possible we will not have any resources during schedule backups due + // vm or namespace deletions + logrus.Warnf("found empty resources for VM backup during resourceBackup stage...") + } } else { objectMap = stork_api.CreateObjectsMap(backup.Spec.IncludeResources) } - namespacelist := backup.Spec.Namespaces // GetResources takes more time, if we have more number of namespaces // So, submitting it in batches and in between each batch, @@ -1927,7 +1963,6 @@ func (a *ApplicationBackupController) backupResources( } return nil } - // Do any additional preparation for the resources if required if err = a.prepareResources(backup, allObjects); err != nil { message := fmt.Sprintf("Error preparing resources for backup: %v", err) diff --git a/vendor/github.com/libopenstorage/stork/pkg/applicationmanager/controllers/applicationrestore.go b/vendor/github.com/libopenstorage/stork/pkg/applicationmanager/controllers/applicationrestore.go index c7f302a89..be82f6c61 100644 --- a/vendor/github.com/libopenstorage/stork/pkg/applicationmanager/controllers/applicationrestore.go +++ b/vendor/github.com/libopenstorage/stork/pkg/applicationmanager/controllers/applicationrestore.go @@ -1319,7 +1319,6 @@ func getNamespacedPVCLocation(pvc *v1.PersistentVolumeClaim) string { // getPVCToPVMapping constructs a mapping of PVC name/namespace to PV objects func getPVCToPVMapping(allObjects []runtime.Unstructured) (map[string]*v1.PersistentVolume, error) { - // Get mapping of PVC name to PV name pvNameToPVCName := make(map[string]string) for _, o := range allObjects { @@ -1365,7 +1364,7 @@ func getPVCToPVMapping(allObjects []runtime.Unstructured) (map[string]*v1.Persis } func isGenericCSIPersistentVolume(pv *v1.PersistentVolume) (bool, error) { - driverName, err := volume.GetPVDriver(pv) + driverName, err := volume.GetPVDriverForRestore(pv) if err != nil { return false, err } @@ -1599,10 +1598,24 @@ func (a *ApplicationRestoreController) applyResources( namespacedName := types.NamespacedName{} namespacedName.Namespace = restore.Namespace namespacedName.Name = restore.Name - - pvNameMappings, err := a.getPVNameMappings(restore, objects) - if err != nil { - return err + // The applyResources is getting called in both the volume stage and resource stage. + // In the volume stage, it is getting called for applying the preRestore object. + // During the volume stage, we will not have restoreVolume updated in the volumeInfo structure. + // In between two driver's PVC restore processing, there is a chance that applicationrestore CR will status.VolumeInfo + // updated with the basic information of the volume, with out restoreVolume name. + // List of prerestore resource for each driver is as follow: + // aws, azure, gke driver does not have any preRestore object. + // kdmp - restore PVC spec but we do not apply it in the volume stage, as we do not call applyResource for kdmp case. + // PXD - for px volumes, we apply the secrets of encrypted volumes. + // That means , we do not need to call getPVNameMappings during volume stage. + // So, avoiding the call to getPVNameMappings, if it getting called from volume stage. + var pvNameMappings map[string]string + var err error + if restore.Status.Stage != storkapi.ApplicationRestoreStageVolumes { + pvNameMappings, err = a.getPVNameMappings(restore, objects) + if err != nil { + return err + } } objectMap := storkapi.CreateObjectsMap(restore.Spec.IncludeResources) tempObjects := make([]runtime.Unstructured, 0) diff --git a/vendor/github.com/libopenstorage/stork/pkg/resourcecollector/persistentvolume.go b/vendor/github.com/libopenstorage/stork/pkg/resourcecollector/persistentvolume.go index 982288fa4..89b889e76 100644 --- a/vendor/github.com/libopenstorage/stork/pkg/resourcecollector/persistentvolume.go +++ b/vendor/github.com/libopenstorage/stork/pkg/resourcecollector/persistentvolume.go @@ -207,7 +207,7 @@ func (r *ResourceCollector) preparePVResourceForApply( // checks proper driver by looking at pv name if driverName == "" { var err error - driverName, err = volume.GetPVDriver(&pv) + driverName, err = volume.GetPVDriverForRestore(&pv) if err != nil { return false, err } diff --git a/vendor/modules.txt b/vendor/modules.txt index aa5c51fc2..f78e00cf9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -441,7 +441,7 @@ github.com/libopenstorage/openstorage-sdk-clients/sdk/golang github.com/libopenstorage/secrets github.com/libopenstorage/secrets/aws/credentials github.com/libopenstorage/secrets/k8s -# github.com/libopenstorage/stork v1.4.1-0.20240502172400-885982c36058 +# github.com/libopenstorage/stork v1.4.1-0.20240506185157-275e4369d062 ## explicit; go 1.21 github.com/libopenstorage/stork/drivers github.com/libopenstorage/stork/drivers/volume From 9949f66e4fecbca94b7df34aba24134e2ed29d84 Mon Sep 17 00:00:00 2001 From: Pallav Date: Mon, 6 May 2024 20:50:32 +0000 Subject: [PATCH 2/2] Fix Cloud Native Restore Path --- pkg/executor/nfs/nfsrestoreresources.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/executor/nfs/nfsrestoreresources.go b/pkg/executor/nfs/nfsrestoreresources.go index 2a3424c10..c92143f71 100644 --- a/pkg/executor/nfs/nfsrestoreresources.go +++ b/pkg/executor/nfs/nfsrestoreresources.go @@ -384,7 +384,7 @@ func getPVCToPVMapping(allObjects []runtime.Unstructured) (map[string]*v1.Persis } func isGenericCSIPersistentVolume(pv *v1.PersistentVolume) (bool, error) { - driverName, err := volume.GetPVDriver(pv) + driverName, err := volume.GetPVDriverForRestore(pv) if err != nil { return false, err }