@@ -278,6 +278,24 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
278278 clusterAddon .Status .Ready = false
279279 }
280280
281+ // In case the Kubernetes version stays the same, the hook server does not trigger.
282+ // Therefore, we have to check whether the ClusterStack is upgraded and if that is the case, the ClusterAddons have to be upgraded as well.
283+ if clusterAddon .Spec .ClusterStack != cluster .Spec .Topology .Class && clusterAddon .Status .KubernetesVersion == releaseAsset .Meta .Versions .Kubernetes {
284+ if clusterAddon .Spec .Version != releaseAsset .Meta .Versions .Components .ClusterAddon {
285+ clusterAddon .Status .HelmChartStatus = make (map [string ]csov1alpha1.HelmChartStatusConditions )
286+ clusterAddon .Status .CurrentHook = clusterAddon .Spec .Hook
287+ clusterAddon .Status .Ready = false
288+ conditions .Delete (clusterAddon , csov1alpha1 .HelmChartAppliedCondition )
289+ } else {
290+ // If the cluster addon version don't change we don't want to apply helm charts again.
291+ clusterAddon .Spec .ClusterStack = cluster .Spec .Topology .Class
292+ clusterAddon .Status .Ready = true
293+ }
294+ }
295+
296+ clusterAddon .Spec .ClusterStack = cluster .Spec .Topology .Class
297+ clusterAddon .Spec .Version = releaseAsset .Meta .Versions .Components .ClusterAddon
298+
281299 if clusterAddon .Status .Ready {
282300 return reconcile.Result {}, nil
283301 }
@@ -293,8 +311,38 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re
293311 return reconcile.Result {}, fmt .Errorf ("failed to parse clusteraddon.yaml config: %w" , err )
294312 }
295313
296- for _ , stage := range clusterAddonConfig .AddonStages [in .clusterAddon .Spec .Hook ] {
297- shouldRequeue , err := executeStage (ctx , stage , in )
314+ // In case the Kubernetes version stayed the same during an upgrade, the hook server does not trigger and
315+ // we just take the Helm charts that are supposed to be installed in the BeforeClusterUpgrade hook and apply them.
316+ if clusterAddon .Status .KubernetesVersion == releaseAsset .Meta .Versions .Kubernetes {
317+ clusterAddon .Spec .Hook = "BeforeClusterUpgrade"
318+ for _ , stage := range clusterAddonConfig .AddonStages ["BeforeClusterUpgrade" ] {
319+ shouldRequeue , err := r .executeStage (ctx , stage , in )
320+ if err != nil {
321+ return reconcile.Result {}, fmt .Errorf ("failed to execute stage: %w" , err )
322+ }
323+ if shouldRequeue {
324+ return reconcile.Result {RequeueAfter : 20 * time .Second }, nil
325+ }
326+ }
327+
328+ // Helm chart has been applied successfully
329+ // clusterAddon.Spec.Version = metadata.Versions.Components.ClusterAddon
330+ conditions .MarkTrue (clusterAddon , csov1alpha1 .HelmChartAppliedCondition )
331+
332+ // store the release kubernetes version and current hook
333+ clusterAddon .Status .Ready = true
334+
335+ return ctrl.Result {}, nil
336+ }
337+
338+ // If hook is empty we can don't want to proceed executing staged according to current hook
339+ // hence we can return.
340+ if clusterAddon .Spec .Hook == "" {
341+ return reconcile.Result {}, nil
342+ }
343+
344+ for _ , stage := range clusterAddonConfig .AddonStages [clusterAddon .Spec .Hook ] {
345+ shouldRequeue , err := r .executeStage (ctx , stage , in )
298346 if err != nil {
299347 return reconcile.Result {}, fmt .Errorf ("failed to execute stage: %w" , err )
300348 }
@@ -414,7 +462,7 @@ func (r *ClusterAddonReconciler) templateAndApplyClusterAddonHelmChart(ctx conte
414462 return shouldRequeue , nil
415463}
416464
417- func executeStage (ctx context.Context , stage clusteraddon.Stage , in templateAndApplyClusterAddonInput ) (bool , error ) {
465+ func ( r * ClusterAddonReconciler ) executeStage (ctx context.Context , stage clusteraddon.Stage , in templateAndApplyClusterAddonInput ) (bool , error ) {
418466 var (
419467 newResources []* csov1alpha1.Resource
420468 shouldRequeue bool
0 commit comments