Skip to content

Commit

Permalink
Check for existing ingress when appending to status (#89)
Browse files Browse the repository at this point in the history
* Check for existing ingress when appending to status

* Dry

* Address PR feedback

* Deep copy the origin earlier
  • Loading branch information
UnstoppableMango authored Jun 3, 2024
1 parent 160ee74 commit f8d799d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pkg/controller/ingress-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package controller
import (
"context"
"fmt"
"slices"

cloudflarecontroller "github.com/STRRL/cloudflare-tunnel-ingress-controller/pkg/cloudflare-controller"
"github.com/STRRL/cloudflare-tunnel-ingress-controller/pkg/exposure"
"github.com/go-logr/logr"
Expand Down Expand Up @@ -99,16 +101,21 @@ func (i *IngressController) Reconcile(ctx context.Context, request reconcile.Req
}
}

origin.Status.LoadBalancer.Ingress = append(origin.Status.LoadBalancer.Ingress,
networkingv1.IngressLoadBalancerIngress{
Hostname: i.tunnelClient.TunnelDomain(),
hostname := i.tunnelClient.TunnelDomain()
newOrigin := origin.DeepCopy()
matchesHostname := func(ingress networkingv1.IngressLoadBalancerIngress) bool {
return ingress.Hostname == hostname
}
if !slices.ContainsFunc(origin.Status.LoadBalancer.Ingress, matchesHostname) {
newOrigin.Status.LoadBalancer.Ingress = []networkingv1.IngressLoadBalancerIngress{{
Hostname: hostname,
Ports: []networkingv1.IngressPortStatus{{
Protocol: v1.ProtocolTCP,
Port: 443,
}},
},
)
if err = i.kubeClient.Status().Update(ctx, &origin); err != nil {
}}
}
if err = i.kubeClient.Status().Update(ctx, newOrigin); err != nil {
return reconcile.Result{}, errors.Wrapf(err, "failed to update ingress status")
}

Expand Down

0 comments on commit f8d799d

Please sign in to comment.