@@ -33,6 +33,7 @@ import (
3333 restclient "k8s.io/client-go/rest"
3434 "k8s.io/client-go/tools/clientcmd"
3535 "k8s.io/client-go/tools/clientcmd/api"
36+ "k8s.io/klog/v2"
3637 ctrl "sigs.k8s.io/controller-runtime"
3738 "sigs.k8s.io/controller-runtime/pkg/client"
3839 "sigs.k8s.io/controller-runtime/pkg/controller"
@@ -134,6 +135,8 @@ func (r *ROSAControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.Req
134135 return ctrl.Result {}, nil
135136 }
136137
138+ log = log .WithValues ("cluster" , klog .KObj (cluster ))
139+
137140 if capiannotations .IsPaused (cluster , rosaControlPlane ) {
138141 log .Info ("Reconciliation is paused for this object" )
139142 return ctrl.Result {}, nil
@@ -144,6 +147,7 @@ func (r *ROSAControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.Req
144147 Cluster : cluster ,
145148 ControlPlane : rosaControlPlane ,
146149 ControllerName : strings .ToLower (rosaControlPlaneKind ),
150+ Logger : log ,
147151 })
148152 if err != nil {
149153 return ctrl.Result {}, fmt .Errorf ("failed to create scope: %w" , err )
@@ -191,7 +195,12 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
191195
192196 if clusterID := cluster .ID (); clusterID != "" {
193197 rosaScope .ControlPlane .Status .ID = & clusterID
194- if cluster .Status ().State () == cmv1 .ClusterStateReady {
198+ rosaScope .ControlPlane .Status .ConsoleURL = cluster .Console ().URL ()
199+ rosaScope .ControlPlane .Status .OIDCEndpointURL = cluster .AWS ().STS ().OIDCEndpointURL ()
200+ rosaScope .ControlPlane .Status .Ready = false
201+
202+ switch cluster .Status ().State () {
203+ case cmv1 .ClusterStateReady :
195204 conditions .MarkTrue (rosaScope .ControlPlane , rosacontrolplanev1 .ROSAControlPlaneReadyCondition )
196205 rosaScope .ControlPlane .Status .Ready = true
197206
@@ -204,15 +213,25 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
204213 if err := r .reconcileKubeconfig (ctx , rosaScope , rosaClient , cluster ); err != nil {
205214 return ctrl.Result {}, fmt .Errorf ("failed to reconcile kubeconfig: %w" , err )
206215 }
207-
216+ return ctrl.Result {}, nil
217+ case cmv1 .ClusterStateError :
218+ errorMessage := cluster .Status ().ProvisionErrorMessage ()
219+ rosaScope .ControlPlane .Status .FailureMessage = & errorMessage
220+
221+ conditions .MarkFalse (rosaScope .ControlPlane ,
222+ rosacontrolplanev1 .ROSAControlPlaneReadyCondition ,
223+ string (cluster .Status ().State ()),
224+ clusterv1 .ConditionSeverityError ,
225+ cluster .Status ().ProvisionErrorCode ())
226+ // Cluster is in an unrecoverable state, returning nil error so that the request doesn't get requeued.
208227 return ctrl.Result {}, nil
209228 }
210229
211230 conditions .MarkFalse (rosaScope .ControlPlane ,
212231 rosacontrolplanev1 .ROSAControlPlaneReadyCondition ,
213232 string (cluster .Status ().State ()),
214233 clusterv1 .ConditionSeverityInfo ,
215- "" )
234+ cluster . Status (). Description () )
216235
217236 rosaScope .Info ("waiting for cluster to become ready" , "state" , cluster .Status ().State ())
218237 // Requeue so that status.ready is set to true when the cluster is fully created.
@@ -333,8 +352,7 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
333352
334353 newCluster , err := rosaClient .CreateCluster (clusterSpec )
335354 if err != nil {
336- rosaScope .Info ("error" , "error" , err )
337- return ctrl.Result {RequeueAfter : 10 * time .Second }, nil
355+ return ctrl.Result {}, fmt .Errorf ("failed to create ROSA cluster: %w" , err )
338356 }
339357
340358 rosaScope .Info ("cluster created" , "state" , newCluster .Status ().State ())
@@ -358,15 +376,22 @@ func (r *ROSAControlPlaneReconciler) reconcileDelete(ctx context.Context, rosaSc
358376 return ctrl.Result {}, err
359377 }
360378
361- if cluster != nil {
379+ if cluster == nil {
380+ // cluster is fully deleted, remove finalizer.
381+ controllerutil .RemoveFinalizer (rosaScope .ControlPlane , ROSAControlPlaneFinalizer )
382+ return ctrl.Result {}, nil
383+ }
384+
385+ if cluster .Status ().State () != cmv1 .ClusterStateUninstalling {
362386 if err := rosaClient .DeleteCluster (cluster .ID ()); err != nil {
363387 return ctrl.Result {}, err
364388 }
365389 }
366390
367- controllerutil .RemoveFinalizer (rosaScope .ControlPlane , ROSAControlPlaneFinalizer )
368-
369- return ctrl.Result {}, nil
391+ rosaScope .ControlPlane .Status .Ready = false
392+ rosaScope .Info ("waiting for cluster to be deleted" )
393+ // Requeue to remove the finalizer when the cluster is fully deleted.
394+ return ctrl.Result {RequeueAfter : time .Second * 60 }, nil
370395}
371396
372397func (r * ROSAControlPlaneReconciler ) reconcileKubeconfig (ctx context.Context , rosaScope * scope.ROSAControlPlaneScope , rosaClient * rosa.RosaClient , cluster * cmv1.Cluster ) error {
0 commit comments