From d761dbe83403c82f9fc57b001cf3771193c8347f Mon Sep 17 00:00:00 2001 From: Nicolas Takashi Date: Mon, 26 Aug 2024 17:00:34 +0100 Subject: [PATCH] [CHORE] enforcing default value instead of block cr onboarding (#136) Signed-off-by: Nicolas Takashi --- .../v1alpha1/recordingrulegroupset_types.go | 1 - .../bases/coralogix.com_recordingrulegroupsets.yaml | 1 - controllers/prometheusrule_controller.go | 13 +++++++++++-- docs/api.md | 11 +++++------ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/apis/coralogix/v1alpha1/recordingrulegroupset_types.go b/apis/coralogix/v1alpha1/recordingrulegroupset_types.go index 40ef575..dce7a6a 100644 --- a/apis/coralogix/v1alpha1/recordingrulegroupset_types.go +++ b/apis/coralogix/v1alpha1/recordingrulegroupset_types.go @@ -187,7 +187,6 @@ type RecordingRuleGroup struct { Name string `json:"name,omitempty"` //+kubebuilder:default=60 - // +kubebuilder:validation:Minimum=60 IntervalSeconds int32 `json:"intervalSeconds,omitempty"` // +optional diff --git a/config/crd/bases/coralogix.com_recordingrulegroupsets.yaml b/config/crd/bases/coralogix.com_recordingrulegroupsets.yaml index 8325b22..4c87274 100644 --- a/config/crd/bases/coralogix.com_recordingrulegroupsets.yaml +++ b/config/crd/bases/coralogix.com_recordingrulegroupsets.yaml @@ -42,7 +42,6 @@ spec: intervalSeconds: default: 60 format: int32 - minimum: 60 type: integer limit: format: int64 diff --git a/controllers/prometheusrule_controller.go b/controllers/prometheusrule_controller.go index d1f7e02..662182d 100644 --- a/controllers/prometheusrule_controller.go +++ b/controllers/prometheusrule_controller.go @@ -246,9 +246,18 @@ func prometheusRuleToRecordingRuleToRuleGroupSet(log logr.Logger, prometheusRule if group.Interval != "" { duration, err := time.ParseDuration(string(group.Interval)) if err != nil { - log.V(int(zapcore.WarnLevel)).Info("failed to parse interval duration", "interval", group.Interval, "error", err, "using default interval") + log.V(int(zapcore.WarnLevel)).Info("Failed to parse interval duration", "interval", group.Interval, "error", err, "using default interval") + } + + // Convert duration to seconds + durationSeconds := int32(duration.Seconds()) + + if durationSeconds < interval { + log.V(int(zapcore.WarnLevel)).Info("Recording rule interval is lower than the default interval", "interval", durationSeconds, "default interval", interval, "using the greater interval") + } else { + // Update interval if parsed duration is greater + interval = durationSeconds } - interval = int32(duration.Seconds()) } if rules := prometheusInnerRulesToCoralogixInnerRules(group.Rules); len(rules) > 0 { diff --git a/docs/api.md b/docs/api.md index 6309bdc..c777cbd 100644 --- a/docs/api.md +++ b/docs/api.md @@ -51,7 +51,7 @@ Alert is the Schema for the alerts API true - metadata + metadata object Refer to the Kubernetes API documentation for the fields of the `metadata` field. true @@ -4623,7 +4623,7 @@ OutboundWebhook is the Schema for the outboundwebhooks API true - metadata + metadata object Refer to the Kubernetes API documentation for the fields of the `metadata` field. true @@ -5842,7 +5842,7 @@ RecordingRuleGroupSet is the Schema for the recordingrulegroupsets API true - metadata + metadata object Refer to the Kubernetes API documentation for the fields of the `metadata` field. true @@ -5915,7 +5915,6 @@ RecordingRuleGroupSetSpec defines the desired state of RecordingRuleGroupSet
Format: int32
Default: 60
- Minimum: 60
false @@ -6146,7 +6145,7 @@ RuleGroup is the Schema for the rulegroups API true - metadata + metadata object Refer to the Kubernetes API documentation for the fields of the `metadata` field. true @@ -7421,4 +7420,4 @@ RuleGroupStatus defines the observed state of RuleGroup true - \ No newline at end of file +