From aa9fde98f33967d4b0cb2bfa2cda89737ff281a2 Mon Sep 17 00:00:00 2001 From: Ekaterina Kazakova Date: Mon, 16 Dec 2024 19:54:16 +0400 Subject: [PATCH] Fix panic when tracking managed cluster heartbeat --- api/v1alpha1/templates_common.go | 2 ++ internal/controller/template_controller.go | 2 ++ internal/telemetry/tracker.go | 2 +- .../hmc/templates/crds/hmc.mirantis.com_clustertemplates.yaml | 4 ++++ .../templates/crds/hmc.mirantis.com_providertemplates.yaml | 4 ++++ .../hmc/templates/crds/hmc.mirantis.com_servicetemplates.yaml | 4 ++++ 6 files changed, 17 insertions(+), 1 deletion(-) diff --git a/api/v1alpha1/templates_common.go b/api/v1alpha1/templates_common.go index fd5e4f1d..8e457ee1 100644 --- a/api/v1alpha1/templates_common.go +++ b/api/v1alpha1/templates_common.go @@ -68,6 +68,8 @@ type TemplateStatusCommon struct { // ChartRef is a reference to a source controller resource containing the // Helm chart representing the template. ChartRef *helmcontrollerv2.CrossNamespaceSourceReference `json:"chartRef,omitempty"` + // ChartVersion represents the version of the Helm Chart associated with this template. + ChartVersion string `json:"chartVersion,omitempty"` // Description contains information about the template. Description string `json:"description,omitempty"` diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go index 32f33a52..0dc3fd25 100644 --- a/internal/controller/template_controller.go +++ b/internal/controller/template_controller.go @@ -214,6 +214,8 @@ func (r *TemplateReconciler) ReconcileTemplate(ctx context.Context, template tem Name: hcChart.Name, Namespace: hcChart.Namespace, } + status.ChartVersion = hcChart.Spec.Version + if reportStatus, err := helm.ArtifactReady(hcChart); err != nil { l.Info("HelmChart Artifact is not ready") if reportStatus { diff --git a/internal/telemetry/tracker.go b/internal/telemetry/tracker.go index b44d9057..8e2e4206 100644 --- a/internal/telemetry/tracker.go +++ b/internal/telemetry/tracker.go @@ -91,7 +91,7 @@ func (t *Tracker) trackManagedClusterHeartbeat(ctx context.Context) error { string(managedCluster.UID), clusterID, managedCluster.Spec.Template, - template.Spec.Helm.ChartSpec.Version, + template.Status.ChartVersion, template.Status.Providers, ) if err != nil { diff --git a/templates/provider/hmc/templates/crds/hmc.mirantis.com_clustertemplates.yaml b/templates/provider/hmc/templates/crds/hmc.mirantis.com_clustertemplates.yaml index e207d6ec..220d710e 100644 --- a/templates/provider/hmc/templates/crds/hmc.mirantis.com_clustertemplates.yaml +++ b/templates/provider/hmc/templates/crds/hmc.mirantis.com_clustertemplates.yaml @@ -295,6 +295,10 @@ spec: - kind - name type: object + chartVersion: + description: ChartVersion represents the version of the Helm Chart + associated with this template. + type: string config: description: |- Config demonstrates available parameters for template customization, diff --git a/templates/provider/hmc/templates/crds/hmc.mirantis.com_providertemplates.yaml b/templates/provider/hmc/templates/crds/hmc.mirantis.com_providertemplates.yaml index 449faa5a..cfe629e8 100644 --- a/templates/provider/hmc/templates/crds/hmc.mirantis.com_providertemplates.yaml +++ b/templates/provider/hmc/templates/crds/hmc.mirantis.com_providertemplates.yaml @@ -300,6 +300,10 @@ spec: - kind - name type: object + chartVersion: + description: ChartVersion represents the version of the Helm Chart + associated with this template. + type: string config: description: |- Config demonstrates available parameters for template customization, diff --git a/templates/provider/hmc/templates/crds/hmc.mirantis.com_servicetemplates.yaml b/templates/provider/hmc/templates/crds/hmc.mirantis.com_servicetemplates.yaml index 73990678..1a96f18c 100644 --- a/templates/provider/hmc/templates/crds/hmc.mirantis.com_servicetemplates.yaml +++ b/templates/provider/hmc/templates/crds/hmc.mirantis.com_servicetemplates.yaml @@ -284,6 +284,10 @@ spec: - kind - name type: object + chartVersion: + description: ChartVersion represents the version of the Helm Chart + associated with this template. + type: string config: description: |- Config demonstrates available parameters for template customization,