diff --git a/pkg/cloudflare-controller/tunnel-client.go b/pkg/cloudflare-controller/tunnel-client.go index 72abff3..df475a6 100644 --- a/pkg/cloudflare-controller/tunnel-client.go +++ b/pkg/cloudflare-controller/tunnel-client.go @@ -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 diff --git a/pkg/controller/ingress-controller.go b/pkg/controller/ingress-controller.go index 9180611..3b82107 100644 --- a/pkg/controller/ingress-controller.go +++ b/pkg/controller/ingress-controller.go @@ -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" @@ -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 } @@ -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 { diff --git a/pkg/controller/transform.go b/pkg/controller/transform.go index 3cc2ffa..a3f6500 100644 --- a/pkg/controller/transform.go +++ b/pkg/controller/transform.go @@ -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 { @@ -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, })