From 97e11fd028d20bc48fedd9da0c073ef708cc2956 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Fri, 28 Jun 2024 10:22:04 +0300 Subject: [PATCH] Add `REPORTING_INTERVAL` env var Signed-off-by: Stefan Prodan --- api/v1/fluxreport_types.go | 18 +++++++++++++++--- docs/api/v1/fluxreport.md | 5 ++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/api/v1/fluxreport_types.go b/api/v1/fluxreport_types.go index 7d127f6..0987dbf 100644 --- a/api/v1/fluxreport_types.go +++ b/api/v1/fluxreport_types.go @@ -4,6 +4,7 @@ package v1 import ( + "os" "strings" "time" @@ -11,7 +12,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -const FluxReportKind = "FluxReport" +const ( + FluxReportKind = "FluxReport" + ReportIntervalEvnKey = "REPORTING_INTERVAL" +) // FluxReportSpec defines the observed state of a Flux installation. type FluxReportSpec struct { @@ -188,13 +192,21 @@ func (in *FluxReport) IsDisabled() bool { } // GetInterval returns the interval at which the object should be reconciled. -// If no interval is set, the default is 10 minutes. +// If the annotation is not set, the interval is read from the +// REPORTING_INTERVAL environment variable. If the variable is not set, +// the default interval is 5 minutes. func (in *FluxReport) GetInterval() time.Duration { val, ok := in.GetAnnotations()[ReconcileAnnotation] if ok && strings.ToLower(val) == DisabledValue { return 0 } - defaultInterval := 10 * time.Minute + defaultInterval := 5 * time.Minute + if ri, _ := os.LookupEnv(ReportIntervalEvnKey); ri != "" { + if d, err := time.ParseDuration(ri); err != nil { + defaultInterval = d + } + } + val, ok = in.GetAnnotations()[ReconcileEveryAnnotation] if !ok { return defaultInterval diff --git a/docs/api/v1/fluxreport.md b/docs/api/v1/fluxreport.md index f615767..95cba8d 100644 --- a/docs/api/v1/fluxreport.md +++ b/docs/api/v1/fluxreport.md @@ -263,7 +263,10 @@ The FluxReport is automatically generated by the operator for the following cond The reconciliation behaviour can be configured using the following annotations: - `fluxcd.controlplane.io/reconcile`: Enable or disable the reconciliation loop. Default is `enabled`, set to `disabled` to pause the reconciliation. -- `fluxcd.controlplane.io/reconcileEvery`: Set the reconciliation interval. Default is `10m`. +- `fluxcd.controlplane.io/reconcileEvery`: Set the reconciliation interval. Default is `5m`. + +The default reconciliation interval of the report can be changed by setting +the `REPORTING_INTERVAL` environment variable in the operator deployment. ## Flux Resource Metrics