Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix namespace metadata not being restored with existing-resource-policy #8607

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sshende-catalogicsoftware

Description

This PR fixes #7519 where namespace metadata (labels and annotations) from backup bundles was not being restored even when --existing-resource-policy was set to "update".

Fix Details

The fix adds logic to:

  1. Check if the namespace exists and if existingResourcePolicy is "update"
  2. Retrieve the namespace definition from the backup bundle
  3. Attempt to patch the existing namespace with backup metadata
  4. Include a fallback mechanism for manual label/annotation updates if patching fails

Testing Done

  1. Created a namespace with custom labels and annotations
  2. Backed up the namespace using Velero
  3. Modified the namespace labels/annotations
  4. Restored with --existing-resource-policy=update
  5. Verified that original labels and annotations were restored

Related PRs or Issues

Reviewer Instructions

Please pay special attention to:

  • Error handling in namespace restoration
  • Backward compatibility
  • The fallback mechanism for manual updates

Please indicate you've done the following:

This change ensures that when restoring namespaces with
existing-resource-policy set to 'update', the namespace metadata
(labels and annotations) from the backup bundle is properly restored.

Fixes vmware-tanzu#7519

Signed-off-by: Swanand Shende <sshende@catalogicsoftware.com>
pkg/restore/restore.go Outdated Show resolved Hide resolved
pkg/restore/restore.go Outdated Show resolved Hide resolved
Thanks. Accept this suggestion

Co-authored-by: Tiger Kaovilai <passawit.kaovilai@gmail.com>
Signed-off-by: sshende-catalogicsoftware <66183996+sshende-catalogicsoftware@users.noreply.github.com>
Thanks. Accept this suggestion as well.

Co-authored-by: Tiger Kaovilai <passawit.kaovilai@gmail.com>
Signed-off-by: sshende-catalogicsoftware <66183996+sshende-catalogicsoftware@users.noreply.github.com>
@sshende-catalogicsoftware
Copy link
Author

@kaovilai , Thanks for the suggestions! I've updated both comments to be clearer:

Please let me know if you'd like to see any other improvements!

resourceClient,
)

// Fall back to manual label/annotation update if the patch fails
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this fallback necessary? In what case the patch will fail but the update will succeed?

if groupResource == kuberesource.Namespaces {
if existingNamespaces.Has(targetNS) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can make condition like

if existingNamespaces.Has(targetNS) && velerov1api.PolicyTypeUpdate == ctx.restore.Spec.ExistingResourcePolicy {...}

and ignore printing the "Skipping ...." log message.

@@ -2243,7 +2325,9 @@ func (ctx *restoreContext) getOrderedResourceCollection(
continue
}

if namespace == "" && !boolptr.IsSetToTrue(ctx.restore.Spec.IncludeClusterResources) && !ctx.namespaceIncludesExcludes.IncludeEverything() {
if groupResource.Resource == "namespaces" {
ctx.log.Infof("Including resource namespaces despite being cluster-scoped")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this log message needed?

It can also be confusing if ctx.restore.Spec.IncludeClusterResources is set to true

@@ -0,0 +1,7 @@
kind: bug
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is trivial but conventionally the changelog is a one-liner, otherwise the format of the combined changelogs may be inconsistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can not update a namespace even if ExistingResourcePolicy is set to "update"
3 participants