Skip to content

Commit

Permalink
fix recreate secret bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelmaliy committed Apr 5, 2021
1 parent 71a15fb commit b57900f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions controllers/servicebinding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"), "")
Expand Down
17 changes: 17 additions & 0 deletions controllers/servicebinding_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down

0 comments on commit b57900f

Please sign in to comment.