Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for existing ingress when appending to status #89

Merged
merged 4 commits into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading