Merge pull request #7069 from 27149chen/imporve-discovery-refresh

improve discoveryHelper.Refresh() in restore
pull/7149/head
qiuming 2023-11-27 18:02:36 +08:00 committed by GitHub
commit 3fdb3ec7c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 9 deletions

View File

@ -0,0 +1 @@
improve discoveryHelper.Refresh() in restore

View File

@ -544,6 +544,23 @@ func (ctx *restoreContext) execute() (results.Result, results.Result) {
errs.Merge(&e)
}
var createdOrUpdatedCRDs bool
for _, restoredItem := range ctx.restoredItems {
if restoredItem.action == itemRestoreResultCreated || restoredItem.action == itemRestoreResultUpdated {
createdOrUpdatedCRDs = true
break
}
}
// 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 {
warnings.Add("", errors.Wrap(err, "refresh discovery after restoring CRDs"))
}
}
// Restore everything else
selectedResourceCollection, _, w, e := ctx.getOrderedResourceCollection(
backupResources,
@ -762,15 +779,6 @@ func (ctx *restoreContext) processSelectedResource(
}
}
// 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
}