Skip to content

Commit 92caab3

Browse files
authored
Merge branch 'main' into update-plugin-aws-version
2 parents 5d7a0e0 + 360095a commit 92caab3

4 files changed

Lines changed: 33 additions & 12 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Wildcard namespaces: Log warning on empty resolution

pkg/backup/backup.go

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,15 @@ func NewKubernetesBackupper(
167167
}, nil
168168
}
169169

170-
// getNamespaceIncludesExcludesAndArgoCDNamespaces returns an IncludesExcludes list containing which namespaces to
171-
// include and exclude from the backup and a list of namespaces managed by ArgoCD.
172-
func getNamespaceIncludesExcludesAndArgoCDNamespaces(backup *velerov1api.Backup, kbClient kbclient.Client) (*collections.NamespaceIncludesExcludes, []string, error) {
170+
// getNamespaceIncludesExcludes returns an IncludesExcludes list containing which namespaces to
171+
// include and exclude from the backup.
172+
func getNamespaceIncludesExcludes(backup *velerov1api.Backup, kbClient kbclient.Client) (*collections.NamespaceIncludesExcludes, error) {
173173
nsList := corev1api.NamespaceList{}
174-
activeNamespaces := []string{}
175-
nsManagedByArgoCD := []string{}
176174
if err := kbClient.List(context.Background(), &nsList); err != nil {
177-
return nil, nsManagedByArgoCD, err
175+
return nil, err
178176
}
177+
178+
activeNamespaces := []string{}
179179
for _, ns := range nsList.Items {
180180
activeNamespaces = append(activeNamespaces, ns.Name)
181181
}
@@ -188,18 +188,28 @@ func getNamespaceIncludesExcludesAndArgoCDNamespaces(backup *velerov1api.Backup,
188188

189189
// Expand wildcards if needed
190190
if err := includesExcludes.ExpandIncludesExcludes(); err != nil {
191-
return nil, []string{}, err
191+
return nil, err
192192
}
193193

194-
// Check for ArgoCD managed namespaces in the namespaces that will be included
194+
return includesExcludes, nil
195+
}
196+
197+
// getArgoCDManagedNamespaces returns a list of namespaces managed by ArgoCD that should be included in the backup.
198+
func getArgoCDManagedNamespaces(kbClient kbclient.Client, includesExcludes *collections.NamespaceIncludesExcludes) ([]string, error) {
199+
nsList := corev1api.NamespaceList{}
200+
if err := kbClient.List(context.Background(), &nsList); err != nil {
201+
return nil, err
202+
}
203+
204+
nsManagedByArgoCD := []string{}
195205
for _, ns := range nsList.Items {
196206
nsLabels := ns.GetLabels()
197207
if len(nsLabels[ArgoCDManagedByNamespaceLabel]) > 0 && includesExcludes.ShouldInclude(ns.Name) {
198208
nsManagedByArgoCD = append(nsManagedByArgoCD, ns.Name)
199209
}
200210
}
201211

202-
return includesExcludes, nsManagedByArgoCD, nil
212+
return nsManagedByArgoCD, nil
203213
}
204214

205215
func getResourceHooks(hookSpecs []velerov1api.BackupResourceHookSpec, discoveryHelper discovery.Helper) ([]hook.ResourceHook, error) {
@@ -274,13 +284,18 @@ func (kb *kubernetesBackupper) BackupWithResolvers(
274284
return errors.WithStack(err)
275285
}
276286
var err error
277-
var nsManagedByArgoCD []string
278-
backupRequest.NamespaceIncludesExcludes, nsManagedByArgoCD, err = getNamespaceIncludesExcludesAndArgoCDNamespaces(backupRequest.Backup, kb.kbClient)
287+
backupRequest.NamespaceIncludesExcludes, err = getNamespaceIncludesExcludes(backupRequest.Backup, kb.kbClient)
279288
if err != nil {
280289
log.WithError(err).Errorf("error getting namespace includes/excludes")
281290
return err
282291
}
283292

293+
nsManagedByArgoCD, err := getArgoCDManagedNamespaces(kb.kbClient, backupRequest.NamespaceIncludesExcludes)
294+
if err != nil {
295+
log.WithError(err).Errorf("error getting ArgoCD managed namespaces")
296+
return err
297+
}
298+
284299
if backupRequest.NamespaceIncludesExcludes.IsWildcardExpanded() {
285300
expandedIncludes := backupRequest.NamespaceIncludesExcludes.GetIncludes()
286301
expandedExcludes := backupRequest.NamespaceIncludesExcludes.GetExcludes()
@@ -292,6 +307,10 @@ func (kb *kubernetesBackupper) BackupWithResolvers(
292307
return err
293308
}
294309

310+
if len(wildcardResult) == 0 {
311+
log.Warnf("no namespaces matched the resolution of wildcard patterns ")
312+
}
313+
295314
log.WithFields(logrus.Fields{
296315
"expandedIncludes": expandedIncludes,
297316
"expandedExcludes": expandedExcludes,

pkg/util/collections/includes_excludes.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ func (nie *NamespaceIncludesExcludes) ExpandIncludesExcludes() error {
173173
}
174174

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

site/content/docs/main/namespace-glob-patterns.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ layout: docs
55

66
When using `--include-namespaces` and `--exclude-namespaces` flags with backup and restore commands, you can use glob patterns to match multiple namespaces.
77

8+
Note: If the resolution of namespace patterns results in no namespaces, the backup will succeed with a warning.
9+
810
## Supported Patterns
911

1012
Velero supports the following glob pattern characters:

0 commit comments

Comments
 (0)