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

Allowing Object-Level Resource Status Restore #8464

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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/8464-shubham-pampattiwar
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allowing Object-Level Resource Status Restore
18 changes: 14 additions & 4 deletions pkg/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ import (
"github.com/vmware-tanzu/velero/pkg/util/results"
)

const ObjectStatusRestoreAnnotationKey = "velero.io/restore-status"

var resourceMustHave = []string{
"datauploads.velero.io",
}
Expand Down Expand Up @@ -1655,15 +1657,23 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso

// determine whether to restore status according to original GR
shouldRestoreStatus := ctx.resourceStatusIncludesExcludes != nil && ctx.resourceStatusIncludesExcludes.ShouldInclude(groupResource.String())
if shouldRestoreStatus && statusFieldErr != nil {

// Check for the object-level annotation on the resource object
objectAnnotation := obj.GetAnnotations()[ObjectStatusRestoreAnnotationKey]
shouldRestoreStatusForObject := objectAnnotation == "true"

// If either the resource type is included or the object-level annotation indicates restoration
if (shouldRestoreStatus || shouldRestoreStatusForObject) && statusFieldErr != nil {
err := fmt.Errorf("could not get status to be restored %s: %v", kube.NamespaceAndName(obj), statusFieldErr)
ctx.log.Errorf(err.Error())
errs.Add(namespace, err)
return warnings, errs, itemExists
}
ctx.log.Debugf("status field for %s: exists: %v, should restore: %v", newGR, statusFieldExists, shouldRestoreStatus)
// if it should restore status, run a UpdateStatus
if statusFieldExists && shouldRestoreStatus {

ctx.log.Debugf("status field for %s: exists: %v, should restore: %v, should restore by annotation: %v", newGR, statusFieldExists, shouldRestoreStatus, shouldRestoreStatusForObject)

// Proceed with status restoration if required by either resource type or annotation
if statusFieldExists && (shouldRestoreStatus || shouldRestoreStatusForObject) {
if err := unstructured.SetNestedField(obj.Object, objStatus, "status"); err != nil {
ctx.log.Errorf("could not set status field %s: %v", kube.NamespaceAndName(obj), err)
errs.Add(namespace, err)
Expand Down