From f0173f0822142f2a4e6817101c2a38ea70ac0417 Mon Sep 17 00:00:00 2001 From: Kevin Pullin Date: Tue, 1 Jan 2019 20:35:17 -0800 Subject: [PATCH 1/2] 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 ff8a3b7d71..fd297a1ee0 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 46725b5c72..85c77b44b1 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 c70a5526fd..14f1dfd24e 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 From f005d4c3ec03ef7a6d5614d5d83eb0e7ebee53d4 Mon Sep 17 00:00:00 2001 From: Kevin Pullin Date: Wed, 2 Jan 2019 09:32:57 -0800 Subject: [PATCH 2/2] L4 config - Only send `Service.Spec` instead of entire `Service`. --- internal/ingress/controller/nginx.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/ingress/controller/nginx.go b/internal/ingress/controller/nginx.go index 85c77b44b1..b549102d3e 100644 --- a/internal/ingress/controller/nginx.go +++ b/internal/ingress/controller/nginx.go @@ -816,21 +816,31 @@ func configureDynamically(pcfg *ingress.Configuration, port int, isDynamicCertif streams := make([]ingress.Backend, 0) for _, ep := range pcfg.TCPEndpoints { + var service *apiv1.Service + if ep.Service != nil { + service = &apiv1.Service{Spec: ep.Service.Spec} + } + key := fmt.Sprintf("tcp-%v-%v-%v", ep.Backend.Namespace, ep.Backend.Name, ep.Backend.Port.String()) streams = append(streams, ingress.Backend{ Name: key, Endpoints: ep.Endpoints, Port: intstr.FromInt(ep.Port), - Service: ep.Service, + Service: service, }) } for _, ep := range pcfg.UDPEndpoints { + var service *apiv1.Service + if ep.Service != nil { + service = &apiv1.Service{Spec: ep.Service.Spec} + } + key := fmt.Sprintf("udp-%v-%v-%v", ep.Backend.Namespace, ep.Backend.Name, ep.Backend.Port.String()) streams = append(streams, ingress.Backend{ Name: key, Endpoints: ep.Endpoints, Port: intstr.FromInt(ep.Port), - Service: ep.Service, + Service: service, }) }