Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix - update binding not supported #101

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/v1alpha1/servicebinding_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func (r *ServiceBinding) specChanged(old runtime.Object) bool {
r.Spec.ServiceInstanceName != oldBinding.Spec.ServiceInstanceName ||
// TODO + labels
//r.Spec.Labels != oldBinding.Spec.Labels ||
r.Spec.Parameters.String() != oldBinding.Spec.Parameters.String()
r.Spec.Parameters.String() != oldBinding.Spec.Parameters.String() ||
r.Spec.SecretName != oldBinding.Spec.SecretName
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
Expand Down
5 changes: 5 additions & 0 deletions controllers/servicebinding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,17 @@ func (r *ServiceBindingReconciler) poll(ctx context.Context, smClient smclient.C
return ctrl.Result{}, statusErr
}

if status == nil {
setFailureConditions(serviceBinding.Status.OperationType, "failed to get last operation status", serviceBinding)
return ctrl.Result{Requeue: true}, r.updateStatusWithRetries(ctx, serviceBinding, log)
}
switch status.State {
case string(smTypes.IN_PROGRESS):
fallthrough
case string(smTypes.PENDING):
return ctrl.Result{Requeue: true, RequeueAfter: r.Config.PollInterval}, nil
case string(smTypes.FAILED):
//non transient error - should not retry
setFailureConditions(smTypes.OperationCategory(status.Type), status.Description, serviceBinding)
if serviceBinding.Status.OperationType == smTypes.DELETE {
serviceBinding.Status.OperationURL = ""
Expand Down
22 changes: 4 additions & 18 deletions controllers/servicebinding_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,6 @@ var _ = Describe("ServiceBinding controller", func() {
fakeClient = &smclientfakes.FakeClient{}
fakeClient.ProvisionReturns("12345678", "", nil)
fakeClient.BindReturns(&smclientTypes.ServiceBinding{ID: fakeBindingID, Credentials: json.RawMessage("{\"secret_key\": \"secret_value\"}")}, "", nil)
fakeClient.ListBindingsReturnsOnCall(0, nil, nil)
fakeClient.ListBindingsReturnsOnCall(1, &smclientTypes.ServiceBindings{
ServiceBindings: []smclientTypes.ServiceBinding{
{
ID: fakeBindingID,
Name: "fake-binding-external-name",
Credentials: json.RawMessage("{\"secret_key\": \"secret_value\"}"),
LastOperation: &smTypes.Operation{
Type: smTypes.CREATE,
State: smTypes.SUCCEEDED,
Description: "fake-description",
},
},
},
}, nil)

smInstance := &smclientTypes.ServiceInstance{ID: fakeInstanceID, Ready: true, LastOperation: &smTypes.Operation{State: smTypes.SUCCEEDED, Type: smTypes.UPDATE}}
fakeClient.GetInstanceByIDReturns(smInstance, nil)
Expand Down Expand Up @@ -412,9 +397,10 @@ var _ = Describe("ServiceBinding controller", func() {

When("bind polling returns error", func() {
JustBeforeEach(func() {
fakeClient.GetBindingByIDReturns(&smclientTypes.ServiceBinding{ID: fakeBindingID, LastOperation: &smTypes.Operation{State: smTypes.SUCCEEDED, Type: smTypes.CREATE}}, nil)
fakeClient.StatusReturns(nil, fmt.Errorf("no polling for you"))
fakeClient.BindReturns(nil, "/v1/service_bindings/id/operations/1234", nil)
fakeClient.StatusReturnsOnCall(0, nil, fmt.Errorf("no polling for you"))
fakeClient.StatusReturnsOnCall(1, &smclientTypes.Operation{ResourceID: fakeBindingID, State: string(smTypes.SUCCEEDED), Type: string(smTypes.CREATE)}, nil)
fakeClient.GetBindingByIDReturns(&smclientTypes.ServiceBinding{ID: fakeBindingID, LastOperation: &smTypes.Operation{State: smTypes.SUCCEEDED, Type: smTypes.CREATE}}, nil)
})
It("should eventually succeed", func() {
createdBinding, err := createBindingWithoutAssertions(context.Background(), bindingName, bindingTestNamespace, instanceName, "")
Expand All @@ -423,7 +409,7 @@ var _ = Describe("ServiceBinding controller", func() {
err := k8sClient.Get(context.Background(), types.NamespacedName{Name: bindingName, Namespace: bindingTestNamespace}, createdBinding)
Expect(err).ToNot(HaveOccurred())
return isReady(createdBinding)
}, timeout, interval).Should(BeTrue())
}, timeout/2, interval).Should(BeTrue())
})
})
})
Expand Down