Skip to content

Commit 5d31e78

Browse files
committed
return gone on unbind from non-existent templateinstance
1 parent 1927cae commit 5d31e78

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

pkg/templateservicebroker/servicebroker/unbind.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,21 @@ func (b *Broker) Unbind(u user.Info, instanceID, bindingID string) *api.Response
4343
return api.Forbidden(err)
4444
}
4545

46+
status := http.StatusGone
4647
templateInstance, err := b.templateclient.TemplateInstances(namespace).Get(brokerTemplateInstance.Spec.TemplateInstance.Name, metav1.GetOptions{})
4748
if err != nil {
48-
return api.InternalServerError(err)
49+
if !kerrors.IsNotFound(err) {
50+
return api.InternalServerError(err)
51+
}
4952
}
50-
if strings.ToLower(templateInstance.Spec.Template.Annotations[templateapi.BindableAnnotation]) == "false" {
53+
if templateInstance != nil && strings.ToLower(templateInstance.Spec.Template.Annotations[templateapi.BindableAnnotation]) == "false" {
5154
return api.BadRequest(errors.New("provisioned service is not bindable"))
5255
}
5356

5457
// The OSB API requires this function to be idempotent (restartable). If
5558
// any actual change was made, per the spec, StatusOK is returned, else
5659
// StatusGone.
5760

58-
status := http.StatusGone
5961
for i := 0; i < len(brokerTemplateInstance.Spec.BindingIDs); i++ {
6062
for i < len(brokerTemplateInstance.Spec.BindingIDs) && brokerTemplateInstance.Spec.BindingIDs[i] == bindingID {
6163
brokerTemplateInstance.Spec.BindingIDs = append(brokerTemplateInstance.Spec.BindingIDs[:i], brokerTemplateInstance.Spec.BindingIDs[i+1:]...)
@@ -65,6 +67,8 @@ func (b *Broker) Unbind(u user.Info, instanceID, bindingID string) *api.Response
6567
if status == http.StatusOK { // binding found; remove it
6668
// end users are not expected to have access to BrokerTemplateInstance
6769
// objects; SAR on the TemplateInstance instead.
70+
// Note that this specific templateinstance object might not actually exist anymore, but the SAR check
71+
// is still valid to confirm the user can update templateinstances in this namespace.
6872
if err := util.Authorize(b.kc.Authorization().SubjectAccessReviews(), u, &authorizationv1.ResourceAttributes{
6973
Namespace: namespace,
7074
Verb: "update",

test/extended/templates/templateservicebroker_e2e.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,21 @@ var _ = g.Describe("[Conformance][templates] templateservicebroker end-to-end te
374374
provision()
375375
bind()
376376
unbind()
377+
// unbinding a second time should result in a gone message, but not an error
378+
unbind()
377379
deprovision()
380+
381+
/*
382+
Reenable once the TSB changes have made it into a published image
383+
provision()
384+
bind()
385+
g.By("deleting the template instance that was bound")
386+
err := cli.Run("delete").Args("templateinstance", "--all").Execute()
387+
o.Expect(err).NotTo(o.HaveOccurred())
388+
unbind()
389+
// unbinding a second time should result in a gone message, but not an error
390+
unbind()
391+
*/
378392
})
379393
})
380394
})

0 commit comments

Comments
 (0)