Skip to content

Commit

Permalink
Implement unbind from managed service instance
Browse files Browse the repository at this point in the history
- Added IsAsync flag to UnbindResponse in OSBAPI and the logic in the
  Unbind method
- Added returning Gone error and ignoring in instances and bindings
  controllers
- Implementing the Unbind call in binding controller and also polling
  the last operation for the unbind response
- Refactor binding controller so that the calls for the Bind, Unbind and
  Provison and Deprovision in the services controller are identical
- Implement Setting owner reference with BlockOwnerDeletion=true and
  added 'foregroundDeletion' finalizer in binding controller

fixes #3296

Co-authored-by: Danail Branekov <danailster@gmail.com>
  • Loading branch information
uzabanov and danail-branekov committed Jan 8, 2025
1 parent d0e8c41 commit e47d419
Show file tree
Hide file tree
Showing 12 changed files with 657 additions and 499 deletions.
20 changes: 3 additions & 17 deletions controllers/api/v1alpha1/cfservicebinding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
)

const (
BindingFailedCondition = "BindingFailed"
BindingRequestedCondition = "BindingRequested"
UnbindingRequestedCondition = "UnbindingRequested"
BindingFailedCondition = "BindingFailed"

UnbindingFailedCondition = "UnbindingFailed"

ServiceInstanceTypeAnnotationKey = "korifi.cloudfoundry.org/service-instance-type"
PlanGUIDLabelKey = "korifi.cloudfoundry.org/plan-guid"
Expand Down Expand Up @@ -57,20 +57,6 @@ type CFServiceBindingStatus struct {
// +optional
Binding v1.LocalObjectReference `json:"binding"`

// The
// [operation](https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md#binding)
// of the bind request to the the OSBAPI broker. Only makes sense for
// bindings to managed service instances
// +optional
BindingOperation string `json:"bindingOperation"`

// The
// [operation](https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md#unbinding)
// of the unbind request to the the OSBAPI broker. Only makes sense for
// bindings to managed service instances
// +optional
UnbindingOperation string `json:"unbindingOperation"`

// A reference to the Secret containing the binding Credentials object. For
// bindings to user-provided services this refers to the credentials secret
// from the service instance. For managed services the secret contains the
Expand Down
10 changes: 9 additions & 1 deletion controllers/controllers/services/bindings/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"code.cloudfoundry.org/korifi/controllers/controllers/shared"
"code.cloudfoundry.org/korifi/tools"
"code.cloudfoundry.org/korifi/tools/k8s"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/go-logr/logr"
servicebindingv1beta1 "github.com/servicebinding/runtime/apis/v1beta1"
Expand Down Expand Up @@ -125,7 +126,14 @@ func (r *Reconciler) ReconcileResource(ctx context.Context, cfServiceBinding *ko

cfServiceBinding.Annotations = tools.SetMapValue(cfServiceBinding.Annotations, korifiv1alpha1.ServiceInstanceTypeAnnotationKey, string(cfServiceInstance.Spec.Type))

err = controllerutil.SetOwnerReference(cfServiceInstance, cfServiceBinding, r.scheme)
if err = k8s.Patch(ctx, r.k8sClient, cfServiceInstance, func() {
controllerutil.AddFinalizer(cfServiceInstance, metav1.FinalizerDeleteDependents)
}); err != nil {
log.Info("error when setting the foreground deletion finalizer on the service instance", "reason", err)
return ctrl.Result{}, err
}

err = controllerutil.SetOwnerReference(cfServiceInstance, cfServiceBinding, r.scheme, controllerutil.WithBlockOwnerDeletion(true))
if err != nil {
log.Info("error when making the service instance owner of the service binding", "reason", err)
return ctrl.Result{}, err
Expand Down
Loading

0 comments on commit e47d419

Please sign in to comment.