From 95feab762f7e2d14631b7017e9964609ccc1cd3a Mon Sep 17 00:00:00 2001 From: Nicolas Takashi Date: Wed, 31 Jul 2024 15:14:14 +0100 Subject: [PATCH] [CHORE] adding recording rule group set suffix flag] (#125) Signed-off-by: Nicolas Takashi --- .../recordingrulegroupset_controller.go | 9 +++++---- main.go | 10 +++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/controllers/alphacontrollers/recordingrulegroupset_controller.go b/controllers/alphacontrollers/recordingrulegroupset_controller.go index c6a81fd..9e947bc 100644 --- a/controllers/alphacontrollers/recordingrulegroupset_controller.go +++ b/controllers/alphacontrollers/recordingrulegroupset_controller.go @@ -41,8 +41,9 @@ var recordingRuleGroupSetFinalizerName = "recordingrulegroupset.coralogix.com/fi // RecordingRuleGroupSetReconciler reconciles a RecordingRuleGroupSet object type RecordingRuleGroupSetReconciler struct { client.Client - CoralogixClientSet clientset.ClientSetInterface - Scheme *runtime.Scheme + CoralogixClientSet clientset.ClientSetInterface + Scheme *runtime.Scheme + RecordingRuleGroupSetSuffix string } //+kubebuilder:rbac:groups=coralogix.com,resources=recordingrulegroupsets,verbs=get;list;watch;create;update;patch;delete @@ -97,7 +98,7 @@ func (r *RecordingRuleGroupSetReconciler) create(ctx context.Context, recordingR response, err := r.CoralogixClientSet. RecordingRuleGroups(). CreateRecordingRuleGroupSet(ctx, &rrg.CreateRuleGroupSet{ - Name: ptr.To(recordingRuleGroupSet.Name), + Name: ptr.To(fmt.Sprintf("%s%s", recordingRuleGroupSet.Name, r.RecordingRuleGroupSetSuffix)), Groups: recordingRuleGroupSet.Spec.ExtractRecordingRuleGroups(), }) @@ -143,7 +144,7 @@ func (r *RecordingRuleGroupSetReconciler) update(ctx context.Context, recordingR UpdateRecordingRuleGroupSet(ctx, &rrg.UpdateRuleGroupSet{ Id: remoteRecordingRule.Id, Groups: recordingRuleGroupSet.Spec.ExtractRecordingRuleGroups(), - Name: ptr.To(recordingRuleGroupSet.Name), + Name: ptr.To(fmt.Sprintf("%s%s", recordingRuleGroupSet.Name, r.RecordingRuleGroupSetSuffix)), }); err != nil { return fmt.Errorf("failed to update recording rule groupSet: %w", err) } diff --git a/main.go b/main.go index c68fe92..fae2dd2 100644 --- a/main.go +++ b/main.go @@ -87,6 +87,9 @@ func main() { var prometheusRuleController bool flag.BoolVar(&prometheusRuleController, "prometheus-rule-controller", true, "Determine if the prometheus rule controller should be started. Default is true.") + var recordingRuleGroupSetSuffix string + flag.StringVar(&recordingRuleGroupSetSuffix, "recording-rule-group-set-suffix", "", "Suffix to be added to the RecordingRuleGroupSet") + opts := zap.Options{} opts.BindFlags(flag.CommandLine) flag.Parse() @@ -158,9 +161,10 @@ func main() { } } if err = (&alphacontrollers.RecordingRuleGroupSetReconciler{ - CoralogixClientSet: clientset.NewClientSet(targetUrl, apiKey), - Client: mgr.GetClient(), - Scheme: mgr.GetScheme(), + CoralogixClientSet: clientset.NewClientSet(targetUrl, apiKey), + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + RecordingRuleGroupSetSuffix: recordingRuleGroupSetSuffix, }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "RecordingRuleGroupSet") os.Exit(1)