Skip to content

Commit

Permalink
undo ENABLE_WEBHOOKS changes, and remove unnecessary× backoff logic
Browse files Browse the repository at this point in the history
  • Loading branch information
OrNovo committed Feb 24, 2025
1 parent 7f860d7 commit 5945019
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 50 deletions.
1 change: 1 addition & 0 deletions charts/coralogix-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ spec:
- -metrics-bind-address=:8080
- -leader-elect
- -prometheus-rule-controller={{.Values.coralogixOperator.prometheusRules.enabled}}
- -enable-webhooks={{.Values.coralogixOperator.webhooks.enabled }}
- -label-selector={{ .Values.coralogixOperator.labelSelector }}
env:
- name: CORALOGIX_REGION
Expand Down
71 changes: 42 additions & 29 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ func main() {
labelSelector := os.Getenv("LABEL_SELECTOR")
flag.StringVar(&labelSelector, "label-selector", labelSelector, "A comma-separated list of key=value labels to filter custom resources.")

enableWebhooks := os.Getenv("ENABLE_WEBHOOKS")
flag.StringVar(&enableWebhooks, "enable-webhooks", enableWebhooks, "Enable webhooks for the operator. Default is true.")
enableWebhooks = strings.ToLower(enableWebhooks)

var prometheusRuleController bool
flag.BoolVar(&prometheusRuleController, "prometheus-rule-controller", true, "Determine if the prometheus rule controller should be started. Default is true.")

Expand Down Expand Up @@ -204,9 +208,13 @@ func main() {
LeaderElection: enableLeaderElection,
LeaderElectionID: "9e1892e3.coralogix",
PprofBindAddress: "0.0.0.0:8888",
WebhookServer: webhook.NewServer(webhook.Options{
}

// Check if webhooks are enabled before setting up the webhook server
if enableWebhooks != "false" {
mgrOpts.WebhookServer = webhook.NewServer(webhook.Options{
TLSOpts: tlsOpts,
}),
})
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), mgrOpts)
Expand Down Expand Up @@ -321,45 +329,50 @@ func main() {
}
}

if err = webhookcoralogixv1alpha1.SetupOutboundWebhookWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "OutboundWebhook")
os.Exit(1)
}
if enableWebhooks != "false" {
if err = webhookcoralogixv1alpha1.SetupOutboundWebhookWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "OutboundWebhook")
os.Exit(1)
}

if err = webhookcoralogixv1alpha1.SetupRuleGroupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "RuleGroup")
os.Exit(1)
}
if err = webhookcoralogixv1alpha1.SetupRuleGroupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "RuleGroup")
os.Exit(1)
}

if err = webhookcoralogixv1alpha1.SetupApiKeyWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "ApiKey")
os.Exit(1)
}
if err = webhookcoralogixv1alpha1.SetupApiKeyWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "ApiKey")
os.Exit(1)
}

if err = webhookcoralogixv1beta1.SetupAlertWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Alert")
os.Exit(1)
}
if err = webhookcoralogixv1alpha1.SetupConnectorWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Connector")
os.Exit(1)
}
if err = webhookcoralogixv1alpha1.SetupPresetWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Preset")
os.Exit(1)
if err = webhookcoralogixv1beta1.SetupAlertWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Alert")
os.Exit(1)
}
if err = webhookcoralogixv1alpha1.SetupConnectorWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Connector")
os.Exit(1)
}
if err = webhookcoralogixv1alpha1.SetupPresetWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Preset")
os.Exit(1)
}
} else {
setupLog.Info("Webhooks are disabled")
}

//+kubebuilder:scaffold:builder

if err = mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
}
if err = mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}
if err = monitoring.SetupMetrics(); err != nil {

if err := monitoring.SetupMetrics(); err != nil {
setupLog.Error(err, "unable to set up metrics")
os.Exit(1)
}
Expand All @@ -371,7 +384,7 @@ func main() {
)

setupLog.Info("starting manager")
if err = mgr.Start(ctrl.SetupSignalHandler()); err != nil {
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
Expand Down
1 change: 1 addition & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ spec:
- --region=${CORALOGIX_REGION}
- --domain=${CORALOGIX_DOMAIN}
- --label-selector=${LABEL_SELECTOR}
- --enable-webhooks=${ENABLE_WEBHOOKS}
name: manager
image: controller
imagePullPolicy: IfNotPresent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ package coralogixreconciler
import (
"context"
"fmt"
"math"
"time"

"github.com/go-logr/logr"
"google.golang.org/grpc/codes"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -182,33 +179,17 @@ func RemoveFinalizer(ctx context.Context, log logr.Logger, obj client.Object, r
}

func ManageErrorWithRequeue(ctx context.Context, log logr.Logger, obj client.Object, reason string, err error) (reconcile.Result, error) {
requeueAfter := utils.DefaultErrRequeuePeriod
if conditionsObj, ok := (obj).(utils.ConditionsObj); ok {
// if the error condition is already set, we increase the requeue period
conditions := conditionsObj.GetConditions()
requeueAfter = calculateErrorRequeuePeriod(conditions)

utils.SetErrorConditionTrue(&conditions, (obj).GetGeneration(), reason, err.Error())
conditionsObj.SetConditions(conditions)
if err2 := k8sClient.Status().Update(ctx, obj); err2 != nil {
log.Error(err2, "unable to update status")
return reconcile.Result{RequeueAfter: requeueAfter}, err2
return reconcile.Result{}, err2
}
}

return reconcile.Result{RequeueAfter: requeueAfter}, err
}

func calculateErrorRequeuePeriod(conditions []metav1.Condition) time.Duration {
if errCondition := meta.FindStatusCondition(conditions, utils.ConditionTypeError); errCondition != nil && errCondition.Status == metav1.ConditionTrue {
lastRequeuePeriod := metav1.Now().Sub(errCondition.LastTransitionTime.Time).Round(time.Second)
return time.Duration(
math.Max(float64(utils.MinErrRequeuePeriod),
math.Min(float64(utils.MaxErrRequeuePeriod), float64(lastRequeuePeriod.Nanoseconds()*2)),
),
)
}
return utils.MinErrRequeuePeriod
return reconcile.Result{}, err
}

func ManageSuccessWithRequeue(ctx context.Context, log logr.Logger, obj client.Object, reason string) (reconcile.Result, error) {
Expand Down

0 comments on commit 5945019

Please sign in to comment.