Skip to content

Commit

Permalink
feat(ingress): Respect uptime-robot.clevyr.com/enabled annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Apr 17, 2024
1 parent c8cfdae commit ed8d83c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions internal/controller/ingress_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controller
import (
"context"
"net/url"
"strconv"
"strings"

uptimerobotv1 "github.com/clevyr/uptime-robot-operator/api/v1"
Expand Down Expand Up @@ -87,9 +88,17 @@ func (r *IngressReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
return ctrl.Result{}, nil
}

annotationCount := r.countMatchingAnnotations(ingress)
annotations := r.getMatchingAnnotations(ingress)

var enabled bool
if val, ok := annotations["enabled"]; ok {
if enabled, err = strconv.ParseBool(val); err != nil {
return ctrl.Result{}, err
}
}

var create bool
if annotationCount == 0 {
if !enabled {
if controllerutil.ContainsFinalizer(ingress, myFinalizerName) {
// Delete existing Monitor
for _, monitor := range list.Items {
Expand Down Expand Up @@ -121,7 +130,6 @@ func (r *IngressReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
})
}

annotations := r.getMatchingAnnotations(ingress)
for _, monitor := range list.Items {
if err := r.updateValues(ingress, &monitor, annotations); err != nil {
return ctrl.Result{}, err
Expand Down Expand Up @@ -178,7 +186,12 @@ func (r *IngressReconciler) countMatchingAnnotations(ingress *networkingv1.Ingre
}

func (r *IngressReconciler) getMatchingAnnotations(ingress *networkingv1.Ingress) map[string]string {
annotations := make(map[string]string, r.countMatchingAnnotations(ingress))
count := r.countMatchingAnnotations(ingress)
if count == 0 {
return nil
}

annotations := make(map[string]string, count)
for k, v := range ingress.Annotations {
if strings.HasPrefix(k, IngressAnnotationPrefix) {
annotations[strings.TrimPrefix(k, IngressAnnotationPrefix)] = v
Expand Down

0 comments on commit ed8d83c

Please sign in to comment.