@@ -33,6 +33,7 @@ import (
33
33
restclient "k8s.io/client-go/rest"
34
34
"k8s.io/client-go/tools/clientcmd"
35
35
"k8s.io/client-go/tools/clientcmd/api"
36
+ "k8s.io/klog/v2"
36
37
ctrl "sigs.k8s.io/controller-runtime"
37
38
"sigs.k8s.io/controller-runtime/pkg/client"
38
39
"sigs.k8s.io/controller-runtime/pkg/controller"
@@ -134,6 +135,8 @@ func (r *ROSAControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.Req
134
135
return ctrl.Result {}, nil
135
136
}
136
137
138
+ log = log .WithValues ("cluster" , klog .KObj (cluster ))
139
+
137
140
if capiannotations .IsPaused (cluster , rosaControlPlane ) {
138
141
log .Info ("Reconciliation is paused for this object" )
139
142
return ctrl.Result {}, nil
@@ -144,6 +147,7 @@ func (r *ROSAControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.Req
144
147
Cluster : cluster ,
145
148
ControlPlane : rosaControlPlane ,
146
149
ControllerName : strings .ToLower (rosaControlPlaneKind ),
150
+ Logger : log ,
147
151
})
148
152
if err != nil {
149
153
return ctrl.Result {}, fmt .Errorf ("failed to create scope: %w" , err )
@@ -191,7 +195,12 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
191
195
192
196
if clusterID := cluster .ID (); clusterID != "" {
193
197
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 :
195
204
conditions .MarkTrue (rosaScope .ControlPlane , rosacontrolplanev1 .ROSAControlPlaneReadyCondition )
196
205
rosaScope .ControlPlane .Status .Ready = true
197
206
@@ -204,15 +213,25 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
204
213
if err := r .reconcileKubeconfig (ctx , rosaScope , rosaClient , cluster ); err != nil {
205
214
return ctrl.Result {}, fmt .Errorf ("failed to reconcile kubeconfig: %w" , err )
206
215
}
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.
208
227
return ctrl.Result {}, nil
209
228
}
210
229
211
230
conditions .MarkFalse (rosaScope .ControlPlane ,
212
231
rosacontrolplanev1 .ROSAControlPlaneReadyCondition ,
213
232
string (cluster .Status ().State ()),
214
233
clusterv1 .ConditionSeverityInfo ,
215
- "" )
234
+ cluster . Status (). Description () )
216
235
217
236
rosaScope .Info ("waiting for cluster to become ready" , "state" , cluster .Status ().State ())
218
237
// 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
333
352
334
353
newCluster , err := rosaClient .CreateCluster (clusterSpec )
335
354
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 )
338
356
}
339
357
340
358
rosaScope .Info ("cluster created" , "state" , newCluster .Status ().State ())
@@ -358,15 +376,22 @@ func (r *ROSAControlPlaneReconciler) reconcileDelete(ctx context.Context, rosaSc
358
376
return ctrl.Result {}, err
359
377
}
360
378
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 {
362
386
if err := rosaClient .DeleteCluster (cluster .ID ()); err != nil {
363
387
return ctrl.Result {}, err
364
388
}
365
389
}
366
390
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
370
395
}
371
396
372
397
func (r * ROSAControlPlaneReconciler ) reconcileKubeconfig (ctx context.Context , rosaScope * scope.ROSAControlPlaneScope , rosaClient * rosa.RosaClient , cluster * cmv1.Cluster ) error {
0 commit comments