diff --git a/api/v1alpha1/clusteraddon_types.go b/api/v1alpha1/clusteraddon_types.go index 9d6e8d0f1..db20ba2f7 100644 --- a/api/v1alpha1/clusteraddon_types.go +++ b/api/v1alpha1/clusteraddon_types.go @@ -64,10 +64,6 @@ type ClusterAddonStatus struct { // +optional Resources []*Resource `json:"resources,omitempty"` - // CurrentHook specifies the current running Hook. - // +optional - CurrentHook string `json:"currentHook,omitempty"` - // HelmChartStatus defines the status of helm chart in the cluster addon. // +optional HelmChartStatus map[string]HelmChartStatusConditions `json:"helmChartStatus,omitempty"` @@ -84,6 +80,7 @@ type ClusterAddonStatus struct { // +kubebuilder:object:root=true // +kubebuilder:subresource:status // +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.ownerReferences[?(@.kind==\"Cluster\")].name" +// +kubebuilder:printcolumn:name="Hook",type="string",JSONPath=".spec.hook",description="Present running hook" // +kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.ready" // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of Cluster Addon" // +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].reason" diff --git a/config/crd/bases/clusterstack.x-k8s.io_clusteraddons.yaml b/config/crd/bases/clusterstack.x-k8s.io_clusteraddons.yaml index 5697c2bd8..6b6bec1ac 100644 --- a/config/crd/bases/clusterstack.x-k8s.io_clusteraddons.yaml +++ b/config/crd/bases/clusterstack.x-k8s.io_clusteraddons.yaml @@ -18,6 +18,10 @@ spec: - jsonPath: .metadata.ownerReferences[?(@.kind=="Cluster")].name name: Cluster type: string + - description: Present running hook + jsonPath: .spec.hook + name: Hook + type: string - jsonPath: .status.ready name: Ready type: boolean @@ -155,9 +159,6 @@ spec: - type type: object type: array - currentHook: - description: CurrentHook specifies the current running Hook. - type: string helmChartStatus: additionalProperties: description: HelmChartStatusConditions defines the status of helm diff --git a/internal/controller/clusteraddon_controller.go b/internal/controller/clusteraddon_controller.go index 4560477cf..38ea515ba 100644 --- a/internal/controller/clusteraddon_controller.go +++ b/internal/controller/clusteraddon_controller.go @@ -303,9 +303,10 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re } } - if clusterAddon.Spec.Hook != clusterAddon.Status.CurrentHook { + // if a hook is specified, we cannot be ready yet + // if a hook is set, it is expected that HelmChartAppliedCondition is removed + if clusterAddon.Spec.Hook != "" { clusterAddon.Status.HelmChartStatus = make(map[string]csov1alpha1.HelmChartStatusConditions) - clusterAddon.Status.CurrentHook = clusterAddon.Spec.Hook clusterAddon.Status.Ready = false } @@ -314,7 +315,6 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re if clusterAddon.Spec.ClusterStack != cluster.Spec.Topology.Class && oldRelease.Meta.Versions.Kubernetes == releaseAsset.Meta.Versions.Kubernetes { if clusterAddon.Spec.Version != releaseAsset.Meta.Versions.Components.ClusterAddon { clusterAddon.Status.HelmChartStatus = make(map[string]csov1alpha1.HelmChartStatusConditions) - clusterAddon.Status.CurrentHook = clusterAddon.Spec.Hook clusterAddon.Status.Ready = false conditions.Delete(clusterAddon, csov1alpha1.HelmChartAppliedCondition) } else { @@ -396,8 +396,8 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re // remove the status resource if hook is finished clusterAddon.Status.Resources = make([]*csov1alpha1.Resource, 0) - // set the current hook and make cluster addon ready - clusterAddon.Status.CurrentHook = clusterAddon.Spec.Hook + // unset spec hook and make cluster addon ready + clusterAddon.Spec.Hook = "" clusterAddon.Status.Ready = true } @@ -718,11 +718,11 @@ func (r *ClusterAddonReconciler) templateAndApplyNewClusterStackAddonHelmChart(c if err != nil { return false, fmt.Errorf("failed to build template from old cluster addon values: %w", err) } - } - oldHelmTemplate, err = helmTemplateClusterAddon(oldClusterStackSubDirPath, oldBuildTemplate) - if err != nil { - return false, fmt.Errorf("failed to template old helm chart: %w", err) + oldHelmTemplate, err = helmTemplateClusterAddon(oldClusterStackSubDirPath, oldBuildTemplate) + if err != nil { + return false, fmt.Errorf("failed to template old helm chart: %w", err) + } } } @@ -807,7 +807,7 @@ func helmTemplateAndDelete(ctx context.Context, in templateAndApplyClusterAddonI } func getDynamicResourceAndEvaluateCEL(ctx context.Context, dynamicClient *dynamic.DynamicClient, discoveryClient *discovery.DiscoveryClient, waitCondition clusteraddon.WaitForCondition) error { - var evalMap = make(map[string]interface{}) + evalMap := make(map[string]interface{}) env, err := cel.NewEnv() if err != nil { diff --git a/internal/test/integration/workloadcluster/cluster_addon_test.go b/internal/test/integration/workloadcluster/cluster_addon_test.go index e79a9b013..0e6e3de74 100644 --- a/internal/test/integration/workloadcluster/cluster_addon_test.go +++ b/internal/test/integration/workloadcluster/cluster_addon_test.go @@ -493,8 +493,7 @@ var _ = Describe("ClusterAddonReconcilerNewWay", func() { return false } - return utils.IsPresentAndTrue(ctx, testEnv.Client, key, &foundClusterAddon, clusterv1.ReadyCondition) && - foundClusterAddon.Status.CurrentHook == "AfterControlPlaneInitialized" + return utils.IsPresentAndTrue(ctx, testEnv.Client, key, &foundClusterAddon, clusterv1.ReadyCondition) }, timeout, interval).Should(BeTrue()) }) })