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

Update Ingress.status.loadBalancer.ingress when reconciling #69

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
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
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(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original comment in #68 they mentioned using the cloudflare cname value, do you agree with this? Or should this use the ingress hostname?

Also, should https:// be appended to the beginning?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @UnstoppableMango , sorry for the late response.

we do not need https:// prefix.

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