Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
zabanov-lab committed Sep 26, 2024
1 parent 4808189 commit b3b5ede
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ func (r *Reconciler) provisionServiceInstance(
return ctrl.Result{}, fmt.Errorf("failed to provision service: %w", err)
}

if provisionResponse.Complete {
return ctrl.Result{}, nil
}

serviceInstance.Status.ProvisionOperation = provisionResponse.Operation
meta.SetStatusCondition(&serviceInstance.Status.Conditions, metav1.Condition{
Type: korifiv1alpha1.ProvisionRequestedCondition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,32 @@ var _ = Describe("CFServiceInstance", func() {
})
})

When("the provision is already complete", func() {
BeforeEach(func() {
brokerClient.ProvisionReturns(osbapi.ServiceInstanceOperationResponse{
Operation: "operation-1",
Complete: true,
}, nil)
})

It("does not check last operation", func() {
Consistently(func(g Gomega) {
g.Expect(brokerClient.GetServiceInstanceLastOperationCallCount()).To(Equal(0))
}).Should(Succeed())
})

It("set sets ready condition to true", func() {
Eventually(func(g Gomega) {
g.Expect(adminClient.Get(ctx, client.ObjectKeyFromObject(instance), instance)).To(Succeed())

g.Expect(instance.Status.Conditions).To(ContainElement(SatisfyAll(
HasType(Equal(korifiv1alpha1.StatusConditionReady)),
HasStatus(Equal(metav1.ConditionTrue)),
)))
}).Should(Succeed())
})
})

When("service provisioning fails", func() {
BeforeEach(func() {
brokerClient.ProvisionReturns(osbapi.ServiceInstanceOperationResponse{}, errors.New("provision-failed"))
Expand Down
2 changes: 1 addition & 1 deletion controllers/controllers/services/osbapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (c *Client) Provision(ctx context.Context, payload InstanceProvisionPayload
return ServiceInstanceOperationResponse{}, fmt.Errorf("provision request failed with status code: %d", statusCode)
}

response := ServiceInstanceOperationResponse{Complete: false}
response := ServiceInstanceOperationResponse{}
if statusCode == 201 {
response.Complete = true
}
Expand Down
5 changes: 3 additions & 2 deletions controllers/controllers/services/osbapi/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ var _ = Describe("OSBAPI Client", func() {
"/v2/service_instances/{id}",
map[string]any{
"operation": "provision_op1",
"complete": true,
},
http.StatusCreated,
)
Expand All @@ -162,11 +163,11 @@ var _ = Describe("OSBAPI Client", func() {
})
})

It("provisions the service", func() {
It("provisions the service using the complete flag", func() {
Expect(provisionErr).NotTo(HaveOccurred())
Expect(provisionResp).To(Equal(osbapi.ServiceInstanceOperationResponse{
Operation: "provision_op1",
Complete: false,
Complete: true,
}))
})

Expand Down

0 comments on commit b3b5ede

Please sign in to comment.