From a9e6820999a32c29e5fd2842ece6aedcfd842047 Mon Sep 17 00:00:00 2001 From: Somtochi Onyekwere Date: Wed, 17 Mar 2021 14:29:53 +0100 Subject: [PATCH 1/2] Record suspension metrics Signed-off-by: Somtochi Onyekwere --- controllers/helmrelease_controller.go | 22 ++++++++++++++++++++++ go.mod | 2 +- go.sum | 3 ++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/controllers/helmrelease_controller.go b/controllers/helmrelease_controller.go index 81c03a951..029a963a9 100644 --- a/controllers/helmrelease_controller.go +++ b/controllers/helmrelease_controller.go @@ -137,6 +137,9 @@ func (r *HelmReleaseReconciler) Reconcile(ctx context.Context, req ctrl.Request) return ctrl.Result{}, client.IgnoreNotFound(err) } + // record suspension metrics + defer r.recordSuspension(ctx, hr) + // Add our finalizer if it does not exist if !controllerutil.ContainsFinalizer(&hr, v2.HelmReleaseFinalizer) { controllerutil.AddFinalizer(&hr, v2.HelmReleaseFinalizer) @@ -731,6 +734,25 @@ func (r *HelmReleaseReconciler) event(ctx context.Context, hr v2.HelmRelease, re } } +func (r *HelmReleaseReconciler) recordSuspension(ctx context.Context, hr v2.HelmRelease) { + if r.MetricsRecorder == nil { + return + } + log := logr.FromContext(ctx) + + objRef, err := reference.GetReference(r.Scheme, &hr) + if err != nil { + log.Error(err, "unable to record suspended metric") + return + } + + if !hr.DeletionTimestamp.IsZero() { + r.MetricsRecorder.RecordSuspend(*objRef, false) + } else { + r.MetricsRecorder.RecordSuspend(*objRef, hr.Spec.Suspend) + } +} + func (r *HelmReleaseReconciler) recordReadiness(ctx context.Context, hr v2.HelmRelease) { if r.MetricsRecorder == nil { return diff --git a/go.mod b/go.mod index 10a2f61d2..2f8101603 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/fluxcd/helm-controller/api v0.8.2 github.com/fluxcd/pkg/apis/kustomize v0.0.1 github.com/fluxcd/pkg/apis/meta v0.8.0 - github.com/fluxcd/pkg/runtime v0.8.4 + github.com/fluxcd/pkg/runtime v0.8.5 github.com/fluxcd/source-controller/api v0.9.1 github.com/go-logr/logr v0.3.0 github.com/hashicorp/go-retryablehttp v0.6.8 diff --git a/go.sum b/go.sum index c1cf284b7..e317f825f 100644 --- a/go.sum +++ b/go.sum @@ -237,8 +237,9 @@ github.com/fluxcd/pkg/apis/kustomize v0.0.1 h1:TkA80R0GopRY27VJqzKyS6ifiKIAfwBd7 github.com/fluxcd/pkg/apis/kustomize v0.0.1/go.mod h1:JAFPfnRmcrAoG1gNiA8kmEXsnOBuDyZ/F5X4DAQcVV0= github.com/fluxcd/pkg/apis/meta v0.8.0 h1:wqWpUsxhKHB1ZztcvOz+vnyhdKW9cWmjFp8Vci/XOdk= github.com/fluxcd/pkg/apis/meta v0.8.0/go.mod h1:yHuY8kyGHYz22I0jQzqMMGCcHViuzC/WPdo9Gisk8Po= -github.com/fluxcd/pkg/runtime v0.8.4 h1:amuhfoHGCUfFCPXg3Zrcyy7f9J+fho+/+FbQDDyewko= github.com/fluxcd/pkg/runtime v0.8.4/go.mod h1:JD0eZIn5xkTeHHQUWXSqJPIh/ecO0d0qrUKbSVHnpnw= +github.com/fluxcd/pkg/runtime v0.8.5 h1:ynh8fszbLQ3QSisQBNOABEUTnvt+/QfCdaL6gOJQcoQ= +github.com/fluxcd/pkg/runtime v0.8.5/go.mod h1:JD0eZIn5xkTeHHQUWXSqJPIh/ecO0d0qrUKbSVHnpnw= github.com/fluxcd/source-controller/api v0.9.1 h1:kaL+tBflccsuj3NDESPPQyKXlZXlAgyNoT2nYY02JAE= github.com/fluxcd/source-controller/api v0.9.1/go.mod h1:Vuw+7UqEUUOdkKBfTUPHwaQgbn6LL2FwqPDx2UAk7NE= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= From e2c5dda4a55a7c6c4e7a691644e00a7fa9da5664 Mon Sep 17 00:00:00 2001 From: Somtochi Onyekwere Date: Wed, 17 Mar 2021 15:04:30 +0100 Subject: [PATCH 2/2] Update pkg/runtime Signed-off-by: Somtochi Onyekwere --- api/go.mod | 2 +- api/go.sum | 4 ++-- go.sum | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/api/go.mod b/api/go.mod index 4db83225d..f62652d06 100644 --- a/api/go.mod +++ b/api/go.mod @@ -5,7 +5,7 @@ go 1.15 require ( github.com/fluxcd/pkg/apis/kustomize v0.0.1 github.com/fluxcd/pkg/apis/meta v0.8.0 - github.com/fluxcd/pkg/runtime v0.8.4 + github.com/fluxcd/pkg/runtime v0.8.5 k8s.io/apiextensions-apiserver v0.20.2 k8s.io/apimachinery v0.20.2 sigs.k8s.io/controller-runtime v0.8.3 diff --git a/api/go.sum b/api/go.sum index 553b0e3a0..2b0ee6ee9 100644 --- a/api/go.sum +++ b/api/go.sum @@ -92,8 +92,8 @@ github.com/fluxcd/pkg/apis/kustomize v0.0.1 h1:TkA80R0GopRY27VJqzKyS6ifiKIAfwBd7 github.com/fluxcd/pkg/apis/kustomize v0.0.1/go.mod h1:JAFPfnRmcrAoG1gNiA8kmEXsnOBuDyZ/F5X4DAQcVV0= github.com/fluxcd/pkg/apis/meta v0.8.0 h1:wqWpUsxhKHB1ZztcvOz+vnyhdKW9cWmjFp8Vci/XOdk= github.com/fluxcd/pkg/apis/meta v0.8.0/go.mod h1:yHuY8kyGHYz22I0jQzqMMGCcHViuzC/WPdo9Gisk8Po= -github.com/fluxcd/pkg/runtime v0.8.4 h1:amuhfoHGCUfFCPXg3Zrcyy7f9J+fho+/+FbQDDyewko= -github.com/fluxcd/pkg/runtime v0.8.4/go.mod h1:JD0eZIn5xkTeHHQUWXSqJPIh/ecO0d0qrUKbSVHnpnw= +github.com/fluxcd/pkg/runtime v0.8.5 h1:ynh8fszbLQ3QSisQBNOABEUTnvt+/QfCdaL6gOJQcoQ= +github.com/fluxcd/pkg/runtime v0.8.5/go.mod h1:JD0eZIn5xkTeHHQUWXSqJPIh/ecO0d0qrUKbSVHnpnw= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= diff --git a/go.sum b/go.sum index e317f825f..ac61d3612 100644 --- a/go.sum +++ b/go.sum @@ -237,7 +237,6 @@ github.com/fluxcd/pkg/apis/kustomize v0.0.1 h1:TkA80R0GopRY27VJqzKyS6ifiKIAfwBd7 github.com/fluxcd/pkg/apis/kustomize v0.0.1/go.mod h1:JAFPfnRmcrAoG1gNiA8kmEXsnOBuDyZ/F5X4DAQcVV0= github.com/fluxcd/pkg/apis/meta v0.8.0 h1:wqWpUsxhKHB1ZztcvOz+vnyhdKW9cWmjFp8Vci/XOdk= github.com/fluxcd/pkg/apis/meta v0.8.0/go.mod h1:yHuY8kyGHYz22I0jQzqMMGCcHViuzC/WPdo9Gisk8Po= -github.com/fluxcd/pkg/runtime v0.8.4/go.mod h1:JD0eZIn5xkTeHHQUWXSqJPIh/ecO0d0qrUKbSVHnpnw= github.com/fluxcd/pkg/runtime v0.8.5 h1:ynh8fszbLQ3QSisQBNOABEUTnvt+/QfCdaL6gOJQcoQ= github.com/fluxcd/pkg/runtime v0.8.5/go.mod h1:JD0eZIn5xkTeHHQUWXSqJPIh/ecO0d0qrUKbSVHnpnw= github.com/fluxcd/source-controller/api v0.9.1 h1:kaL+tBflccsuj3NDESPPQyKXlZXlAgyNoT2nYY02JAE=