Ignore the provided port is already allocated error when restoring the LoadBalancer service (#4462)

Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com>
pull/4480/head
Wenkai Yin(尹文开) 2021-12-21 05:42:27 +08:00 committed by GitHub
parent d7aa82d8ed
commit c7cd95a374
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 13 deletions

View File

@ -0,0 +1 @@
Ignore the provided port is already allocated error when restoring the LoadBalancer service

View File

@ -1328,11 +1328,12 @@ func isAlreadyExistsError(ctx *restoreContext, obj *unstructured.Unstructured, e
if apierrors.IsAlreadyExists(err) {
return true
}
// the "invalid value" error rather than "already exists" error returns when restoring nodePort service
// that has nodePort preservation if the same nodePort service already exists.
// The "invalid value error" or "internal error" rather than "already exists" error returns when restoring nodePort service in the following two cases:
// 1. For NodePort service, the service has nodePort preservation while the same nodePort service already exists. - Get invalid value error
// 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" || !apierrors.IsInvalid(err) {
if obj.GetKind() != "Service" {
return false
}
statusErr, ok := err.(*apierrors.StatusError)

View File

@ -3044,16 +3044,6 @@ func TestIsAlreadyExistsError(t *testing.T) {
},
expected: false,
},
{
name: "The input error isn't InvalidError",
obj: &unstructured.Unstructured{
Object: map[string]interface{}{
"kind": "Service",
},
},
err: apierrors.NewBadRequest(""),
expected: false,
},
{
name: "The StatusError contains no causes",
obj: &unstructured.Unstructured{