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

Handle external managed cluster's image deletion #2052

Merged
Merged
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
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