diff --git a/Makefile b/Makefile index e84d04d5..f420fcae 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 81ed4075..898614c5 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,43 @@ 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 { + isPersistentVolumeType := IsPVCInExcludeResourceType(backup) + exclude := backup.Spec.ExcludeResourceTypes + if isPersistentVolumeType { + 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 +410,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,