Skip to content

Commit

Permalink
[SAPBTPCFS-7876] Optimize handling of non-transient errors
Browse files Browse the repository at this point in the history
  • Loading branch information
I065450 committed Feb 5, 2024
1 parent 8c9cb5f commit 581b415
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion controllers/servicebinding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (r *ServiceBindingReconciler) createBinding(ctx context.Context, smClient s

if bindErr != nil {
log.Error(err, "failed to create service binding", "serviceInstanceID", serviceInstance.Status.InstanceID)
return utils.HandleError(ctx, r.Client, smClientTypes.CREATE, bindErr, serviceBinding, false)
return utils.HandleError(ctx, r.Client, smClientTypes.CREATE, bindErr, serviceBinding, true)
}

if operationURL != "" {
Expand Down
17 changes: 13 additions & 4 deletions controllers/servicebinding_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,16 @@ var _ = Describe("ServiceBinding controller", func() {
}

createBindingWithoutAssertions := func(ctx context.Context, name, namespace, instanceName, instanceNamespace, externalName string) (*v1.ServiceBinding, error) {
return createBindingWithoutAssertionsAndWait(ctx, name, namespace, instanceName, instanceNamespace, externalName, true)
return createBindingWithoutAssertionsAndWait(ctx, name, namespace, instanceName, instanceNamespace, externalName, false)
}

createBindingWithTransitError := func(ctx context.Context, name, namespace, instanceName, externalName, failureMessage string) {
binding, err := createBindingWithoutAssertions(ctx, name, namespace, instanceName, "", externalName)
if err != nil {
Expect(err.Error()).To(ContainSubstring(failureMessage))
} else {
waitForResourceCondition(ctx, binding, common.ConditionSucceeded, metav1.ConditionFalse, common.CreateInProgress, failureMessage)
}
}

createBindingWithError := func(ctx context.Context, name, namespace, instanceName, externalName, failureMessage string) {
Expand Down Expand Up @@ -200,7 +209,7 @@ var _ = Describe("ServiceBinding controller", func() {
Context("invalid parameters", func() {
When("service instance name is not provided", func() {
It("should fail", func() {
createBindingWithError(ctx, bindingName, bindingTestNamespace, "", "",
createBindingWithTransitError(ctx, bindingName, bindingTestNamespace, "", "",
"spec.serviceInstanceName in body should be at least 1 chars long")
})
})
Expand Down Expand Up @@ -417,7 +426,7 @@ var _ = Describe("ServiceBinding controller", func() {
})

It("should fail", func() {
createBindingWithError(ctx, bindingName, bindingTestNamespace, instanceName, "binding-external-name", errorMessage)
createBindingWithTransitError(ctx, bindingName, bindingTestNamespace, instanceName, "binding-external-name", errorMessage)
})
})

Expand Down Expand Up @@ -455,7 +464,7 @@ var _ = Describe("ServiceBinding controller", func() {
})

It("should detect the error as non-transient and fail", func() {
createBindingWithError(ctx, bindingName, bindingTestNamespace, instanceName, "binding-external-name", errorMessage)
createBindingWithTransitError(ctx, bindingName, bindingTestNamespace, instanceName, "binding-external-name", errorMessage)
})
})

Expand Down
2 changes: 1 addition & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func waitForResourceCondition(ctx context.Context, resource common.SAPBTPResourc
}

return true
}, timeout*2, interval).Should(BeTrue(),
}, timeout*3, interval).Should(BeTrue(),
eventuallyMsgForResource(
fmt.Sprintf("expected condition: {type: %s, status: %s, reason: %s, message: %s} was not met", conditionType, status, reason, message),
key,
Expand Down

0 comments on commit 581b415

Please sign in to comment.