Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
zabanov-lab committed Sep 20, 2024
1 parent b5c5781 commit 62b1c58
Showing 1 changed file with 47 additions and 7 deletions.
54 changes: 47 additions & 7 deletions controllers/controllers/services/instances/managed/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func (r *Reconciler) ReconcileResource(ctx context.Context, serviceInstance *kor
serviceInstance.Status.ObservedGeneration = serviceInstance.Generation
log.V(1).Info("set observed generation", "generation", serviceInstance.Status.ObservedGeneration)

if !serviceInstance.GetDeletionTimestamp().IsZero() {
return r.finalizeCFServiceInstance(ctx, serviceInstance)
}

servicePlan, err := r.getServicePlan(ctx, serviceInstance.Spec.PlanGUID)
if err != nil {
log.Error(err, "failed to get service plan")
Expand All @@ -117,10 +121,6 @@ func (r *Reconciler) ReconcileResource(ctx context.Context, serviceInstance *kor
return ctrl.Result{}, fmt.Errorf("failed to create client for broker %q: %w", serviceBroker.Name, err)
}

if !serviceInstance.GetDeletionTimestamp().IsZero() {
return r.finalizeCFServiceInstance(ctx, osbapiClient, serviceInstance, serviceOffering, servicePlan)
}

if isReady(serviceInstance) {
return ctrl.Result{}, nil
}
Expand Down Expand Up @@ -230,17 +230,57 @@ func getServiceInstanceParameters(serviceInstance *korifiv1alpha1.CFServiceInsta

func (r *Reconciler) finalizeCFServiceInstance(
ctx context.Context,
osbapiClient osbapi.BrokerClient,
serviceInstance *korifiv1alpha1.CFServiceInstance,
serviceOffering *korifiv1alpha1.CFServiceOffering,
servicePlan *korifiv1alpha1.CFServicePlan,
) (ctrl.Result, error) {
log := logr.FromContextOrDiscard(ctx).WithName("finalizeCFServiceInstance")

if !controllerutil.ContainsFinalizer(serviceInstance, korifiv1alpha1.CFManagedServiceInstanceFinalizerName) {
return ctrl.Result{}, nil
}

servicePlan, err := r.getServicePlan(ctx, serviceInstance.Spec.PlanGUID)
if err != nil {
log.Error(err, "failed to get service plan")

if controllerutil.RemoveFinalizer(serviceInstance, korifiv1alpha1.CFManagedServiceInstanceFinalizerName) {
log.V(1).Info("finalizer removed")
}

return ctrl.Result{}, err
}

serviceBroker, err := r.getServiceBroker(ctx, servicePlan.Labels[korifiv1alpha1.RelServiceBrokerGUIDLabel])
if err != nil {
log.Error(err, "failed to get service broker")

if controllerutil.RemoveFinalizer(serviceInstance, korifiv1alpha1.CFManagedServiceInstanceFinalizerName) {
log.V(1).Info("finalizer removed")
}

return ctrl.Result{}, err
}

serviceOffering, err := r.getServiceOffering(ctx, servicePlan.Labels[korifiv1alpha1.RelServiceOfferingGUIDLabel])
if err != nil {
log.Error(err, "failed to get service offering")

if controllerutil.RemoveFinalizer(serviceInstance, korifiv1alpha1.CFManagedServiceInstanceFinalizerName) {
log.V(1).Info("finalizer removed")
}
return ctrl.Result{}, err
}

osbapiClient, err := r.osbapiClientFactory.CreateClient(ctx, serviceBroker)
if err != nil {
log.Error(err, "failed to create broker client", "broker", serviceBroker.Name)

if controllerutil.RemoveFinalizer(serviceInstance, korifiv1alpha1.CFManagedServiceInstanceFinalizerName) {
log.V(1).Info("finalizer removed")
}

return ctrl.Result{}, fmt.Errorf("failed to create client for broker %q: %w", serviceBroker.Name, err)
}

if !isDeprovisionRequested(serviceInstance) {
deprovisionResponse, err := osbapiClient.Deprovision(ctx, osbapi.InstanceDeprovisionPayload{

Check failure on line 285 in controllers/controllers/services/instances/managed/controller.go

View workflow job for this annotation

GitHub Actions / linter

shadow: declaration of "err" shadows declaration at line 241 (govet)

Check failure on line 285 in controllers/controllers/services/instances/managed/controller.go

View workflow job for this annotation

GitHub Actions / linter

shadow: declaration of "err" shadows declaration at line 241 (govet)
ID: serviceInstance.Name,
Expand Down

0 comments on commit 62b1c58

Please sign in to comment.