Skip to content

Commit

Permalink
pb-8713: Added excludeResourceType option handing in the nfsexecutor …
Browse files Browse the repository at this point in the history
…apis.
  • Loading branch information
sivakumar subraani committed Nov 16, 2024
1 parent b211146 commit 15b9d21
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
57 changes: 46 additions & 11 deletions pkg/executor/nfs/nfsbkpresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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...)
}
}
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 15b9d21

Please sign in to comment.