in pkg/gateway/model_build_targets.go [173:208]
func (t *latticeTargetsModelBuildTask) getTargetListFromEndpoints(ctx context.Context, servicePortNames map[string]struct{}, skipMatch bool) ([]model.Target, error) {
epSlices := &discoveryv1.EndpointSliceList{}
if err := t.client.List(ctx, epSlices,
client.InNamespace(t.service.Namespace),
client.MatchingLabels{discoveryv1.LabelServiceName: t.service.Name}); err != nil {
return nil, err
}
var targetList []model.Target
for _, epSlice := range epSlices.Items {
for _, port := range epSlice.Ports {
// Note that the Endpoint's port name is from ServicePort, but the actual registered port
// is from Pods(targets).
if _, ok := servicePortNames[aws.StringValue(port.Name)]; ok || skipMatch {
for _, ep := range epSlice.Endpoints {
for _, address := range ep.Addresses {
// Do not model terminating endpoints so that they can deregister.
if aws.BoolValue(ep.Conditions.Terminating) {
continue
}
target := model.Target{
TargetIP: address,
Port: int64(aws.Int32Value(port.Port)),
Ready: aws.BoolValue(ep.Conditions.Ready),
}
if ep.TargetRef != nil && ep.TargetRef.Kind == "Pod" {
target.TargetRef = types.NamespacedName{Namespace: ep.TargetRef.Namespace, Name: ep.TargetRef.Name}
}
targetList = append(targetList, target)
}
}
}
}
}
return targetList, nil
}