From ff1a51fd17a7197480c160e6e11196e1dfaf0570 Mon Sep 17 00:00:00 2001 From: Janis Kemper Date: Mon, 2 Sep 2024 17:50:00 +0100 Subject: [PATCH] :seedling: Use condition to mark false clusteraddon.yaml Add a condition to mark an invalid clusteraddon.yaml. Also add an event. Signed-off-by: janiskemper --- api/v1alpha1/conditions_const.go | 14 +++++++++++--- internal/controller/clusteraddon_controller.go | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/api/v1alpha1/conditions_const.go b/api/v1alpha1/conditions_const.go index 82b59906..24ba7760 100644 --- a/api/v1alpha1/conditions_const.go +++ b/api/v1alpha1/conditions_const.go @@ -39,7 +39,7 @@ const ( const ( // HelmChartFoundCondition reports when mentioned helm chart is present in the cluster addon tar archive. - HelmChartFoundCondition = "HelmChartFound" + HelmChartFoundCondition clusterv1.ConditionType = "HelmChartFound" // HelmChartMissingReason is used when mentioned helm chart is missing in the cluster addon tar archive. HelmChartMissingReason = "HelmChartMissing" @@ -62,6 +62,14 @@ const ( TemplateNewClusterStackFailedReason = "TemplateNewClusterStackFailed" ) +const ( + // ClusterAddonConfigValidatedCondition reports when there is a error parsing clusteraddon.yaml. + ClusterAddonConfigValidatedCondition clusterv1.ConditionType = "ClusterAddonConfigValidated" + + // ParsingClusterAddonConfigFailedReason is used when there's some error happen while parsing clusteraddon.yaml. + ParsingClusterAddonConfigFailedReason = "ParsingClusterAddonConfigFailed" +) + const ( // HelmChartAppliedCondition reports on whether the relevant helm chart has been applied. HelmChartAppliedCondition clusterv1.ConditionType = "HelmChartApplied" @@ -91,7 +99,7 @@ const ( const ( // ProviderClusterStackReleasesSyncedCondition reports on whether the ProviderClusterStackReleases are ready. - ProviderClusterStackReleasesSyncedCondition = "ProviderClusterStackReleasesSynced" + ProviderClusterStackReleasesSyncedCondition clusterv1.ConditionType = "ProviderClusterStackReleasesSynced" // ProviderTemplateNotFoundReason is used when providerTemplate is not found. ProviderTemplateNotFoundReason = "ProviderTemplateNotFound" @@ -102,7 +110,7 @@ const ( const ( // ClusterStackReleasesSyncedCondition reports on whether the ClusterStackReleases are ready. - ClusterStackReleasesSyncedCondition = "ClusterStackReleasesSynced" //#nosec + ClusterStackReleasesSyncedCondition clusterv1.ConditionType = "ClusterStackReleasesSynced" //#nosec ) const ( diff --git a/internal/controller/clusteraddon_controller.go b/internal/controller/clusteraddon_controller.go index 307e231b..23aaf7d4 100644 --- a/internal/controller/clusteraddon_controller.go +++ b/internal/controller/clusteraddon_controller.go @@ -298,8 +298,23 @@ func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Re // multi-stage cluster addon flow in.addonStagesInput, err = r.getAddonStagesInput(in.restConfig, in.clusterAddonChartPath) if err != nil { - return reconcile.Result{}, fmt.Errorf("failed to get addon stages input: %w", err) + conditions.MarkFalse( + clusterAddon, + csov1alpha1.ClusterAddonConfigValidatedCondition, + csov1alpha1.ParsingClusterAddonConfigFailedReason, + clusterv1.ConditionSeverityError, + "cluster addon config (clusteraddon.yaml) is wrong: %s", err.Error(), + ) + + record.Warnf( + clusterAddon, + csov1alpha1.ParsingClusterAddonConfigFailedReason, + "cluster addon config (clusteraddon.yaml) is wrong: %s", err.Error(), + ) + + return reconcile.Result{}, nil } + conditions.MarkTrue(clusterAddon, csov1alpha1.ClusterAddonConfigValidatedCondition) // clusteraddon.yaml in the release. clusterAddonConfig, err := clusteraddon.ParseConfig(in.clusterAddonConfigPath)