Merge pull request #9558 from Joeavaikath/wildcard-ns-bugfix
Some checks failed
Run the E2E test on kind / get-go-version (push) Failing after 50s
Run the E2E test on kind / build (push) Has been skipped
Run the E2E test on kind / setup-test-matrix (push) Successful in 3s
Run the E2E test on kind / run-e2e-test (push) Has been skipped
Main CI / get-go-version (push) Successful in 12s
Main CI / Build (push) Failing after 41s

Wildcard namespaces: Log warning on empty resolution
This commit is contained in:
Joseph Antony Vaikath
2026-05-06 04:30:36 -04:00
committed by GitHub
parent 7aab742041
commit 360095a2e7
4 changed files with 33 additions and 12 deletions

View File

@@ -0,0 +1 @@
Wildcard namespaces: Log warning on empty resolution

View File

@@ -167,15 +167,15 @@ func NewKubernetesBackupper(
}, nil
}
// getNamespaceIncludesExcludesAndArgoCDNamespaces returns an IncludesExcludes list containing which namespaces to
// include and exclude from the backup and a list of namespaces managed by ArgoCD.
func getNamespaceIncludesExcludesAndArgoCDNamespaces(backup *velerov1api.Backup, kbClient kbclient.Client) (*collections.NamespaceIncludesExcludes, []string, error) {
// getNamespaceIncludesExcludes returns an IncludesExcludes list containing which namespaces to
// include and exclude from the backup.
func getNamespaceIncludesExcludes(backup *velerov1api.Backup, kbClient kbclient.Client) (*collections.NamespaceIncludesExcludes, error) {
nsList := corev1api.NamespaceList{}
activeNamespaces := []string{}
nsManagedByArgoCD := []string{}
if err := kbClient.List(context.Background(), &nsList); err != nil {
return nil, nsManagedByArgoCD, err
return nil, err
}
activeNamespaces := []string{}
for _, ns := range nsList.Items {
activeNamespaces = append(activeNamespaces, ns.Name)
}
@@ -188,10 +188,20 @@ func getNamespaceIncludesExcludesAndArgoCDNamespaces(backup *velerov1api.Backup,
// Expand wildcards if needed
if err := includesExcludes.ExpandIncludesExcludes(); err != nil {
return nil, []string{}, err
return nil, err
}
// Check for ArgoCD managed namespaces in the namespaces that will be included
return includesExcludes, nil
}
// getArgoCDManagedNamespaces returns a list of namespaces managed by ArgoCD that should be included in the backup.
func getArgoCDManagedNamespaces(kbClient kbclient.Client, includesExcludes *collections.NamespaceIncludesExcludes) ([]string, error) {
nsList := corev1api.NamespaceList{}
if err := kbClient.List(context.Background(), &nsList); err != nil {
return nil, err
}
nsManagedByArgoCD := []string{}
for _, ns := range nsList.Items {
nsLabels := ns.GetLabels()
if len(nsLabels[ArgoCDManagedByNamespaceLabel]) > 0 && includesExcludes.ShouldInclude(ns.Name) {
@@ -199,7 +209,7 @@ func getNamespaceIncludesExcludesAndArgoCDNamespaces(backup *velerov1api.Backup,
}
}
return includesExcludes, nsManagedByArgoCD, nil
return nsManagedByArgoCD, nil
}
func getResourceHooks(hookSpecs []velerov1api.BackupResourceHookSpec, discoveryHelper discovery.Helper) ([]hook.ResourceHook, error) {
@@ -274,13 +284,18 @@ func (kb *kubernetesBackupper) BackupWithResolvers(
return errors.WithStack(err)
}
var err error
var nsManagedByArgoCD []string
backupRequest.NamespaceIncludesExcludes, nsManagedByArgoCD, err = getNamespaceIncludesExcludesAndArgoCDNamespaces(backupRequest.Backup, kb.kbClient)
backupRequest.NamespaceIncludesExcludes, err = getNamespaceIncludesExcludes(backupRequest.Backup, kb.kbClient)
if err != nil {
log.WithError(err).Errorf("error getting namespace includes/excludes")
return err
}
nsManagedByArgoCD, err := getArgoCDManagedNamespaces(kb.kbClient, backupRequest.NamespaceIncludesExcludes)
if err != nil {
log.WithError(err).Errorf("error getting ArgoCD managed namespaces")
return err
}
if backupRequest.NamespaceIncludesExcludes.IsWildcardExpanded() {
expandedIncludes := backupRequest.NamespaceIncludesExcludes.GetIncludes()
expandedExcludes := backupRequest.NamespaceIncludesExcludes.GetExcludes()
@@ -292,6 +307,10 @@ func (kb *kubernetesBackupper) BackupWithResolvers(
return err
}
if len(wildcardResult) == 0 {
log.Warnf("no namespaces matched the resolution of wildcard patterns ")
}
log.WithFields(logrus.Fields{
"expandedIncludes": expandedIncludes,
"expandedExcludes": expandedExcludes,

View File

@@ -173,7 +173,6 @@ func (nie *NamespaceIncludesExcludes) ExpandIncludesExcludes() error {
}
// ResolveNamespaceList returns a list of all namespaces which will be backed up.
// The second return value indicates whether wildcard expansion was performed.
func (nie *NamespaceIncludesExcludes) ResolveNamespaceList() ([]string, error) {
// Check if this is being called by non-backup processing e.g. backup queue controller
if !nie.wildcardExpanded {

View File

@@ -5,6 +5,8 @@ layout: docs
When using `--include-namespaces` and `--exclude-namespaces` flags with backup and restore commands, you can use glob patterns to match multiple namespaces.
Note: If the resolution of namespace patterns results in no namespaces, the backup will succeed with a warning.
## Supported Patterns
Velero supports the following glob pattern characters: