From f0173f0822142f2a4e6817101c2a38ea70ac0417 Mon Sep 17 00:00:00 2001 From: Kevin Pullin Date: Tue, 1 Jan 2019 20:35:17 -0800 Subject: [PATCH] Pass k8s `Service` data through to the TCP balancer script. Fixes broken L4 ExternalName services. Details --------- The `tcp_udp_balancer.lua` script checks if the property `backend.service.spec["type"]` equals "ExternalName". If so, the script does a DNS lookup on the name in order to configure the backend configuration. However, before this commit, the k8s `Service` data was _not_ set on the `Backend` struct passed into the `tcp_udp_balancer.lua` script and therefore the ExternalName check always returned false. This commit fixes the issue by setting the `Service` field on the `Backend` struct. This also requires adding a new field to the `L4Backend` struct first, so that it's available to set on the `Backend`. --- internal/ingress/controller/controller.go | 1 + internal/ingress/controller/nginx.go | 2 ++ internal/ingress/types.go | 2 ++ 3 files changed, 5 insertions(+) diff --git a/internal/ingress/controller/controller.go b/internal/ingress/controller/controller.go index ff8a3b7d7..fd297a1ee 100644 --- a/internal/ingress/controller/controller.go +++ b/internal/ingress/controller/controller.go @@ -343,6 +343,7 @@ func (n *NGINXController) getStreamServices(configmapName string, proto apiv1.Pr ProxyProtocol: svcProxyProtocol, }, Endpoints: endps, + Service: svc, }) } // Keep upstream order sorted to reduce unnecessary nginx config reloads. diff --git a/internal/ingress/controller/nginx.go b/internal/ingress/controller/nginx.go index 46725b5c7..85c77b44b 100644 --- a/internal/ingress/controller/nginx.go +++ b/internal/ingress/controller/nginx.go @@ -821,6 +821,7 @@ func configureDynamically(pcfg *ingress.Configuration, port int, isDynamicCertif Name: key, Endpoints: ep.Endpoints, Port: intstr.FromInt(ep.Port), + Service: ep.Service, }) } for _, ep := range pcfg.UDPEndpoints { @@ -829,6 +830,7 @@ func configureDynamically(pcfg *ingress.Configuration, port int, isDynamicCertif Name: key, Endpoints: ep.Endpoints, Port: intstr.FromInt(ep.Port), + Service: ep.Service, }) } diff --git a/internal/ingress/types.go b/internal/ingress/types.go index c70a5526f..14f1dfd24 100644 --- a/internal/ingress/types.go +++ b/internal/ingress/types.go @@ -322,6 +322,8 @@ type L4Service struct { Backend L4Backend `json:"backend"` // Endpoints active endpoints of the service Endpoints []Endpoint `json:"endpoints,omitempty"` + // k8s Service + Service *apiv1.Service `json:"service,omitempty"` } // L4Backend describes the kubernetes service behind L4 Ingress service