Skip to content

Commit

Permalink
fix(expose): still support non-name port services that have no endpoi…
Browse files Browse the repository at this point in the history
…nts (#69)

Signed-off-by: Jared Allard <jaredallard@hey.com>
  • Loading branch information
jaredallard authored Feb 3, 2021
1 parent cd12873 commit 29c4c49
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions internal/kube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 29c4c49

Please sign in to comment.