@@ -322,7 +322,7 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
322322 if clusterAddon .Status .Ready || len (clusterAddon .Status .Stages ) == 0 {
323323 clusterAddon .Status .Stages = make ([]csov1alpha1.StageStatus , len (clusterAddonConfig .AddonStages [clusterAddon .Spec .Hook ]))
324324 for i , stage := range clusterAddonConfig .AddonStages [clusterAddon .Spec .Hook ] {
325- clusterAddon .Status .Stages [i ].Name = stage .HelmChartName
325+ clusterAddon .Status .Stages [i ].Name = stage .Name
326326 clusterAddon .Status .Stages [i ].Action = stage .Action
327327 clusterAddon .Status .Stages [i ].Phase = csov1alpha1 .StagePhasePending
328328 }
@@ -337,7 +337,7 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
337337 if clusterAddon .Status .Ready || len (clusterAddon .Status .Stages ) == 0 {
338338 clusterAddon .Status .Stages = make ([]csov1alpha1.StageStatus , len (clusterAddonConfig .AddonStages ["BeforeClusterUpgrade" ]))
339339 for i , stage := range clusterAddonConfig .AddonStages ["BeforeClusterUpgrade" ] {
340- clusterAddon .Status .Stages [i ].Name = stage .HelmChartName
340+ clusterAddon .Status .Stages [i ].Name = stage .Name
341341 clusterAddon .Status .Stages [i ].Action = stage .Action
342342 clusterAddon .Status .Stages [i ].Phase = csov1alpha1 .StagePhasePending
343343 }
@@ -361,6 +361,7 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
361361 // we just take the Helm charts that are supposed to be installed in the BeforeClusterUpgrade hook and apply them.
362362 if oldRelease != nil && oldRelease .Meta .Versions .Kubernetes == releaseAsset .Meta .Versions .Kubernetes {
363363 clusterAddon .Spec .Hook = "BeforeClusterUpgrade"
364+
364365 for _ , stage := range clusterAddonConfig .AddonStages ["BeforeClusterUpgrade" ] {
365366 shouldRequeue , err := r .executeStage (ctx , stage , in )
366367 if err != nil {
@@ -428,7 +429,7 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
428429 for _ , stage := range clusterAddonConfig .AddonStages [clusterAddon .Spec .Hook ] {
429430 shouldRequeue , err := r .executeStage (ctx , stage , in )
430431 if err != nil {
431- return reconcile.Result {}, fmt .Errorf ("failed to execute stage: %q: %w" , stage .HelmChartName , err )
432+ return reconcile.Result {}, fmt .Errorf ("failed to execute stage: %q: %w" , stage .Name , err )
432433 }
433434 if shouldRequeue {
434435 return reconcile.Result {RequeueAfter : 20 * time .Second }, nil
@@ -490,14 +491,14 @@ func (r *ClusterAddonReconciler) getNewReleaseObjects(ctx context.Context, in *t
490491 )
491492
492493 for _ , stage := range clusterAddonConfig .AddonStages [in .clusterAddon .Spec .Hook ] {
493- if _ , err := os .Stat (filepath .Join (in .newDestinationClusterAddonChartDir , stage .HelmChartName , release .OverwriteYaml )); err == nil {
494- newBuildTemplate , err = buildTemplateFromClusterAddonValues (ctx , filepath .Join (in .newDestinationClusterAddonChartDir , stage .HelmChartName , release .OverwriteYaml ), in .cluster , r .Client )
494+ if _ , err := os .Stat (filepath .Join (in .newDestinationClusterAddonChartDir , stage .Name , release .OverwriteYaml )); err == nil {
495+ newBuildTemplate , err = buildTemplateFromClusterAddonValues (ctx , filepath .Join (in .newDestinationClusterAddonChartDir , stage .Name , release .OverwriteYaml ), in .cluster , r .Client )
495496 if err != nil {
496497 return nil , fmt .Errorf ("failed to build template from new cluster addon values of the latest cluster stack: %w" , err )
497498 }
498499 }
499500
500- helmTemplate , err := helmTemplateClusterAddon (filepath .Join (in .newDestinationClusterAddonChartDir , stage .HelmChartName ), newBuildTemplate )
501+ helmTemplate , err := helmTemplateClusterAddon (filepath .Join (in .newDestinationClusterAddonChartDir , stage .Name ), newBuildTemplate )
501502 if err != nil {
502503 return nil , fmt .Errorf ("failed to template new helm chart of the latest cluster stack: %w" , err )
503504 }
@@ -566,14 +567,14 @@ func (r *ClusterAddonReconciler) getOldReleaseObjects(ctx context.Context, in *t
566567 }
567568
568569 for _ , stage := range clusterAddonConfig .AddonStages [hook ] {
569- if _ , err := os .Stat (filepath .Join (in .oldDestinationClusterAddonChartDir , stage .HelmChartName , release .OverwriteYaml )); err == nil {
570- newBuildTemplate , err = buildTemplateFromClusterAddonValues (ctx , filepath .Join (in .oldDestinationClusterAddonChartDir , stage .HelmChartName , release .OverwriteYaml ), in .cluster , r .Client )
570+ if _ , err := os .Stat (filepath .Join (in .oldDestinationClusterAddonChartDir , stage .Name , release .OverwriteYaml )); err == nil {
571+ newBuildTemplate , err = buildTemplateFromClusterAddonValues (ctx , filepath .Join (in .oldDestinationClusterAddonChartDir , stage .Name , release .OverwriteYaml ), in .cluster , r .Client )
571572 if err != nil {
572573 return nil , fmt .Errorf ("failed to build template from new cluster addon values: %w" , err )
573574 }
574575 }
575576
576- helmTemplate , err := helmTemplateClusterAddon (filepath .Join (in .oldDestinationClusterAddonChartDir , stage .HelmChartName ), newBuildTemplate )
577+ helmTemplate , err := helmTemplateClusterAddon (filepath .Join (in .oldDestinationClusterAddonChartDir , stage .Name ), newBuildTemplate )
577578 if err != nil {
578579 return nil , fmt .Errorf ("failed to template new helm chart: %w" , err )
579580 }
@@ -737,7 +738,7 @@ func (r *ClusterAddonReconciler) executeStage(ctx context.Context, stage *cluste
737738 err error
738739 )
739740
740- _ , exists := in .chartMap [stage .HelmChartName ]
741+ _ , exists := in .chartMap [stage .Name ]
741742 if ! exists {
742743 // do not reconcile by returning error, just create an event.
743744 conditions .MarkFalse (
@@ -746,44 +747,44 @@ func (r *ClusterAddonReconciler) executeStage(ctx context.Context, stage *cluste
746747 csov1alpha1 .HelmChartMissingReason ,
747748 clusterv1 .ConditionSeverityInfo ,
748749 "helm chart name doesn't exists in the cluster addon helm chart: %q" ,
749- stage .HelmChartName ,
750+ stage .Name ,
750751 )
751752 return false , nil
752753 }
753754
754755check:
755- switch in .clusterAddon .GetStagePhase (stage .HelmChartName , stage .Action ) {
756+ switch in .clusterAddon .GetStagePhase (stage .Name , stage .Action ) {
756757 case csov1alpha1 .StagePhasePending , csov1alpha1 .StagePhaseWaitingForPreCondition :
757758 // If WaitForPreCondition is mentioned.
758759 if ! reflect .DeepEqual (stage .WaitForPreCondition , clusteraddon.WaitForCondition {}) {
759760 // Evaluate the condition.
760- logger .V (1 ).Info ("starting to evaluate pre condition" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart " , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
761+ logger .V (1 ).Info ("starting to evaluate pre condition" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "name " , stage .Name , "hook" , in .clusterAddon .Spec .Hook )
761762 if err := getDynamicResourceAndEvaluateCEL (ctx , in .dynamicClient , in .discoverClient , stage .WaitForPreCondition ); err != nil {
762763 if errors .Is (err , clusteraddon .ErrConditionNotMatch ) {
763764 conditions .MarkFalse (
764765 in .clusterAddon ,
765766 csov1alpha1 .EvaluatedCELCondition ,
766767 csov1alpha1 .FailedToEvaluatePreConditionReason ,
767768 clusterv1 .ConditionSeverityInfo ,
768- "failed to successfully evaluate pre condition: %q: %s" , stage .HelmChartName , err .Error (),
769+ "failed to successfully evaluate pre condition: %q: %s" , stage .Name , err .Error (),
769770 )
770771
771- in .clusterAddon .SetStagePhase (stage .HelmChartName , stage .Action , csov1alpha1 .StagePhaseWaitingForPreCondition )
772+ in .clusterAddon .SetStagePhase (stage .Name , stage .Action , csov1alpha1 .StagePhaseWaitingForPreCondition )
772773
773774 return true , nil
774775 }
775776 return false , fmt .Errorf ("failed to get dynamic resource and evaluate cel expression for pre condition: %w" , err )
776777 }
777- logger .V (1 ).Info ("finished evaluating pre condition" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart " , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
778+ logger .V (1 ).Info ("finished evaluating pre condition" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "name " , stage .Name , "hook" , in .clusterAddon .Spec .Hook )
778779 }
779780
780- in .clusterAddon .SetStagePhase (stage .HelmChartName , stage .Action , csov1alpha1 .StagePhaseApplyingOrDeleting )
781+ in .clusterAddon .SetStagePhase (stage .Name , stage .Action , csov1alpha1 .StagePhaseApplyingOrDeleting )
781782 goto check
782783
783784 case csov1alpha1 .StagePhaseApplyingOrDeleting :
784785 if stage .Action == clusteraddon .Apply {
785- logger .V (1 ).Info ("starting to apply helm chart" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart " , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
786- shouldRequeue , err = r .templateAndApplyNewClusterStackAddonHelmChart (ctx , in , stage .HelmChartName )
786+ logger .V (1 ).Info ("starting to apply helm chart" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "name " , stage .Name , "hook" , in .clusterAddon .Spec .Hook )
787+ shouldRequeue , err = r .templateAndApplyNewClusterStackAddonHelmChart (ctx , in , stage .Name )
787788 if err != nil {
788789 return false , fmt .Errorf ("failed to helm template and apply: %w" , err )
789790 }
@@ -793,22 +794,22 @@ check:
793794 csov1alpha1 .HelmChartAppliedCondition ,
794795 csov1alpha1 .FailedToApplyObjectsReason ,
795796 clusterv1 .ConditionSeverityInfo ,
796- "failed to successfully apply helm chart: %q" , stage .HelmChartName ,
797+ "failed to successfully apply helm chart: %q" , stage .Name ,
797798 )
798799
799800 return true , nil
800801 }
801- logger .V (1 ).Info ("finished applying helm chart" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart " , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
802+ logger .V (1 ).Info ("finished applying helm chart" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "name " , stage .Name , "hook" , in .clusterAddon .Spec .Hook )
802803
803804 // remove status resource if applied successfully
804805 in .clusterAddon .Status .Resources = make ([]* csov1alpha1.Resource , 0 )
805806
806- in .clusterAddon .SetStagePhase (stage .HelmChartName , stage .Action , csov1alpha1 .StagePhaseWaitingForPostCondition )
807+ in .clusterAddon .SetStagePhase (stage .Name , stage .Action , csov1alpha1 .StagePhaseWaitingForPostCondition )
807808 goto check
808809 } else {
809810 // Delete part
810- logger .V (1 ).Info ("starting to delete helm chart" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart " , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
811- shouldRequeue , err = helmTemplateAndDeleteNewClusterStack (ctx , in , stage .HelmChartName )
811+ logger .V (1 ).Info ("starting to delete helm chart" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "name " , stage .Name , "hook" , in .clusterAddon .Spec .Hook )
812+ shouldRequeue , err = helmTemplateAndDeleteNewClusterStack (ctx , in , stage .Name )
812813 if err != nil {
813814 return false , fmt .Errorf ("failed to delete helm chart: %w" , err )
814815 }
@@ -818,43 +819,43 @@ check:
818819 csov1alpha1 .HelmChartDeletedCondition ,
819820 csov1alpha1 .FailedToDeleteObjectsReason ,
820821 clusterv1 .ConditionSeverityInfo ,
821- "failed to successfully delete helm chart: %q" , stage .HelmChartName ,
822+ "failed to successfully delete helm chart: %q" , stage .Name ,
822823 )
823824
824825 return true , nil
825826 }
826- logger .V (1 ).Info ("finished deleting helm chart" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart " , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
827+ logger .V (1 ).Info ("finished deleting helm chart" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "name " , stage .Name , "hook" , in .clusterAddon .Spec .Hook )
827828
828829 // remove status resource if deleted successfully
829830 in .clusterAddon .Status .Resources = make ([]* csov1alpha1.Resource , 0 )
830831
831- in .clusterAddon .SetStagePhase (stage .HelmChartName , stage .Action , csov1alpha1 .StagePhaseWaitingForPostCondition )
832+ in .clusterAddon .SetStagePhase (stage .Name , stage .Action , csov1alpha1 .StagePhaseWaitingForPostCondition )
832833 goto check
833834 }
834835
835836 case csov1alpha1 .StagePhaseWaitingForPostCondition :
836837 // If WaitForPostCondition is mentioned.
837838 if ! reflect .DeepEqual (stage .WaitForPostCondition , clusteraddon.WaitForCondition {}) {
838839 // Evaluate the condition.
839- logger .V (1 ).Info ("starting to evaluate post condition" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart " , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
840+ logger .V (1 ).Info ("starting to evaluate post condition" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "name " , stage .Name , "hook" , in .clusterAddon .Spec .Hook )
840841 if err := getDynamicResourceAndEvaluateCEL (ctx , in .dynamicClient , in .discoverClient , stage .WaitForPostCondition ); err != nil {
841842 if errors .Is (err , clusteraddon .ErrConditionNotMatch ) {
842843 conditions .MarkFalse (
843844 in .clusterAddon ,
844845 csov1alpha1 .EvaluatedCELCondition ,
845846 csov1alpha1 .FailedToEvaluatePostConditionReason ,
846847 clusterv1 .ConditionSeverityInfo ,
847- "failed to successfully evaluate post condition: %q: %s" , stage .HelmChartName , err .Error (),
848+ "failed to successfully evaluate post condition: %q: %s" , stage .Name , err .Error (),
848849 )
849850
850851 return true , nil
851852 }
852853 return false , fmt .Errorf ("failed to get dynamic resource and evaluate cel expression for post condition: %w" , err )
853854 }
854- logger .V (1 ).Info ("finished evaluating post condition" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart " , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
855+ logger .V (1 ).Info ("finished evaluating post condition" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "name " , stage .Name , "hook" , in .clusterAddon .Spec .Hook )
855856 }
856857
857- in .clusterAddon .SetStagePhase (stage .HelmChartName , stage .Action , csov1alpha1 .StagePhaseDone )
858+ in .clusterAddon .SetStagePhase (stage .Name , stage .Action , csov1alpha1 .StagePhaseDone )
858859 }
859860
860861 return false , nil
@@ -926,7 +927,7 @@ func (r *ClusterAddonReconciler) downloadOldClusterStackRelease(ctx context.Cont
926927 return & releaseAsset , false , nil
927928}
928929
929- func (r * ClusterAddonReconciler ) templateAndApplyNewClusterStackAddonHelmChart (ctx context.Context , in * templateAndApplyClusterAddonInput , helmChartName string ) (bool , error ) {
930+ func (r * ClusterAddonReconciler ) templateAndApplyNewClusterStackAddonHelmChart (ctx context.Context , in * templateAndApplyClusterAddonInput , name string ) (bool , error ) {
930931 var (
931932 oldHelmTemplate []byte
932933 oldBuildTemplate []byte
@@ -935,7 +936,7 @@ func (r *ClusterAddonReconciler) templateAndApplyNewClusterStackAddonHelmChart(c
935936 )
936937
937938 if in .oldDestinationClusterAddonChartDir != "" {
938- oldClusterStackSubDirPath := filepath .Join (in .oldDestinationClusterAddonChartDir , helmChartName )
939+ oldClusterStackSubDirPath := filepath .Join (in .oldDestinationClusterAddonChartDir , name )
939940
940941 // we skip helm templating if last cluster stack don't follow the new convention.
941942 if _ , err := os .Stat (filepath .Join (oldClusterStackSubDirPath , release .OverwriteYaml )); err == nil {
@@ -951,7 +952,7 @@ func (r *ClusterAddonReconciler) templateAndApplyNewClusterStackAddonHelmChart(c
951952 }
952953 }
953954
954- newClusterStackSubDirPath := filepath .Join (in .newDestinationClusterAddonChartDir , helmChartName )
955+ newClusterStackSubDirPath := filepath .Join (in .newDestinationClusterAddonChartDir , name )
955956
956957 if _ , err := os .Stat (filepath .Join (newClusterStackSubDirPath , release .OverwriteYaml )); err == nil {
957958 newBuildTemplate , err = buildTemplateFromClusterAddonValues (ctx , filepath .Join (newClusterStackSubDirPath , release .OverwriteYaml ), in .cluster , r .Client )
@@ -976,13 +977,13 @@ func (r *ClusterAddonReconciler) templateAndApplyNewClusterStackAddonHelmChart(c
976977 return shouldRequeue , nil
977978}
978979
979- func helmTemplateAndDeleteNewClusterStack (ctx context.Context , in * templateAndApplyClusterAddonInput , helmChartName string ) (bool , error ) {
980+ func helmTemplateAndDeleteNewClusterStack (ctx context.Context , in * templateAndApplyClusterAddonInput , name string ) (bool , error ) {
980981 var (
981982 buildTemplate []byte
982983 err error
983984 )
984985
985- newClusterStackSubDirPath := filepath .Join (in .newDestinationClusterAddonChartDir , helmChartName )
986+ newClusterStackSubDirPath := filepath .Join (in .newDestinationClusterAddonChartDir , name )
986987 newHelmTemplate , err := helmTemplateClusterAddon (newClusterStackSubDirPath , buildTemplate )
987988 if err != nil {
988989 return false , fmt .Errorf ("failed to template new helm chart: %w" , err )
0 commit comments