From b57900f8eec4b422c5631adc77847c82e4b520f8 Mon Sep 17 00:00:00 2001 From: pavelmaliy Date: Mon, 5 Apr 2021 12:04:58 +0300 Subject: [PATCH] fix recreate secret bug --- controllers/servicebinding_controller.go | 1 + controllers/servicebinding_controller_test.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/controllers/servicebinding_controller.go b/controllers/servicebinding_controller.go index 35052c81..eae5ffc9 100644 --- a/controllers/servicebinding_controller.go +++ b/controllers/servicebinding_controller.go @@ -159,6 +159,7 @@ func (r *ServiceBindingReconciler) Reconcile(ctx context.Context, req ctrl.Reque if serviceBinding.Status.Ready != metav1.ConditionTrue { return r.createBinding(ctx, smClient, serviceInstance, serviceBinding, log) } + return ctrl.Result{}, nil } log.Error(fmt.Errorf("update binding is not allowed, this line should not be reached"), "") diff --git a/controllers/servicebinding_controller_test.go b/controllers/servicebinding_controller_test.go index 5e3263bd..81a96f8e 100644 --- a/controllers/servicebinding_controller_test.go +++ b/controllers/servicebinding_controller_test.go @@ -318,11 +318,28 @@ var _ = Describe("ServiceBinding controller", func() { }) When("secret deleted by user", func() { + fakeSmResponse := func(bindingID string) { + fakeClient.ListBindingsReturns(&smclientTypes.ServiceBindings{ + ServiceBindings: []smclientTypes.ServiceBinding{ + { + ID: bindingID, + Credentials: json.RawMessage("{\"secret_key\": \"secret_value\"}"), + LastOperation: &smTypes.Operation{ + Type: smTypes.CREATE, + State: smTypes.SUCCEEDED, + Description: "fake-description", + }, + }, + }, + }, nil) + } + It("should recreate the secret", func() { ctx := context.Background() createdBinding = createBinding(ctx, bindingName, bindingTestNamespace, instanceName, "binding-external-name") secretLookupKey := types.NamespacedName{Name: createdBinding.Spec.SecretName, Namespace: createdBinding.Namespace} bindingSecret := getSecret(ctx, secretLookupKey.Name, secretLookupKey.Namespace, true) + fakeSmResponse(createdBinding.Status.BindingID) err := k8sClient.Delete(ctx, bindingSecret) Expect(err).ToNot(HaveOccurred())