refactor: simplify assignment to Service target list

This commit is contained in:
John Gardiner Myers 2023-06-25 12:39:27 -07:00
parent 4ee8bae85c
commit 039f1a91fb

View File

@ -498,16 +498,15 @@ func (sc *serviceSource) generateEndpoints(svc *v1.Service, hostname string, pro
switch svc.Spec.Type { switch svc.Spec.Type {
case v1.ServiceTypeLoadBalancer: case v1.ServiceTypeLoadBalancer:
if useClusterIP { if useClusterIP {
targets = append(targets, extractServiceIps(svc)...) targets = extractServiceIps(svc)
} else { } else {
targets = append(targets, extractLoadBalancerTargets(svc, sc.resolveLoadBalancerHostname)...) targets = extractLoadBalancerTargets(svc, sc.resolveLoadBalancerHostname)
} }
case v1.ServiceTypeClusterIP: case v1.ServiceTypeClusterIP:
if sc.publishInternal {
targets = append(targets, extractServiceIps(svc)...)
}
if svc.Spec.ClusterIP == v1.ClusterIPNone { if svc.Spec.ClusterIP == v1.ClusterIPNone {
endpoints = append(endpoints, sc.extractHeadlessEndpoints(svc, hostname, ttl)...) endpoints = append(endpoints, sc.extractHeadlessEndpoints(svc, hostname, ttl)...)
} else if sc.publishInternal {
targets = extractServiceIps(svc)
} }
case v1.ServiceTypeNodePort: case v1.ServiceTypeNodePort:
// add the nodeTargets and extract an SRV endpoint // add the nodeTargets and extract an SRV endpoint
@ -518,7 +517,7 @@ func (sc *serviceSource) generateEndpoints(svc *v1.Service, hostname string, pro
} }
endpoints = append(endpoints, sc.extractNodePortEndpoints(svc, hostname, ttl)...) endpoints = append(endpoints, sc.extractNodePortEndpoints(svc, hostname, ttl)...)
case v1.ServiceTypeExternalName: case v1.ServiceTypeExternalName:
targets = append(targets, extractServiceExternalName(svc)...) targets = extractServiceExternalName(svc)
} }
} }