Skip to content

Commit

Permalink
Changes to support ibmpowervs image deletion without cluster reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik-K-N committed Nov 3, 2022
1 parent 3f6a409 commit 543392f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
22 changes: 7 additions & 15 deletions cloud/scope/powervs_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ const BucketAccess = "public"

// PowerVSImageScopeParams defines the input parameters used to create a new PowerVSImageScope.
type PowerVSImageScopeParams struct {
Client client.Client
Logger logr.Logger
IBMPowerVSImage *infrav1beta1.IBMPowerVSImage
IBMPowerVSCluster *infrav1beta1.IBMPowerVSCluster
ServiceEndpoint []endpoints.ServiceEndpoint
Client client.Client
Logger logr.Logger
IBMPowerVSImage *infrav1beta1.IBMPowerVSImage
ServiceEndpoint []endpoints.ServiceEndpoint
}

// PowerVSImageScope defines a scope defined around a Power VS Cluster.
Expand All @@ -59,10 +58,9 @@ type PowerVSImageScope struct {
Client client.Client
patchHelper *patch.Helper

IBMPowerVSClient powervs.PowerVS
IBMPowerVSImage *infrav1beta1.IBMPowerVSImage
IBMPowerVSCluster *infrav1beta1.IBMPowerVSCluster
ServiceEndpoint []endpoints.ServiceEndpoint
IBMPowerVSClient powervs.PowerVS
IBMPowerVSImage *infrav1beta1.IBMPowerVSImage
ServiceEndpoint []endpoints.ServiceEndpoint
}

// NewPowerVSImageScope creates a new PowerVSImageScope from the supplied parameters.
Expand Down Expand Up @@ -125,12 +123,6 @@ func NewPowerVSImageScope(params PowerVSImageScopeParams) (scope *PowerVSImageSc
CloudInstanceID: spec.ServiceInstanceID,
}

if params.IBMPowerVSCluster == nil {
err = errors.New("failed to generate new scope from nil IBMPowerVSCluster")
return
}
scope.IBMPowerVSCluster = params.IBMPowerVSCluster

// Fetch the service endpoint.
if svcEndpoint := endpoints.FetchPVSEndpoint(endpoints.CostructRegionFromZone(*res.RegionID), params.ServiceEndpoint); svcEndpoint != "" {
options.IBMPIOptions.URL = svcEndpoint
Expand Down
25 changes: 10 additions & 15 deletions controllers/ibmpowervsimage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterv1util "sigs.k8s.io/cluster-api/util"
Expand Down Expand Up @@ -70,22 +69,17 @@ func (r *IBMPowerVSImageReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return ctrl.Result{}, err
}

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

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

// Always close the scope when exiting this function so we can persist any GCPMachine changes.
if err != nil {
return ctrl.Result{}, errors.Errorf("failed to create scope: %+v", err)
}
// Always close the scope when exiting this function so we can persist any IBM PowerVS Image changes.
defer func() {
if err := imageScope.Close(); err != nil && reterr == nil {
reterr = err
Expand All @@ -97,8 +91,9 @@ func (r *IBMPowerVSImageReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return r.reconcileDelete(imageScope)
}

cluster, err := util.GetClusterByName(ctx, r.Client, ibmImage.Namespace, ibmImage.Spec.ClusterName)
if err != nil {
return reconcile.Result{}, errors.Errorf("failed to create scope: %+v", err)
return ctrl.Result{}, err
}
return r.reconcile(cluster, imageScope)
}
Expand Down

0 comments on commit 543392f

Please sign in to comment.