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

improve discoveryHelper.Refresh() in restore #7069

Merged
merged 3 commits into from
Nov 27, 2023
Merged
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/7069-27149chen
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
improve discoveryHelper.Refresh() in restore
26 changes: 17 additions & 9 deletions pkg/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,23 @@
errs.Merge(&e)
}

var createdOrUpdatedCRDs bool
for _, restoredItem := range ctx.restoredItems {
if restoredItem.action == itemRestoreResultCreated || restoredItem.action == itemRestoreResultUpdated {
createdOrUpdatedCRDs = true
break
}
}

Check warning on line 545 in pkg/restore/restore.go

View check run for this annotation

Codecov / codecov/patch

pkg/restore/restore.go#L539-L545

Added lines #L539 - L545 were not covered by tests
// If we just restored custom resource definitions (CRDs), refresh
// discovery because the restored CRDs may have created or updated new APIs that
// didn't previously exist in the cluster, and we want to be able to
// resolve & restore instances of them in subsequent loop iterations.
if createdOrUpdatedCRDs {
if err := ctx.discoveryHelper.Refresh(); err != nil {

Check warning on line 551 in pkg/restore/restore.go

View check run for this annotation

Codecov / codecov/patch

pkg/restore/restore.go#L549-L551

Added lines #L549 - L551 were not covered by tests
warnings.Add("", errors.Wrap(err, "refresh discovery after restoring CRDs"))
}
}

// Restore everything else
selectedResourceCollection, _, w, e := ctx.getOrderedResourceCollection(
backupResources,
Expand Down Expand Up @@ -754,15 +771,6 @@
}
}

// If we just restored custom resource definitions (CRDs), refresh
// discovery because the restored CRDs may have created new APIs that
// didn't previously exist in the cluster, and we want to be able to
// resolve & restore instances of them in subsequent loop iterations.
if groupResource == kuberesource.CustomResourceDefinitions {
if err := ctx.discoveryHelper.Refresh(); err != nil {
warnings.Add("", errors.Wrap(err, "refresh discovery after restoring CRDs"))
}
}
return processedItems, warnings, errs
}

Expand Down
Loading