diff --git a/pkg/controllers/plugin/helm_controller.go b/pkg/controllers/plugin/helm_controller.go index a0a4aeaf1..539189102 100644 --- a/pkg/controllers/plugin/helm_controller.go +++ b/pkg/controllers/plugin/helm_controller.go @@ -256,11 +256,11 @@ func (r *HelmReconciler) reconcileHelmRelease( if err := helm.InstallOrUpgradeHelmChartFromPlugin(ctx, r.Client, restClientGetter, pluginDefinition, plugin); err != nil { reconcileFailedCondition.Status = metav1.ConditionTrue reconcileFailedCondition.Message = "Helm install/upgrade failed: " + err.Error() - metrics.UpdateMetrics(plugin, metrics.MetricResultError, metrics.MetricReasonUninstallHelmFailed) return driftDetectedCondition, reconcileFailedCondition } reconcileFailedCondition.Status = metav1.ConditionFalse reconcileFailedCondition.Message = "Helm install/upgrade successful" + metrics.UpdateMetrics(plugin, metrics.MetricResultSuccess, metrics.MetricReasonEmpty) return driftDetectedCondition, reconcileFailedCondition } diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go index 11b79aeab..9cbb7fdfa 100644 --- a/pkg/helm/helm.go +++ b/pkg/helm/helm.go @@ -56,6 +56,7 @@ const driftDetectionInterval = 60 * time.Minute func InstallOrUpgradeHelmChartFromPlugin(ctx context.Context, local client.Client, restClientGetter genericclioptions.RESTClientGetter, pluginDefinition *greenhousev1alpha1.PluginDefinition, plugin *greenhousev1alpha1.Plugin) error { // Early return if the pluginDefinition is not helm based if pluginDefinition.Spec.HelmChart == nil { + metrics.UpdateMetrics(plugin, metrics.MetricResultError, metrics.MetricReasonHelmChartIsNotDefined) return fmt.Errorf("no helm chart defined in pluginDefinition.Spec.HelmChart for pluginDefinition %s", plugin.Spec.PluginDefinition) } latestRelease, isReleaseExists, err := isReleaseExistsForPlugin(ctx, restClientGetter, plugin) @@ -71,27 +72,32 @@ func InstallOrUpgradeHelmChartFromPlugin(ctx context.Context, local client.Clien } helmChart, err := locateChartForPlugin(restClientGetter, pluginDefinition) if err != nil { + metrics.UpdateMetrics(plugin, metrics.MetricResultError, metrics.MetricReasonUpgradeFailed) return err } // Avoid attempts to upgrade a failed release and attempt to resurrect it. if latestRelease.Info != nil && latestRelease.Info.Status == release.StatusFailed { log.FromContext(ctx).Info("attempting to reset release status", "current status", latestRelease.Info.Status.String()) if err := ResetHelmReleaseStatusToDeployed(ctx, restClientGetter, plugin); err != nil { + metrics.UpdateMetrics(plugin, metrics.MetricResultError, metrics.MetricReasonUpgradeFailed) return err } } // Avoid upgrading a currently pending release. if releaseStatus, ok := isCanReleaseBeUpgraded(latestRelease); !ok { + metrics.UpdateMetrics(plugin, metrics.MetricResultError, metrics.MetricReasonUpgradeFailed) return fmt.Errorf("cannot upgrade release %s/%s in status %s", latestRelease.Namespace, latestRelease.Name, releaseStatus.String()) } log.FromContext(ctx).Info("upgrading release", "namespace", plugin.Spec.ReleaseNamespace, "name", plugin.Name) c, err := clientutil.NewK8sClientFromRestClientGetter(restClientGetter) if err != nil { + metrics.UpdateMetrics(plugin, metrics.MetricResultError, metrics.MetricReasonUpgradeFailed) return err } if err := replaceCustomResourceDefinitions(ctx, c, helmChart.CRDObjects(), true); err != nil { + metrics.UpdateMetrics(plugin, metrics.MetricResultError, metrics.MetricReasonUpgradeFailed) return err } diff --git a/pkg/metrics/plugin_metrics.go b/pkg/metrics/plugin_metrics.go index 2ae4ee2cc..f5bab89cb 100644 --- a/pkg/metrics/plugin_metrics.go +++ b/pkg/metrics/plugin_metrics.go @@ -27,6 +27,7 @@ const ( MetricReasonPluginDefinitionNotFound MetricReason = "plugin_definition_not_found" MetricReasonTemplateFailed MetricReason = "template_failed" MetricReasonDiffFailed MetricReason = "diff_failed" + MetricReasonHelmChartIsNotDefined MetricReason = "helm_chart_is_not_defined" ) var (