From 29c4c495e81241e3c8cac43122fe9119207def59 Mon Sep 17 00:00:00 2001 From: Jared Allard Date: Tue, 2 Feb 2021 18:13:55 -0800 Subject: [PATCH] fix(expose): still support non-name port services that have no endpoints (#69) Signed-off-by: Jared Allard --- internal/kube/client.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/internal/kube/client.go b/internal/kube/client.go index b8d693a..3526fb9 100644 --- a/internal/kube/client.go +++ b/internal/kube/client.go @@ -99,6 +99,27 @@ type ResolvedServicePort struct { func ResolveServicePorts(log logrus.FieldLogger, s *corev1.Service) ([]ResolvedServicePort, error) { store := kevents.GlobalCache.Core().V1().Endpoints().Informer().GetStore() + hasNamedPorts := false + for _, p := range s.Spec.Ports { + if p.TargetPort.Type == intstr.String { + hasNamedPorts = true + break + } + } + + // Don't try to resolve anything if we don't have named ports + if !hasNamedPorts { + servicePorts := make([]ResolvedServicePort, len(s.Spec.Ports)) + for i, sp := range s.Spec.Ports { + servicePorts[i] = ResolvedServicePort{ + sp, + "", + uint(sp.Port), + } + } + return servicePorts, nil + } + obj, _, err := store.GetByKey(s.Namespace + "/" + s.Name) e, ok := obj.(*corev1.Endpoints) if !ok || len(e.Subsets) == 0 || err != nil {