Skip to content

Commit

Permalink
Update Ingress.status.loadBalancer.ingress when reconciling (#69)
Browse files Browse the repository at this point in the history
* Update service status when reconciling

* Addressing PR comments

Missed some stuff
  • Loading branch information
UnstoppableMango authored May 8, 2024
1 parent 43ea074 commit 8b4fb07
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions pkg/cloudflare-controller/tunnel-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func (t *TunnelClient) PutExposures(ctx context.Context, exposures []exposure.Ex
return nil
}

func (t *TunnelClient) TunnelDomain() string {
return tunnelDomain(t.tunnelId)
}

func (t *TunnelClient) updateTunnelIngressRules(ctx context.Context, exposures []exposure.Exposure) error {
var ingressRules []cloudflare.UnvalidatedIngressRule

Expand Down
17 changes: 15 additions & 2 deletions pkg/controller/ingress-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package controller
import (
"context"
"fmt"

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"
"github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -99,6 +99,19 @@ 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(),
Ports: []networkingv1.IngressPortStatus{{
Protocol: v1.ProtocolTCP,
Port: 443,
}},
},
)
if err = i.kubeClient.Status().Update(ctx, &origin); err != nil {
return reconcile.Result{}, errors.Wrapf(err, "failed to update ingress status")
}

i.logger.V(3).Info("reconcile completed", "triggered-by", request.NamespacedName)
return reconcile.Result{}, nil
}
Expand Down Expand Up @@ -135,7 +148,7 @@ func (i *IngressController) listControlledIngressClasses(ctx context.Context) ([
if err != nil {
return nil, errors.Wrap(err, "list ingress classes")
}

filteredList := make([]networkingv1.IngressClass, 0, len(list.Items))
for _, ingress := range list.Items {
if ingress.Spec.Controller != i.controllerClassName {
Expand Down
5 changes: 1 addition & 4 deletions pkg/controller/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func FromIngressToExposure(ctx context.Context, logger logr.Logger, kubeClient c
}

hostname := rule.Host

scheme := "http"

if backendProtocol, ok := getAnnotation(ingress.Annotations, AnnotationBackendProtocol); ok {
Expand Down Expand Up @@ -96,12 +95,10 @@ func FromIngressToExposure(ctx context.Context, logger logr.Logger, kubeClient c
return nil, errors.Errorf("path type in ingress %s/%s is %s, which is not supported", ingress.GetNamespace(), ingress.GetName(), *path.PathType)
}

pathPrefix := path.Path

result = append(result, exposure.Exposure{
Hostname: hostname,
ServiceTarget: fmt.Sprintf("%s://%s:%d", scheme, host, port),
PathPrefix: pathPrefix,
PathPrefix: path.Path,
IsDeleted: isDeleted,
ProxySSLVerifyEnabled: proxySSLVerifyEnabled,
})
Expand Down

0 comments on commit 8b4fb07

Please sign in to comment.