Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/6999-kaovilai
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
restore: Add new resource filters can separate cluster and namespace scope resources.
22 changes: 22 additions & 0 deletions pkg/apis/velero/v1/backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,25 @@ type BackupList struct {

Items []Backup `json:"items"`
}

func (b BackupSpec) GetIncludeClusterResources() *bool {
return b.IncludeClusterResources
}
func (b BackupSpec) GetIncludedResources() []string {
return b.IncludedResources
}
func (b BackupSpec) GetExcludedResources() []string {
return b.ExcludedResources
}
func (b BackupSpec) GetIncludedClusterScopedResources() []string {
return b.IncludedClusterScopedResources
}
func (b BackupSpec) GetExcludedClusterScopedResources() []string {
return b.ExcludedClusterScopedResources
}
func (b BackupSpec) GetIncludedNamespaceScopedResources() []string {
return b.IncludedNamespaceScopedResources
}
func (b BackupSpec) GetExcludedNamespaceScopedResources() []string {
return b.ExcludedNamespaceScopedResources
}
54 changes: 54 additions & 0 deletions pkg/apis/velero/v1/restore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,38 @@ type RestoreSpec struct {
// +nullable
ExcludedResources []string `json:"excludedResources,omitempty"`

// IncludedClusterScopedResources is a slice of cluster-scoped
// resource type names to include in the restore.
// If set to "*", all cluster-scoped resource types are included.
// The default value is empty, which means only related
// cluster-scoped resources are included.
// +optional
// +nullable
IncludedClusterScopedResources []string `json:"includedClusterScopedResources,omitempty"`

// ExcludedClusterScopedResources is a slice of cluster-scoped
// resource type names to exclude from the restore.
// If set to "*", all cluster-scoped resource types are excluded.
// The default value is empty.
// +optional
// +nullable
ExcludedClusterScopedResources []string `json:"excludedClusterScopedResources,omitempty"`

// IncludedNamespaceScopedResources is a slice of namespace-scoped
// resource type names to include in the restore.
// The default value is "*".
// +optional
// +nullable
IncludedNamespaceScopedResources []string `json:"includedNamespaceScopedResources,omitempty"`

// ExcludedNamespaceScopedResources is a slice of namespace-scoped
// resource type names to exclude from the restore.
// If set to "*", all namespace-scoped resource types are excluded.
// The default value is empty.
// +optional
// +nullable
ExcludedNamespaceScopedResources []string `json:"excludedNamespaceScopedResources,omitempty"`

// NamespaceMapping is a map of source namespace names
// to target namespace names to restore into. Any source
// namespaces not included in the map will be restored into
Expand Down Expand Up @@ -396,3 +428,25 @@ type RestoreList struct {

// PolicyType helps specify the ExistingResourcePolicy
type PolicyType string

func (r RestoreSpec) GetIncludeClusterResources() *bool {
return r.IncludeClusterResources
}
func (r RestoreSpec) GetIncludedResources() []string {
return r.IncludedResources
}
func (r RestoreSpec) GetExcludedResources() []string {
return r.ExcludedResources
}
func (r RestoreSpec) GetIncludedClusterScopedResources() []string {
return r.IncludedClusterScopedResources
}
func (r RestoreSpec) GetExcludedClusterScopedResources() []string {
return r.ExcludedClusterScopedResources
}
func (r RestoreSpec) GetIncludedNamespaceScopedResources() []string {
return r.IncludedNamespaceScopedResources
}
func (r RestoreSpec) GetExcludedNamespaceScopedResources() []string {
return r.ExcludedNamespaceScopedResources
}
33 changes: 21 additions & 12 deletions pkg/util/collections/includes_excludes.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"

velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"github.com/vmware-tanzu/velero/pkg/discovery"
"github.com/vmware-tanzu/velero/pkg/kuberesource"
"github.com/vmware-tanzu/velero/pkg/util/boolptr"
Expand Down Expand Up @@ -540,25 +539,35 @@ func GetScopeResourceIncludesExcludes(helper discovery.Helper, logger logrus.Fie
return ret
}

type BackupOrRestoreIncludeExcludeSpec interface{
GetIncludeClusterResources() *bool
GetIncludedResources() []string
GetExcludedResources() []string
GetIncludedClusterScopedResources() []string
GetExcludedClusterScopedResources() []string
GetIncludedNamespaceScopedResources() []string
GetExcludedNamespaceScopedResources() []string
}

// UseOldResourceFilters checks whether to use old resource filters (IncludeClusterResources,
// IncludedResources and ExcludedResources), depending the backup's filters setting.
// New filters are IncludedClusterScopedResources, ExcludedClusterScopedResources,
// IncludedNamespaceScopedResources and ExcludedNamespaceScopedResources.
func UseOldResourceFilters(backupSpec velerov1api.BackupSpec) bool {
func UseOldResourceFilters(brSpec BackupOrRestoreIncludeExcludeSpec) bool {
// If all resource filters are none, it is treated as using old parameter filters.
if backupSpec.IncludeClusterResources == nil &&
len(backupSpec.IncludedResources) == 0 &&
len(backupSpec.ExcludedResources) == 0 &&
len(backupSpec.IncludedClusterScopedResources) == 0 &&
len(backupSpec.ExcludedClusterScopedResources) == 0 &&
len(backupSpec.IncludedNamespaceScopedResources) == 0 &&
len(backupSpec.ExcludedNamespaceScopedResources) == 0 {
if brSpec.GetIncludeClusterResources() == nil &&
len(brSpec.GetIncludedResources()) == 0 &&
len(brSpec.GetExcludedResources()) == 0 &&
len(brSpec.GetIncludedClusterScopedResources()) == 0 &&
len(brSpec.GetExcludedClusterScopedResources()) == 0 &&
len(brSpec.GetIncludedNamespaceScopedResources()) == 0 &&
len(brSpec.GetExcludedNamespaceScopedResources()) == 0 {
return true
}

if backupSpec.IncludeClusterResources != nil ||
len(backupSpec.IncludedResources) > 0 ||
len(backupSpec.ExcludedResources) > 0 {
if brSpec.GetIncludeClusterResources() != nil ||
len(brSpec.GetIncludedResources()) > 0 ||
len(brSpec.GetExcludedResources()) > 0 {
return true
}

Expand Down