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

Improve OSBPI compatibility #3724

Merged
merged 1 commit into from
Jan 17, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (r *Reconciler) deprovisionServiceInstance(
}
deprovisionResponse, err := osbapiClient.Deprovision(ctx, osbapi.DeprovisionPayload{
ID: serviceInstance.Name,
DeprovisionRequest: osbapi.DeprovisionRequest{
DeprovisionRequestParamaters: osbapi.DeprovisionRequestParamaters{
ServiceId: assets.ServiceOffering.Spec.BrokerCatalog.ID,
PlanID: assets.ServicePlan.Spec.BrokerCatalog.ID,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ var _ = Describe("CFServiceInstance", func() {
_, actualDeprovisionRequest := brokerClient.DeprovisionArgsForCall(0)
Expect(actualDeprovisionRequest).To(Equal(osbapi.DeprovisionPayload{
ID: instance.Name,
DeprovisionRequest: osbapi.DeprovisionRequest{
DeprovisionRequestParamaters: osbapi.DeprovisionRequestParamaters{
ServiceId: "service-offering-id",
PlanID: "service-plan-id",
},
Expand Down Expand Up @@ -863,7 +863,7 @@ var _ = Describe("CFServiceInstance", func() {
_, actualDeprovisionRequest := brokerClient.DeprovisionArgsForCall(0)
g.Expect(actualDeprovisionRequest).To(Equal(osbapi.DeprovisionPayload{
ID: instance.Name,
DeprovisionRequest: osbapi.DeprovisionRequest{
DeprovisionRequestParamaters: osbapi.DeprovisionRequestParamaters{
ServiceId: "service-offering-id",
PlanID: "service-plan-id",
},
Expand Down
7 changes: 6 additions & 1 deletion controllers/controllers/services/osbapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ func (c *Client) Deprovision(ctx context.Context, payload DeprovisionPayload) (P
ctx,
"/v2/service_instances/"+payload.ID,
http.MethodDelete,
map[string]string{
"service_id": payload.ServiceId,
"plan_id": payload.PlanID,
},
nil,
payload.DeprovisionRequest,
)
if err != nil {
return ProvisionResponse{}, fmt.Errorf("deprovision request failed: %w", err)
Expand Down Expand Up @@ -348,6 +351,8 @@ func (r *brokerRequester) sendRequest(ctx context.Context, requestPath string, m
if err != nil {
return 0, nil, fmt.Errorf("failed to create new HTTP request: %w", err)
}

req.Header.Add("Content-Type", "application/json")
req.Header.Add("X-Broker-API-Version", osbapiVersion)

queryValues := req.URL.Query()
Expand Down
31 changes: 5 additions & 26 deletions controllers/controllers/services/osbapi/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@ var _ = Describe("OSBAPI Client", func() {
}))))
})

It("sends OSBAPI version request header", func() {
Expect(brokerServer.ServedRequests()).To(ConsistOf(PointTo(MatchFields(IgnoreExtras, Fields{
"Header": HaveKeyWithValue(
"X-Broker-Api-Version", ConsistOf("2.17"),
),
}))))
})

When("getting the catalog fails", func() {
BeforeEach(func() {
brokerServer = brokerServer.WithResponse("/v2/catalog", nil, http.StatusTeapot)
Expand Down Expand Up @@ -265,7 +257,7 @@ var _ = Describe("OSBAPI Client", func() {
JustBeforeEach(func() {
deprovisionResp, deprovisionErr = brokerClient.Deprovision(ctx, osbapi.DeprovisionPayload{
ID: "my-service-instance",
DeprovisionRequest: osbapi.DeprovisionRequest{
DeprovisionRequestParamaters: osbapi.DeprovisionRequestParamaters{
ServiceId: "service-guid",
PlanID: "plan-guid",
},
Expand All @@ -289,23 +281,10 @@ var _ = Describe("OSBAPI Client", func() {
Expect(requests[0].Method).To(Equal(http.MethodDelete))
Expect(requests[0].URL.Path).To(Equal("/v2/service_instances/my-service-instance"))

Expect(requests[0].URL.Query().Get("accepts_incomplete")).To(Equal("true"))
})

It("sends correct request body", func() {
Expect(deprovisionErr).NotTo(HaveOccurred())
requests := brokerServer.ServedRequests()

Expect(requests).To(HaveLen(1))

requestBytes, err := io.ReadAll(requests[0].Body)
Expect(err).NotTo(HaveOccurred())
requestBody := map[string]any{}
Expect(json.Unmarshal(requestBytes, &requestBody)).To(Succeed())

Expect(requestBody).To(MatchAllKeys(Keys{
"service_id": Equal("service-guid"),
"plan_id": Equal("plan-guid"),
Expect(requests[0].URL.Query()).To(BeEquivalentTo(map[string][]string{
"service_id": {"service-guid"},
"plan_id": {"plan-guid"},
"accepts_incomplete": {"true"},
}))
})

Expand Down
4 changes: 2 additions & 2 deletions controllers/controllers/services/osbapi/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ type GetLastOperationRequestParameters struct {
}
type DeprovisionPayload struct {
ID string
DeprovisionRequest
DeprovisionRequestParamaters
}

type DeprovisionRequest struct {
type DeprovisionRequestParamaters struct {
ServiceId string `json:"service_id"`
PlanID string `json:"plan_id"`
}
Expand Down
2 changes: 2 additions & 0 deletions tests/helpers/broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func (b *BrokerServer) WithResponse(pattern string, response map[string]any, sta
Expect(err).NotTo(HaveOccurred())

return b.withHandler(pattern, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expect(r.Header).To(HaveKeyWithValue("Content-Type", ConsistOf("application/json")))
Expect(r.Header).To(HaveKeyWithValue("X-Broker-Api-Version", ConsistOf("2.17")))
w.WriteHeader(statusCode)
_, err := w.Write(respBytes)
Expect(err).NotTo(HaveOccurred())
Expand Down
Loading