@@ -280,6 +280,12 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
280280 return reconcile.Result {}, fmt .Errorf ("failed to get addon stages input: %w" , err )
281281 }
282282
283+ // clusteraddon.yaml in the release.
284+ clusterAddonConfig , err := clusteraddon .ParseClusterAddonConfig (in .clusterAddonConfigPath )
285+ if err != nil {
286+ return reconcile.Result {}, fmt .Errorf ("failed to parse clusteraddon.yaml config: %w" , err )
287+ }
288+
283289 var (
284290 oldRelease release.Release
285291 requeue bool
@@ -307,11 +313,13 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
307313 // if a hook is set, it is expected that HelmChartAppliedCondition is removed
308314 if clusterAddon .Spec .Hook != "" {
309315 // if the clusterAddon was ready before, it means this hook is fresh and we have to reset the status
310- if clusterAddon .Status .Ready {
311- clusterAddon .Status .HelmChartStatus = make (map [string ]csov1alpha1.HelmChartStatusConditions )
312- }
313- if clusterAddon .Status .HelmChartStatus == nil {
314- clusterAddon .Status .HelmChartStatus = make (map [string ]csov1alpha1.HelmChartStatusConditions )
316+ if clusterAddon .Status .Ready || len (clusterAddon .Status .Stages ) == 0 {
317+ clusterAddon .Status .Stages = make ([]csov1alpha1.StageStatus , len (clusterAddonConfig .AddonStages [clusterAddon .Spec .Hook ]))
318+ for i , stage := range clusterAddonConfig .AddonStages [clusterAddon .Spec .Hook ] {
319+ clusterAddon .Status .Stages [i ].Name = stage .HelmChartName
320+ clusterAddon .Status .Stages [i ].Action = stage .Action
321+ clusterAddon .Status .Stages [i ].Phase = csov1alpha1 .Pending
322+ }
315323 }
316324 clusterAddon .Status .Ready = false
317325 }
@@ -320,7 +328,14 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
320328 // Therefore, we have to check whether the ClusterStack is upgraded and if that is the case, the ClusterAddons have to be upgraded as well.
321329 if clusterAddon .Spec .ClusterStack != cluster .Spec .Topology .Class && oldRelease .Meta .Versions .Kubernetes == releaseAsset .Meta .Versions .Kubernetes {
322330 if clusterAddon .Spec .Version != releaseAsset .Meta .Versions .Components .ClusterAddon {
323- clusterAddon .Status .HelmChartStatus = make (map [string ]csov1alpha1.HelmChartStatusConditions )
331+ if clusterAddon .Status .Ready || len (clusterAddon .Status .Stages ) == 0 {
332+ clusterAddon .Status .Stages = make ([]csov1alpha1.StageStatus , len (clusterAddonConfig .AddonStages ["BeforeClusterUpgrade" ]))
333+ for i , stage := range clusterAddonConfig .AddonStages ["BeforeClusterUpgrade" ] {
334+ clusterAddon .Status .Stages [i ].Name = stage .HelmChartName
335+ clusterAddon .Status .Stages [i ].Action = stage .Action
336+ clusterAddon .Status .Stages [i ].Phase = csov1alpha1 .Pending
337+ }
338+ }
324339 clusterAddon .Status .Ready = false
325340 conditions .Delete (clusterAddon , csov1alpha1 .HelmChartAppliedCondition )
326341 } else {
@@ -336,12 +351,6 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
336351 return reconcile.Result {}, nil
337352 }
338353
339- // clusteraddon.yaml in the release.
340- clusterAddonConfig , err := clusteraddon .ParseClusterAddonConfig (in .clusterAddonConfigPath )
341- if err != nil {
342- return reconcile.Result {}, fmt .Errorf ("failed to parse clusteraddon.yaml config: %w" , err )
343- }
344-
345354 // In case the Kubernetes version stayed the same during an upgrade, the hook server does not trigger and
346355 // we just take the Helm charts that are supposed to be installed in the BeforeClusterUpgrade hook and apply them.
347356 if oldRelease .Meta .Versions .Kubernetes == releaseAsset .Meta .Versions .Kubernetes {
@@ -363,7 +372,7 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
363372 clusterAddon .Status .Resources = make ([]* csov1alpha1.Resource , 0 )
364373
365374 // remove the helm chart status from the status.
366- clusterAddon .Status .HelmChartStatus = make (map [ string ]csov1alpha1.HelmChartStatusConditions )
375+ clusterAddon .Status .Stages = make ([ ]csov1alpha1.StageStatus , 0 )
367376
368377 // update the latest cluster class
369378 clusterAddon .Spec .ClusterStack = cluster .Spec .Topology .Class
@@ -397,7 +406,7 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
397406 conditions .MarkTrue (clusterAddon , csov1alpha1 .HelmChartAppliedCondition )
398407
399408 // remove the helm chart status from the status.
400- clusterAddon .Status .HelmChartStatus = make (map [ string ]csov1alpha1.HelmChartStatusConditions )
409+ clusterAddon .Status .Stages = make ([ ]csov1alpha1.StageStatus , 0 )
401410
402411 // remove the status resource if hook is finished
403412 clusterAddon .Status .Resources = make ([]* csov1alpha1.Resource , 0 )
@@ -534,8 +543,8 @@ func (r *ClusterAddonReconciler) executeStage(ctx context.Context, stage cluster
534543 }
535544
536545check:
537- switch in .clusterAddon .Status . HelmChartStatus [ stage .HelmChartName ] {
538- case csov1alpha1 .None , csov1alpha1 .WaitingForPreCondition :
546+ switch in .clusterAddon .GetStagePhase ( stage .HelmChartName , stage . Action ) {
547+ case csov1alpha1 .Pending , csov1alpha1 .WaitingForPreCondition :
539548 // If WaitForPreCondition is mentioned.
540549 if ! reflect .DeepEqual (stage .WaitForPreCondition , clusteraddon.WaitForCondition {}) {
541550 // Evaluate the condition.
@@ -550,15 +559,16 @@ check:
550559 "failed to successfully evaluate pre condition: %q: %s" , stage .HelmChartName , err .Error (),
551560 )
552561
553- in .clusterAddon .Status . HelmChartStatus [ stage .HelmChartName ] = csov1alpha1 .WaitingForPreCondition
562+ in .clusterAddon .SetStagePhase ( stage .HelmChartName , stage . Action , csov1alpha1 .WaitingForPreCondition )
554563
555564 return true , nil
556565 }
557566 return false , fmt .Errorf ("failed to get dynamic resource and evaluate cel expression for pre condition: %w" , err )
558567 }
559568 logger .V (1 ).Info ("finished evaluating pre condition" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart" , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
560569 }
561- in .clusterAddon .Status .HelmChartStatus [stage .HelmChartName ] = csov1alpha1 .ApplyingOrDeleting
570+
571+ in .clusterAddon .SetStagePhase (stage .HelmChartName , stage .Action , csov1alpha1 .ApplyingOrDeleting )
562572 goto check
563573
564574 case csov1alpha1 .ApplyingOrDeleting :
@@ -584,7 +594,7 @@ check:
584594 // remove status resource if applied successfully
585595 in .clusterAddon .Status .Resources = make ([]* csov1alpha1.Resource , 0 )
586596
587- in .clusterAddon .Status . HelmChartStatus [ stage .HelmChartName ] = csov1alpha1 .WaitingForPostCondition
597+ in .clusterAddon .SetStagePhase ( stage .HelmChartName , stage . Action , csov1alpha1 .WaitingForPostCondition )
588598 goto check
589599
590600 } else {
@@ -610,7 +620,7 @@ check:
610620 // remove status resource if deleted successfully
611621 in .clusterAddon .Status .Resources = make ([]* csov1alpha1.Resource , 0 )
612622
613- in .clusterAddon .Status . HelmChartStatus [ stage .HelmChartName ] = csov1alpha1 .WaitingForPostCondition
623+ in .clusterAddon .SetStagePhase ( stage .HelmChartName , stage . Action , csov1alpha1 .WaitingForPostCondition )
614624 goto check
615625 }
616626
@@ -636,7 +646,7 @@ check:
636646 logger .V (1 ).Info ("finished evaluating post condition" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart" , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
637647 }
638648
639- in .clusterAddon .Status . HelmChartStatus [ stage .HelmChartName ] = csov1alpha1 .Done
649+ in .clusterAddon .SetStagePhase ( stage .HelmChartName , stage . Action , csov1alpha1 .Done )
640650 }
641651
642652 return false , nil
0 commit comments