Skip to content

Commit

Permalink
Handle external managed cluster's image deletion (#2052)
Browse files Browse the repository at this point in the history
When an image is associated to a externally managed cluster, during deletion there might be a chance where cluster resource might have already cleaned up
So get cluster only when image is not deleted
  • Loading branch information
dharaneeshvrd authored Nov 15, 2024
1 parent 3c06b43 commit 1edcfec
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions controllers/ibmpowervsimage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,25 @@ func (r *IBMPowerVSImageReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return ctrl.Result{}, err
}

cluster, err := scope.GetClusterByName(ctx, r.Client, ibmImage.Namespace, ibmImage.Spec.ClusterName)
if err != nil {
return ctrl.Result{}, err
}

// Create the scope.
imageScope, err := scope.NewPowerVSImageScope(scope.PowerVSImageScopeParams{
var cluster *infrav1beta2.IBMPowerVSCluster
scopeParams := scope.PowerVSImageScopeParams{
Client: r.Client,
Logger: log,
IBMPowerVSImage: ibmImage,
Zone: cluster.Spec.Zone,
ServiceEndpoint: r.ServiceEndpoint,
})
}

// Externally managed clusters might not be available during image deletion. Get the cluster only when image is still not deleted.
if ibmImage.DeletionTimestamp.IsZero() {
cluster, err = scope.GetClusterByName(ctx, r.Client, ibmImage.Namespace, ibmImage.Spec.ClusterName)
if err != nil {
return ctrl.Result{}, err
}
scopeParams.Zone = cluster.Spec.Zone
}

// Create the scope
imageScope, err := scope.NewPowerVSImageScope(scopeParams)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to create scope: %w", err)
}
Expand Down

0 comments on commit 1edcfec

Please sign in to comment.