mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-06 21:36:30 +00:00
do not ignore unknown gvr at the beginning and get new gr when kind is changed
Signed-off-by: lou <alex1988@outlook.com>
This commit is contained in:
@@ -1113,6 +1113,7 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso
|
||||
// itemExists bool is used to determine whether to include this item in the "wait for additional items" list
|
||||
itemExists := false
|
||||
resourceID := getResourceID(groupResource, namespace, obj.GetName())
|
||||
resourceKind := obj.GetKind()
|
||||
|
||||
restoreLogger := ctx.log.WithFields(logrus.Fields{
|
||||
"namespace": obj.GetNamespace(),
|
||||
@@ -1217,13 +1218,13 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso
|
||||
return warnings, errs, itemExists
|
||||
}
|
||||
|
||||
resourceClient, err := ctx.getResourceClient(groupResource, obj, namespace)
|
||||
if err != nil {
|
||||
errs.AddVeleroError(fmt.Errorf("error getting resource client for namespace %q, resource %q: %v", namespace, &groupResource, err))
|
||||
return warnings, errs, itemExists
|
||||
}
|
||||
|
||||
if groupResource == kuberesource.PersistentVolumes {
|
||||
resourceClient, err := ctx.getResourceClient(groupResource, obj, namespace)
|
||||
if err != nil {
|
||||
errs.AddVeleroError(fmt.Errorf("error getting resource client for namespace %q, resource %q: %v", namespace, &groupResource, err))
|
||||
return warnings, errs, itemExists
|
||||
}
|
||||
|
||||
if volumeInfo, ok := ctx.volumeInfoMap[obj.GetName()]; ok {
|
||||
ctx.log.Infof("Find VolumeInfo for PV %s.", obj.GetName())
|
||||
|
||||
@@ -1504,9 +1505,18 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso
|
||||
// The object apiVersion might get modified by a RestorePlugin so we need to
|
||||
// get a new client to reflect updated resource path.
|
||||
newGR := schema.GroupResource{Group: obj.GroupVersionKind().Group, Resource: groupResource.Resource}
|
||||
resourceClient, err = ctx.getResourceClient(newGR, obj, obj.GetNamespace())
|
||||
if obj.GetKind() != resourceKind {
|
||||
ctx.log.Infof("Resource kind changed from %s to %s", resourceKind, obj.GetKind())
|
||||
gvr, _, err := ctx.discoveryHelper.KindFor(obj.GroupVersionKind())
|
||||
if err != nil {
|
||||
errs.Add(namespace, fmt.Errorf("error getting GVR for %s: %v", obj.GroupVersionKind(), err))
|
||||
return warnings, errs, itemExists
|
||||
}
|
||||
newGR.Resource = gvr.Resource
|
||||
}
|
||||
resourceClient, err := ctx.getResourceClient(newGR, obj, obj.GetNamespace())
|
||||
if err != nil {
|
||||
errs.AddVeleroError(fmt.Errorf("error getting updated resource client for namespace %q, resource %q: %v", namespace, &groupResource, err))
|
||||
warnings.Add(namespace, fmt.Errorf("error getting updated resource client for namespace %q, resource %q: %v", namespace, &groupResource, err))
|
||||
return warnings, errs, itemExists
|
||||
}
|
||||
|
||||
@@ -2184,13 +2194,14 @@ func (ctx *restoreContext) getOrderedResourceCollection(
|
||||
resourceList = resourcePriorities.HighPriorities
|
||||
}
|
||||
for _, resource := range resourceList {
|
||||
groupResource := schema.ParseGroupResource(resource)
|
||||
// try to resolve the resource via discovery to a complete group/version/resource
|
||||
gvr, _, err := ctx.discoveryHelper.ResourceFor(schema.ParseGroupResource(resource).WithVersion(""))
|
||||
gvr, _, err := ctx.discoveryHelper.ResourceFor(groupResource.WithVersion(""))
|
||||
if err != nil {
|
||||
ctx.log.WithField("resource", resource).Infof("Skipping restore of resource because it cannot be resolved via discovery")
|
||||
continue
|
||||
ctx.log.WithField("resource", resource).Infof("resource cannot be resolved via discovery")
|
||||
} else {
|
||||
groupResource = gvr.GroupResource()
|
||||
}
|
||||
groupResource := gvr.GroupResource()
|
||||
|
||||
// Check if we've already restored this resource (this would happen if
|
||||
// the resource we're currently looking at was already restored because
|
||||
|
||||
Reference in New Issue
Block a user