@@ -39,7 +39,6 @@ import (
3939 "github.com/SovereignCloudStack/cluster-stack-operator/pkg/kube"
4040 "github.com/SovereignCloudStack/cluster-stack-operator/pkg/release"
4141 "github.com/SovereignCloudStack/cluster-stack-operator/pkg/workloadcluster"
42- "github.com/go-logr/logr"
4342 sprig "github.com/go-task/slim-sprig"
4443 "github.com/google/cel-go/cel"
4544 celtypes "github.com/google/cel-go/common/types"
@@ -213,8 +212,6 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
213212 return reconcile.Result {}, fmt .Errorf ("failed to get cluster addon config path: %w" , err )
214213 }
215214
216- logger := log .FromContext (ctx )
217-
218215 // Check whether current Helm chart has been applied in the workload cluster. If not, then we need to apply the helm chart (again).
219216 // the spec.clusterStack is only set after a Helm chart from a ClusterStack has been applied successfully.
220217 // If it is not set, the Helm chart has never been applied.
@@ -284,7 +281,7 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
284281 }
285282
286283 if clusterAddon .Spec .ClusterStack != "" {
287- oldClusterStackAddonChartPath , requeue , err := r .downloadOldClusterStackRelease (ctx , clusterAddon , logger )
284+ oldClusterStackAddonChartPath , requeue , err := r .downloadOldClusterStackRelease (ctx , clusterAddon )
288285 if err != nil {
289286 return reconcile.Result {}, fmt .Errorf ("failed to download old cluster stack releases: %w" , err )
290287 }
@@ -296,8 +293,6 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
296293 // dst - /tmp/cluster-stacks/docker-ferrol-1-27-v1/docker-ferrol-1-27-cluster-addon-v1/
297294 in .oldDestinationClusterAddonChartDir = strings .TrimSuffix (oldClusterStackAddonChartPath , ".tgz" )
298295
299- logger .Info ("old cluster stack's cluster addon chart path" , "path" , in .oldDestinationClusterAddonChartDir )
300-
301296 if err := unTarContent (oldClusterStackAddonChartPath , in .oldDestinationClusterAddonChartDir ); err != nil {
302297 return reconcile.Result {}, fmt .Errorf ("failed to untar cluster addon chart: %q: %w" , oldClusterStackAddonChartPath , err )
303298 }
@@ -502,6 +497,8 @@ func (r *ClusterAddonReconciler) templateAndApplyClusterAddonHelmChart(ctx conte
502497}
503498
504499func (r * ClusterAddonReconciler ) executeStage (ctx context.Context , stage clusteraddon.Stage , in templateAndApplyClusterAddonInput ) (bool , error ) {
500+ logger := log .FromContext (ctx )
501+
505502 var (
506503 shouldRequeue bool
507504 err error
@@ -524,9 +521,10 @@ func (r *ClusterAddonReconciler) executeStage(ctx context.Context, stage cluster
524521check:
525522 switch in .clusterAddon .Status .HelmChartStatus [stage .HelmChartName ] {
526523 case csov1alpha1 .None :
527- // If no WaitForPreCondition is mentioned.
524+ // If WaitForPreCondition is mentioned.
528525 if ! reflect .DeepEqual (stage .WaitForPreCondition , clusteraddon.WaitForCondition {}) {
529526 // Evaluate the condition.
527+ logger .V (1 ).Info ("starting to evaluate pre condition" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart" , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
530528 if err := getDynamicResourceAndEvaluateCEL (ctx , in .dynamicClient , in .discoverClient , stage .WaitForPreCondition ); err != nil {
531529 if errors .Is (err , clusteraddon .ConditionNotMatchError ) {
532530 conditions .MarkFalse (
@@ -543,12 +541,14 @@ check:
543541 }
544542 return false , fmt .Errorf ("failed to get dynamic resource and evaluate cel expression for pre condition: %w" , err )
545543 }
544+ logger .V (1 ).Info ("finished evaluating pre condition" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart" , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
546545 }
547546 in .clusterAddon .Status .HelmChartStatus [stage .HelmChartName ] = csov1alpha1 .ApplyingOrDeleting
548547 goto check
549548
550549 case csov1alpha1 .ApplyingOrDeleting :
551550 if stage .Action == clusteraddon .Apply {
551+ logger .V (1 ).Info ("starting to apply helm chart" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart" , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
552552 shouldRequeue , err = helmTemplateAndApplyNewClusterStack (ctx , in , stage .HelmChartName )
553553 if err != nil {
554554 return false , fmt .Errorf ("failed to helm template and apply: %w" , err )
@@ -564,12 +564,14 @@ check:
564564
565565 return true , nil
566566 }
567+ logger .V (1 ).Info ("finished applying helm chart" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart" , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
567568
568569 in .clusterAddon .Status .HelmChartStatus [stage .HelmChartName ] = csov1alpha1 .WaitingForPostCondition
569570 goto check
570571
571572 } else {
572573 // Delete part
574+ logger .V (1 ).Info ("starting to delete helm chart" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart" , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
573575 shouldRequeue , err = helmTemplateAndDeleteNewClusterStack (ctx , in , stage .HelmChartName )
574576 if err != nil {
575577 return false , fmt .Errorf ("failed to delete helm chart: %w" , err )
@@ -585,14 +587,17 @@ check:
585587
586588 return true , nil
587589 }
590+ logger .V (1 ).Info ("finished deleting helm chart" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart" , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
591+
588592 in .clusterAddon .Status .HelmChartStatus [stage .HelmChartName ] = csov1alpha1 .WaitingForPostCondition
589593 goto check
590594 }
591595
592596 case csov1alpha1 .WaitingForPostCondition :
593- // If no WaitForPostCondition is mentioned.
597+ // If WaitForPostCondition is mentioned.
594598 if ! reflect .DeepEqual (stage .WaitForPostCondition , clusteraddon.WaitForCondition {}) {
595599 // Evaluate the condition.
600+ logger .V (1 ).Info ("starting to evaluate post condition" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart" , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
596601 if err := getDynamicResourceAndEvaluateCEL (ctx , in .dynamicClient , in .discoverClient , stage .WaitForPostCondition ); err != nil {
597602 if errors .Is (err , clusteraddon .ConditionNotMatchError ) {
598603 conditions .MarkFalse (
@@ -607,7 +612,9 @@ check:
607612 }
608613 return false , fmt .Errorf ("failed to get dynamic resource and evaluate cel expression for post condition: %w" , err )
609614 }
615+ logger .V (1 ).Info ("finished evaluating post condition" , "clusterStack" , in .clusterAddon .Spec .ClusterStack , "helm chart" , stage .HelmChartName , "hook" , in .clusterAddon .Spec .Hook )
610616 }
617+
611618 in .clusterAddon .Status .HelmChartStatus [stage .HelmChartName ] = csov1alpha1 .Done
612619 }
613620
@@ -644,9 +651,7 @@ func (r *ClusterAddonReconciler) downloadOldClusterStackRelease(ctx context.Cont
644651 return "" , true , nil
645652 }
646653 if download {
647- logger .Info ("the old cluster stack is not present" , "clusterstack" , clusterAddon .Spec .ClusterStack )
648654 // if download is true, it means that the release assets have not been downloaded yet
649-
650655 conditions .MarkFalse (clusterAddon , csov1alpha1 .ClusterStackReleaseAssetsReadyCondition , csov1alpha1 .ReleaseAssetsNotDownloadedYetReason , clusterv1 .ConditionSeverityInfo , "assets not downloaded yet" )
651656
652657 // this is the point where we download the release.
@@ -683,8 +688,6 @@ func (r *ClusterAddonReconciler) downloadOldClusterStackRelease(ctx context.Cont
683688}
684689
685690func helmTemplateAndApplyNewClusterStack (ctx context.Context , in templateAndApplyClusterAddonInput , helmChartName string ) (bool , error ) {
686- logger := log .FromContext (ctx )
687-
688691 var (
689692 buildTemplate []byte
690693 oldHelmTemplate []byte
@@ -697,15 +700,13 @@ func helmTemplateAndApplyNewClusterStack(ctx context.Context, in templateAndAppl
697700 if err != nil {
698701 return false , fmt .Errorf ("failed to template old helm chart: %w" , err )
699702 }
700- logger .Info ("oldClusterStackAddonChartPath v1" , "path" , oldClusterStackSubDirPath )
701703 }
702704
703705 newClusterStackSubDirPath := filepath .Join (in .newDestinationClusterAddonChartDir , helmChartName )
704706 newHelmTemplate , err := helmTemplateClusterAddon (newClusterStackSubDirPath , buildTemplate , true )
705707 if err != nil {
706708 return false , fmt .Errorf ("failed to template new helm chart: %w" , err )
707709 }
708- logger .Info ("newClusterStackSubDirPath v1" , "path" , newClusterStackSubDirPath )
709710
710711 shouldRequeue , err := in .kubeClient .ApplyNewClusterStack (ctx , oldHelmTemplate , newHelmTemplate )
711712 if err != nil {
@@ -716,28 +717,16 @@ func helmTemplateAndApplyNewClusterStack(ctx context.Context, in templateAndAppl
716717}
717718
718719func helmTemplateAndDeleteNewClusterStack (ctx context.Context , in templateAndApplyClusterAddonInput , helmChartName string ) (bool , error ) {
719- // logger := log.FromContext(ctx)
720720 var (
721721 buildTemplate []byte
722- // oldHelmTemplate []byte
723- err error
722+ err error
724723 )
725724
726- // if in.oldDestinationClusterAddonChartDir != "" {
727- // oldClusterStackSubDirPath := filepath.Join(in.oldDestinationClusterAddonChartDir, helmChartName)
728- // oldHelmTemplate, err = helmTemplateClusterAddon(oldClusterStackSubDirPath, buildTemplate, true)
729- // if err != nil {
730- // return false, fmt.Errorf("failed to template old helm chart: %w", err)
731- // }
732- // logger.Info("oldClusterStackAddonChartPath v1", "path", oldClusterStackSubDirPath)
733- // }
734-
735725 newClusterStackSubDirPath := filepath .Join (in .newDestinationClusterAddonChartDir , helmChartName )
736726 newHelmTemplate , err := helmTemplateClusterAddon (newClusterStackSubDirPath , buildTemplate , true )
737727 if err != nil {
738728 return false , fmt .Errorf ("failed to template new helm chart: %w" , err )
739729 }
740- // logger.Info("newClusterStackSubDirPath v1", "path", newClusterStackSubDirPath)
741730
742731 shouldRequeue , err := in .kubeClient .DeleteNewClusterStack (ctx , newHelmTemplate )
743732 if err != nil {
0 commit comments