From b211146f2eff81893344431c9d199556f167cecf Mon Sep 17 00:00:00 2001 From: sivakumar subraani Date: Fri, 15 Nov 2024 16:00:16 +0000 Subject: [PATCH 1/2] vendor stork repo from release-24.3.4 branch. --- go.mod | 2 +- go.sum | 4 +- .../stork/drivers/volume/portworx/portworx.go | 2 +- .../stork/drivers/volume/volume.go | 6 + .../apis/stork/v1alpha1/applicationbackup.go | 5 +- .../stork/v1alpha1/zz_generated.deepcopy.go | 239 +++++++++++++++++- .../controllers/applicationbackup.go | 73 ++++-- vendor/modules.txt | 2 +- 8 files changed, 308 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index 5e3823657..325995018 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.20241029051218-6fcdc46e8ffc + github.com/libopenstorage/stork v1.4.1-0.20241115110516-1b6d535ef497 github.com/portworx/pxc v0.33.0 github.com/portworx/sched-ops v1.20.4-rc1.0.20240812234304-948bf116243e github.com/sirupsen/logrus v1.9.3 diff --git a/go.sum b/go.sum index e19faf732..155150836 100644 --- a/go.sum +++ b/go.sum @@ -3394,8 +3394,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.20241029051218-6fcdc46e8ffc h1:awMZ+7AxZQMSZQ8MXfJJfs/f1bQNeWyRTm2M7ZpiGUk= -github.com/libopenstorage/stork v1.4.1-0.20241029051218-6fcdc46e8ffc/go.mod h1:6LHv0kJyrIftmHrS+Xx59SCMqDdclnXdi14vrTafFxg= +github.com/libopenstorage/stork v1.4.1-0.20241115110516-1b6d535ef497 h1:abWQI7IIO+x0tASheueW/zzAC+Pvf9A7GwkcUDomnd8= +github.com/libopenstorage/stork v1.4.1-0.20241115110516-1b6d535ef497/go.mod h1:Ng/SWv7bO2fytEtt3FivXWscukhU2bvLKLkEKizt7F0= 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/portworx/portworx.go b/vendor/github.com/libopenstorage/stork/drivers/volume/portworx/portworx.go index 4eb38f7d6..276e9cf29 100644 --- a/vendor/github.com/libopenstorage/stork/drivers/volume/portworx/portworx.go +++ b/vendor/github.com/libopenstorage/stork/drivers/volume/portworx/portworx.go @@ -4385,7 +4385,7 @@ func (p *portworx) IsVirtualMachineSupported() bool { } func (p *portworx) getVirtLauncherPatches(podNamespace string, pod *v1.Pod) ([]k8sutils.JSONPatchOp, error) { - if pod.Labels["kubevirt.io"] != "virt-launcher" { + if pod.Labels["kubevirt.io"] != "virt-launcher" || storkvolume.SkipKubevirtPreloadStatfs { return nil, nil } diff --git a/vendor/github.com/libopenstorage/stork/drivers/volume/volume.go b/vendor/github.com/libopenstorage/stork/drivers/volume/volume.go index a20cc79e9..74d8a981e 100644 --- a/vendor/github.com/libopenstorage/stork/drivers/volume/volume.go +++ b/vendor/github.com/libopenstorage/stork/drivers/volume/volume.go @@ -77,6 +77,12 @@ var ( CSIDriverName, KDMPDriverName, } + + // `kubevirt-skip-preload-statfs=true` stork argument can be configured + // by the user as per their need through which stork can get to know if to + // actually create the configmap and mount the ld.so.preload and px_statfs.so + // shared lib onto the virt-launcher container. + SkipKubevirtPreloadStatfs bool ) // Driver defines an external volume driver interface. diff --git a/vendor/github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1/applicationbackup.go b/vendor/github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1/applicationbackup.go index 4f7dc5552..702b7677a 100644 --- a/vendor/github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1/applicationbackup.go +++ b/vendor/github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1/applicationbackup.go @@ -49,8 +49,9 @@ type ApplicationBackupSpec struct { BackupObjectType string `json:"backupObjectType"` // SkipAutoExecRules is false by default, if set true will skip auto exec rules for VM specific backup. // This field is unused for non VM specific Backup. - SkipAutoExecRules bool `json:"skipAutoExecRules"` - DirectKDMP bool `json:"directKDMP"` + SkipAutoExecRules bool `json:"skipAutoExecRules"` + DirectKDMP bool `json:"directKDMP"` + ExcludeResourceTypes []string `json:"excludeResourceTypes"` } // ApplicationBackupReclaimPolicyType is the reclaim policy for the application backup diff --git a/vendor/github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1/zz_generated.deepcopy.go b/vendor/github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1/zz_generated.deepcopy.go index ce39c0923..baf572326 100644 --- a/vendor/github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1/zz_generated.deepcopy.go +++ b/vendor/github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1/zz_generated.deepcopy.go @@ -32,7 +32,8 @@ func (in *Action) DeepCopyInto(out *Action) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) return } @@ -87,9 +88,46 @@ func (in *ActionList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ActionParameter) DeepCopyInto(out *ActionParameter) { + *out = *in + in.FailoverParameter.DeepCopyInto(&out.FailoverParameter) + in.FailbackParameter.DeepCopyInto(&out.FailbackParameter) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ActionParameter. +func (in *ActionParameter) DeepCopy() *ActionParameter { + if in == nil { + return nil + } + out := new(ActionParameter) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ActionParameterItem) DeepCopyInto(out *ActionParameterItem) { + *out = *in + in.FailoverParameter.DeepCopyInto(&out.FailoverParameter) + in.FailbackParameter.DeepCopyInto(&out.FailbackParameter) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ActionParameterItem. +func (in *ActionParameterItem) DeepCopy() *ActionParameterItem { + if in == nil { + return nil + } + out := new(ActionParameterItem) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ActionSpec) DeepCopyInto(out *ActionSpec) { *out = *in + in.ActionParameter.DeepCopyInto(&out.ActionParameter) return } @@ -103,6 +141,104 @@ func (in *ActionSpec) DeepCopy() *ActionSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ActionStatus) DeepCopyInto(out *ActionStatus) { + *out = *in + in.FinishTimestamp.DeepCopyInto(&out.FinishTimestamp) + if in.Summary != nil { + in, out := &in.Summary, &out.Summary + *out = new(ActionSummary) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ActionStatus. +func (in *ActionStatus) DeepCopy() *ActionStatus { + if in == nil { + return nil + } + out := new(ActionStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ActionSummary) DeepCopyInto(out *ActionSummary) { + *out = *in + if in.FailoverSummaryItem != nil { + in, out := &in.FailoverSummaryItem, &out.FailoverSummaryItem + *out = make([]*FailoverSummary, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(FailoverSummary) + **out = **in + } + } + } + if in.FailbackSummaryItem != nil { + in, out := &in.FailbackSummaryItem, &out.FailbackSummaryItem + *out = make([]*FailbackSummary, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(FailbackSummary) + **out = **in + } + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ActionSummary. +func (in *ActionSummary) DeepCopy() *ActionSummary { + if in == nil { + return nil + } + out := new(ActionSummary) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ActionSummaryItem) DeepCopyInto(out *ActionSummaryItem) { + *out = *in + if in.FailoverSummaryItem != nil { + in, out := &in.FailoverSummaryItem, &out.FailoverSummaryItem + *out = make([]*FailoverSummary, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(FailoverSummary) + **out = **in + } + } + } + if in.FailbackSummaryItem != nil { + in, out := &in.FailbackSummaryItem, &out.FailbackSummaryItem + *out = make([]*FailbackSummary, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(FailbackSummary) + **out = **in + } + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ActionSummaryItem. +func (in *ActionSummaryItem) DeepCopy() *ActionSummaryItem { + if in == nil { + return nil + } + out := new(ActionSummaryItem) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ApplicationBackup) DeepCopyInto(out *ApplicationBackup) { *out = *in @@ -347,6 +483,11 @@ func (in *ApplicationBackupSpec) DeepCopyInto(out *ApplicationBackupSpec) { (*out)[key] = val } } + if in.ExcludeResourceTypes != nil { + in, out := &in.ExcludeResourceTypes, &out.ExcludeResourceTypes + *out = make([]string, len(*in)) + copy(*out, *in) + } return } @@ -433,6 +574,7 @@ func (in *ApplicationBackupVolumeInfo) DeepCopyInto(out *ApplicationBackupVolume (*out)[key] = val } } + out.JobSecurityContext = in.JobSecurityContext return } @@ -1486,6 +1628,85 @@ func (in *ExportStatus) DeepCopy() *ExportStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *FailbackParameter) DeepCopyInto(out *FailbackParameter) { + *out = *in + if in.FailbackNamespaces != nil { + in, out := &in.FailbackNamespaces, &out.FailbackNamespaces + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FailbackParameter. +func (in *FailbackParameter) DeepCopy() *FailbackParameter { + if in == nil { + return nil + } + out := new(FailbackParameter) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *FailbackSummary) DeepCopyInto(out *FailbackSummary) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FailbackSummary. +func (in *FailbackSummary) DeepCopy() *FailbackSummary { + if in == nil { + return nil + } + out := new(FailbackSummary) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *FailoverParameter) DeepCopyInto(out *FailoverParameter) { + *out = *in + if in.FailoverNamespaces != nil { + in, out := &in.FailoverNamespaces, &out.FailoverNamespaces + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.SkipSourceOperations != nil { + in, out := &in.SkipSourceOperations, &out.SkipSourceOperations + *out = new(bool) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FailoverParameter. +func (in *FailoverParameter) DeepCopy() *FailoverParameter { + if in == nil { + return nil + } + out := new(FailoverParameter) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *FailoverSummary) DeepCopyInto(out *FailoverSummary) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FailoverSummary. +func (in *FailoverSummary) DeepCopy() *FailoverSummary { + if in == nil { + return nil + } + out := new(FailoverSummary) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *GoogleConfig) DeepCopyInto(out *GoogleConfig) { *out = *in @@ -1642,6 +1863,22 @@ func (in *IntervalPolicy) DeepCopy() *IntervalPolicy { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *JobSecurityContext) DeepCopyInto(out *JobSecurityContext) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JobSecurityContext. +func (in *JobSecurityContext) DeepCopy() *JobSecurityContext { + if in == nil { + return nil + } + out := new(JobSecurityContext) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in KindResourceTransform) DeepCopyInto(out *KindResourceTransform) { { 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 ca8e658c2..8f3302d75 100644 --- a/vendor/github.com/libopenstorage/stork/pkg/applicationmanager/controllers/applicationbackup.go +++ b/vendor/github.com/libopenstorage/stork/pkg/applicationmanager/controllers/applicationbackup.go @@ -847,7 +847,8 @@ func (a *ApplicationBackupController) backupVolumes(backup *stork_api.Applicatio // We could have case where includeResource has data, current ns is not part of includeResource // and the user has given ResourceType list and ResourceType does not contain PVC. In this case we don't // want to collect vol data from this ns - if len(backup.Spec.ResourceTypes) != 0 && !isResourceTypePVC { + if (len(backup.Spec.ResourceTypes) != 0 && !isResourceTypePVC) || + (len(backup.Spec.ExcludeResourceTypes) != 0 && IsPVCInExcludeResourceType(backup)) { break } } @@ -1012,7 +1013,8 @@ func (a *ApplicationBackupController) backupVolumes(backup *stork_api.Applicatio if volInfo.Status == stork_api.ApplicationBackupStatusFailed { continue } - if volInfo.BackupID == "" { + // Check if the snapshot is completed only for pxd volumes by checking the backupID + if volInfo.DriverName == volume.PortworxDriverName && volInfo.BackupID == "" { log.ApplicationBackupLog(backup).Infof("Snapshot of volume [%v] from namespace [%v] hasn't completed yet, retry checking status", volInfo.PersistentVolumeClaim, volInfo.Namespace) // Some portworx volume snapshot is not completed yet // hence we will retry checking the status in the next reconciler iteration @@ -1846,7 +1848,7 @@ func (a *ApplicationBackupController) backupResources( return err } // Listing all resource types - if len(backup.Spec.ResourceTypes) != 0 { + if len(backup.Spec.ResourceTypes) != 0 || len(backup.Spec.ExcludeResourceTypes) != 0 { optionalResourceTypes := []string{} resourceTypes, err = a.resourceCollector.GetResourceTypes(optionalResourceTypes, true) if err != nil { @@ -1908,7 +1910,7 @@ func (a *ApplicationBackupController) backupResources( // As we support both includeResource and ResourceType to be mentioned // match out ns for which we want to take includeResource path and // for which we want to take ResourceType path - if len(backup.Spec.ResourceTypes) != 0 { + if len(backup.Spec.ResourceTypes) != 0 || len(backup.Spec.ExcludeResourceTypes) != 0 { if !resourcecollector.IsNsPresentInIncludeResource(objectMap, ns) { resourceTypeNsBatch = append(resourceTypeNsBatch, ns) } else { @@ -1936,18 +1938,43 @@ func (a *ApplicationBackupController) backupResources( } if len(resourceTypeNsBatch) != 0 { - for _, backupResourceType := range backup.Spec.ResourceTypes { - for _, resource := range resourceTypes { - if resource.Kind == backupResourceType || (backupResourceType == "PersistentVolumeClaim" && resource.Kind == "PersistentVolume") { - log.ApplicationBackupLog(backup).Tracef("GetResourcesType for : %v", resource.Kind) - objects, _, err := a.resourceCollector.GetResourcesForType(resource, nil, resourceTypeNsBatch, backup.Spec.Selectors, nil, nil, true, resourceCollectorOpts) - if err != nil { - log.ApplicationBackupLog(backup).Errorf("Error getting resources: %v", err) - return err + if len(backup.Spec.ResourceTypes) != 0 { + for _, backupResourceType := range backup.Spec.ResourceTypes { + for _, resource := range resourceTypes { + if resource.Kind == backupResourceType || + (backupResourceType == "PersistentVolumeClaim" && resource.Kind == "PersistentVolume") { + log.ApplicationBackupLog(backup).Tracef("GetResourcesType for : %v", resource.Kind) + objects, _, err := a.resourceCollector.GetResourcesForType(resource, nil, resourceTypeNsBatch, + backup.Spec.Selectors, nil, nil, true, resourceCollectorOpts) + if err != nil { + log.ApplicationBackupLog(backup).Errorf("Error getting resources: %v", err) + return err + } + allObjects = append(allObjects, objects.Items...) } - allObjects = append(allObjects, objects.Items...) } } + } else if len(backup.Spec.ExcludeResourceTypes) != 0 { + isPersistentVolumeType := IsPVCInExcludeResourceType(backup) + exclude := backup.Spec.ExcludeResourceTypes + if isPersistentVolumeType { + exclude = append(exclude, "PersistentVolume") + } + excludeTypeObjects, _, err := a.resourceCollector.GetResourcesExcludingTypes( + resourceTypeNsBatch, + exclude, + backup.Spec.Selectors, + nil, + nil, + optionalBackupResources, + true, + resourceCollectorOpts, + ) + if err != nil { + log.ApplicationBackupLog(backup).Errorf("Error getting resources for ExcludeResouceTypes: %v", err) + return err + } + allObjects = append(allObjects, excludeTypeObjects...) } } @@ -2075,7 +2102,6 @@ func (a *ApplicationBackupController) backupResources( if err != nil { return err } - return nil } // Do any additional preparation for the resources if required if err = a.prepareResources(backup, allObjects); err != nil { @@ -2401,8 +2427,9 @@ func (a *ApplicationBackupController) createCRD() error { func (a *ApplicationBackupController) IsVolsToBeBackedUp(backup *stork_api.ApplicationBackup) bool { // If ResourceType is mentioned and doesn't have PVC in it we would // like to skip the vol backups IFF includeResources doesn't have any ref to PVC - if len(backup.Spec.ResourceTypes) != 0 { - if IsResourceTypePVC(backup) { + if len(backup.Spec.ResourceTypes) != 0 || len(backup.Spec.ExcludeResourceTypes) != 0 { + if (len(backup.Spec.ResourceTypes) != 0 && IsResourceTypePVC(backup)) || + (len(backup.Spec.ExcludeResourceTypes) != 0 && !IsPVCInExcludeResourceType(backup)) { return true } @@ -2424,6 +2451,16 @@ func (a *ApplicationBackupController) IsVolsToBeBackedUp(backup *stork_api.Appli return true } +// IsPVCInExcludeResourceType check if given ResourceType is PVC +func IsPVCInExcludeResourceType(backup *stork_api.ApplicationBackup) bool { + for _, resType := range backup.Spec.ExcludeResourceTypes { + if resType == "PersistentVolumeClaim" { + return true + } + } + return false +} + // IsResourceTypePVC check if given ResourceType is PVC func IsResourceTypePVC(backup *stork_api.ApplicationBackup) bool { for _, resType := range backup.Spec.ResourceTypes { @@ -2670,7 +2707,9 @@ func (a *ApplicationBackupController) isNsPresentForVmBackup(backup *stork_api.A } func (a *ApplicationBackupController) validateApplicationBackupParameters(backup *stork_api.ApplicationBackup) error { - + if len(backup.Spec.ResourceTypes) != 0 && len(backup.Spec.ExcludeResourceTypes) != 0 { + return fmt.Errorf("both ResourceTypes and ExcludeResourceTypes parameter can not be set together") + } if IsBackupObjectTypeVirtualMachine(backup) { //Check resourceTypes is not specified if len(backup.Spec.ResourceTypes) != 0 { diff --git a/vendor/modules.txt b/vendor/modules.txt index ed20a18d4..57be95eca 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -505,7 +505,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.20241029051218-6fcdc46e8ffc +# github.com/libopenstorage/stork v1.4.1-0.20241115110516-1b6d535ef497 ## explicit; go 1.21 github.com/libopenstorage/stork/drivers github.com/libopenstorage/stork/drivers/volume From 3516e56a92aaa334be506756c68082c9f251f1da Mon Sep 17 00:00:00 2001 From: sivakumar subraani Date: Sat, 16 Nov 2024 13:45:57 +0000 Subject: [PATCH 2/2] pb-8713: Added excludeResourceType option handing in the nfsexecutor apis. --- Makefile | 2 +- pkg/executor/nfs/nfsbkpresources.go | 56 +++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index e84d04d55..f420fcae5 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ export GOFLAGS = -mod=vendor MAJOR_VERSION := 1 MINOR_VERSION := 2 -PATCH_VERSION := 15 +PATCH_VERSION := 16 ifndef PKGS PKGS := $(shell GOFLAGS=-mod=vendor go list ./... 2>&1 | grep -v 'go: ' | grep -v 'github.com/portworx/kdmp/vendor' | grep -v versioned | grep -v 'pkg/apis/v1') diff --git a/pkg/executor/nfs/nfsbkpresources.go b/pkg/executor/nfs/nfsbkpresources.go index 81ed40756..38706412f 100644 --- a/pkg/executor/nfs/nfsbkpresources.go +++ b/pkg/executor/nfs/nfsbkpresources.go @@ -201,7 +201,7 @@ func uploadResource( var err error // Listing all resource types - if len(backup.Spec.ResourceTypes) != 0 { + if len(backup.Spec.ResourceTypes) != 0 || len(backup.Spec.ExcludeResourceTypes) != 0 { optionalResourceTypes := []string{} resourceTypes, err = rc.GetResourceTypes(optionalResourceTypes, true) if err != nil { @@ -269,7 +269,7 @@ func uploadResource( // As we support both includeResource and ResourceType to be mentioned // match out ns for which we want to take includeResource path and // for which we want to take ResourceType path - if len(backup.Spec.ResourceTypes) != 0 { + if len(backup.Spec.ResourceTypes) != 0 || len(backup.Spec.ExcludeResourceTypes) != 0 { if !resourcecollector.IsNsPresentInIncludeResource(objectMap, ns) { resourceTypeNsBatch = append(resourceTypeNsBatch, ns) } else { @@ -297,18 +297,42 @@ func uploadResource( } if len(resourceTypeNsBatch) != 0 { - for _, backupResourceType := range backup.Spec.ResourceTypes { - for _, resource := range resourceTypes { - if resource.Kind == backupResourceType || (backupResourceType == "PersistentVolumeClaim" && resource.Kind == "PersistentVolume") { - log.ApplicationBackupLog(backup).Tracef("GetResourcesType for : %v", resource.Kind) - objects, _, err := rc.GetResourcesForType(resource, nil, resourceTypeNsBatch, backup.Spec.Selectors, nil, nil, true, resourceCollectorOpts) - if err != nil { - log.ApplicationBackupLog(backup).Errorf("Error getting resources: %v", err) - return err + if len(backup.Spec.ResourceTypes) != 0 { + for _, backupResourceType := range backup.Spec.ResourceTypes { + for _, resource := range resourceTypes { + if resource.Kind == backupResourceType || + (backupResourceType == "PersistentVolumeClaim" && resource.Kind == "PersistentVolume") { + log.ApplicationBackupLog(backup).Tracef("GetResourcesType for : %v", resource.Kind) + objects, _, err := rc.GetResourcesForType(resource, nil, resourceTypeNsBatch, + backup.Spec.Selectors, nil, nil, true, resourceCollectorOpts) + if err != nil { + log.ApplicationBackupLog(backup).Errorf("Error getting resources: %v", err) + return err + } + allObjects = append(allObjects, objects.Items...) } - allObjects = append(allObjects, objects.Items...) } } + } else if len(backup.Spec.ExcludeResourceTypes) != 0 { + exclude := backup.Spec.ExcludeResourceTypes + if IsPVCInExcludeResourceType(backup) { + exclude = append(exclude, "PersistentVolume") + } + excludeTypeObjects, _, err := rc.GetResourcesExcludingTypes( + resourceTypeNsBatch, + exclude, + backup.Spec.Selectors, + nil, + nil, + optionalBackupResources, + true, + resourceCollectorOpts, + ) + if err != nil { + log.ApplicationBackupLog(backup).Errorf("Error getting resources for ExcludeResouceTypes: %v", err) + return err + } + allObjects = append(allObjects, excludeTypeObjects...) } } } @@ -385,6 +409,16 @@ func uploadResource( return nil } +// IsPVCInExcludeResourceType check if given ResourceType is PVC +func IsPVCInExcludeResourceType(backup *stork_api.ApplicationBackup) bool { + for _, resType := range backup.Spec.ExcludeResourceTypes { + if resType == "PersistentVolumeClaim" { + return true + } + } + return false +} + func uploadStorageClasses( bkpNamespace string, backup *stork_api.ApplicationBackup,