Skip to content

Commit

Permalink
Bug fix - delete orphan binding (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
kerenlahav authored Jan 4, 2024
1 parent f33b73a commit 22894a8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion controllers/servicebinding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ func (r *ServiceBindingReconciler) getServiceInstanceForBinding(ctx context.Cont
}
log.Info(fmt.Sprintf("getting service instance named %s in namespace %s for binding %s in namespace %s", binding.Spec.ServiceInstanceName, namespace, binding.Name, binding.Namespace))
if err := r.Client.Get(ctx, types.NamespacedName{Name: binding.Spec.ServiceInstanceName, Namespace: namespace}, serviceInstance); err != nil {
return nil, err
return serviceInstance, err
}

return serviceInstance.DeepCopy(), nil
Expand Down
21 changes: 21 additions & 0 deletions controllers/servicebinding_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,27 @@ var _ = Describe("ServiceBinding controller", func() {
deleteAndValidate(createdBinding)
})
})

When("delete orphan binding with finalizer", func() {
BeforeEach(func() {
fakeClient.UnbindReturns("", nil)
})
It("should succeed", func() {
createdBinding, err := createBindingWithoutAssertions(ctx, bindingName+"-new", bindingTestNamespace, "non-exist-instance", "", "binding-external-name")
Expect(err).ToNot(HaveOccurred())
createdBinding.Finalizers = []string{api.FinalizerName}
Expect(k8sClient.Update(ctx, createdBinding))
Eventually(func() bool {
err := k8sClient.Get(ctx, getResourceNamespacedName(createdBinding), createdBinding)
if err != nil {
return false
}
cond := meta.FindStatusCondition(createdBinding.GetConditions(), api.ConditionSucceeded)
return cond != nil && cond.Reason == Blocked
}, timeout, interval).Should(BeTrue())
deleteAndValidate(createdBinding)
})
})
})

Context("Async", func() {
Expand Down

0 comments on commit 22894a8

Please sign in to comment.