From c03a137098879decb0e78c3e95796c72a32c397a Mon Sep 17 00:00:00 2001 From: Adam Lehechka <42357034+alehechka@users.noreply.github.com> Date: Sat, 29 Jul 2023 11:31:01 -0500 Subject: [PATCH] Fix broken IngressRoute no-TLS replication (#23) shortcircuit if TLS is nil --- .../traefik/ingressroute/ingressroutes.go | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/client/replicate/traefik/ingressroute/ingressroutes.go b/client/replicate/traefik/ingressroute/ingressroutes.go index bb24d6b..8001716 100644 --- a/client/replicate/traefik/ingressroute/ingressroutes.go +++ b/client/replicate/traefik/ingressroute/ingressroutes.go @@ -162,39 +162,37 @@ func (r *Replicator) prepareRoutes(namespace string, source *v1alpha1.IngressRou } func (r *Replicator) prepareTLS(namespace string, source *v1alpha1.IngressRoute) *v1alpha1.TLS { + if source.Spec.TLS == nil { + return nil + } + annotations := source.GetAnnotations() + tls := &v1alpha1.TLS{ + SecretName: annotations[common.TLDSecretName], + Options: source.Spec.TLS.Options, + Store: source.Spec.TLS.Store, + CertResolver: source.Spec.TLS.CertResolver, + } + if tld, ok := annotations[common.TopLevelDomain]; ok { - return &v1alpha1.TLS{ - SecretName: annotations[common.TLDSecretName], - Options: source.Spec.TLS.Options, - Store: source.Spec.TLS.Store, - CertResolver: source.Spec.TLS.CertResolver, - Domains: []types.Domain{{ - Main: common.PrepareTLD(namespace, tld), - }}, - } + tls.Domains = []types.Domain{{ + Main: common.PrepareTLD(namespace, tld), + }} + + return tls } if r.HasDefaultIngressHostname() { - return &v1alpha1.TLS{ - SecretName: annotations[common.TLDSecretName], - Options: source.Spec.TLS.Options, - Store: source.Spec.TLS.Store, - CertResolver: source.Spec.TLS.CertResolver, - Domains: []types.Domain{{ - Main: common.PrepareTLD(namespace, r.DefaultIngressHostname), - }}, - } - } + tls.Domains = []types.Domain{{ + Main: common.PrepareTLD(namespace, r.DefaultIngressHostname), + }} - return &v1alpha1.TLS{ - SecretName: source.Spec.TLS.SecretName, - Options: source.Spec.TLS.Options, - Store: source.Spec.TLS.Store, - CertResolver: source.Spec.TLS.CertResolver, - Domains: prepareDomains(namespace, source), + return tls } + + tls.Domains = prepareDomains(namespace, source) + return tls } func prepareDomains(namespace string, source *v1alpha1.IngressRoute) (domains []types.Domain) {