Skip to content

Commit

Permalink
skip forbidden error for restore priorityClass
Browse files Browse the repository at this point in the history
  • Loading branch information
cleverhu committed Sep 6, 2022
1 parent c7bd2b9 commit 7bcecb3
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions pkg/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -1448,30 +1448,46 @@ func isAlreadyExistsError(ctx *restoreContext, obj *unstructured.Unstructured, e
// 2. For LoadBalancer service, the "healthCheckNodePort" already exists. - Get internal error
// If this is the case, the function returns true to avoid reporting error.
// Refer to https://github.com/vmware-tanzu/velero/issues/2308 for more details
if obj.GetKind() != "Service" {
// The "forbidden error" rather than "already exists" error returns when restoring priorityClass in the following case:
// 1. For globalDefault priorityClass, the default priorityClass already exists. - Get forbidden error
// Refer to https://github.com/vmware-tanzu/velero/issues/5288 for more details
if obj.GetKind() != "Service" && obj.GetKind() != "PriorityClass" {
return false, nil
}
statusErr, ok := err.(*apierrors.StatusError)
if !ok || statusErr.Status().Details == nil || len(statusErr.Status().Details.Causes) == 0 {
return false, nil
}
// make sure all the causes are "port allocated" error
// make sure all the causes are "port allocated" or "marked as default" error for service error
// make sure all the causes are "already marked as default" error for priorityClass error
for _, cause := range statusErr.Status().Details.Causes {
if !strings.Contains(cause.Message, "provided port is already allocated") {
if !strings.Contains(cause.Message, "provided port is already allocated") && !strings.Contains(cause.Message, "is already marked as default. Only one default can exist") {
return false, nil
}
}

// the "already allocated" error may caused by other services, check whether the expected service exists or not
// the "already allocated" or "already marked as default" error may be caused by other services/priorityClasses, check whether the expected service/priorityClass exists or not
if _, err = client.Get(obj.GetName(), metav1.GetOptions{}); err != nil {
if apierrors.IsNotFound(err) {
ctx.log.Debugf("Service %s not found", kube.NamespaceAndName(obj))
ctx.log.Debugf("%s %s not found", obj.GetKind(), kube.NamespaceAndName(obj))
return false, nil
}
return false, errors.Wrapf(err, "Unable to get the service %s while checking the NodePort is already allocated error", kube.NamespaceAndName(obj))

switch obj.GetKind() {
case "Service":
return false, errors.Wrapf(err, "Unable to get the service %s while checking the NodePort is already allocated error", kube.NamespaceAndName(obj))
case "PriorityClass":
return false, errors.Wrapf(err, "Unable to get the priorityClass %s while checking the priorityClass is already marked as default error", kube.NamespaceAndName(obj))
}
}

switch obj.GetKind() {
case "Service":
ctx.log.Infof("Service %s exists, ignore the provided port is already allocated error", kube.NamespaceAndName(obj))
case "PriorityClass":
ctx.log.Infof("PriorityClass %s exists, ignore the priorityClass is already marked as default error", kube.NamespaceAndName(obj))
}

ctx.log.Infof("Service %s exists, ignore the provided port is already allocated error", kube.NamespaceAndName(obj))
return true, nil
}

Expand Down

0 comments on commit 7bcecb3

Please sign in to comment.