Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2321 from StrongMonkey/generate-endpoints
Browse files Browse the repository at this point in the history
Deduplicate endpoints for ingress that has port defined
  • Loading branch information
StrongMonkey committed Nov 7, 2023
2 parents 1849371 + 62be11b commit c337c56
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions pkg/controller/appstatus/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func serviceEndpoints(ctx context.Context, c kclient.Client, app *v1.AppInstance
return nil, err
}

endpointSet := map[string]v1.Endpoint{}
for _, service := range serviceList.Items {
containerName := service.Labels[labels.AcornContainerName]
if containerName == "" {
Expand All @@ -53,44 +54,57 @@ func serviceEndpoints(ctx context.Context, c kclient.Client, app *v1.AppInstance
portNum := port.Port
if len(ingress.Ports) > 0 {
for _, ingressPort := range ingress.Ports {
endpoints = append(endpoints, v1.Endpoint{
portProtocol := port.Protocol
if ingressPort.Protocol != "" {
portProtocol = ingressPort.Protocol
}
ep := v1.Endpoint{
Target: containerName,
TargetPort: port.TargetPort.IntVal,
Address: fmt.Sprintf("%s:%d", ingress.Hostname, ingressPort.Port),
Protocol: protocol,
})
Protocol: v1.Protocol(portProtocol),
}
endpointSet[endpointKey(ep)] = ep
}
} else {
endpoints = append(endpoints, v1.Endpoint{
ep := v1.Endpoint{
Target: containerName,
TargetPort: port.TargetPort.IntVal,
Address: fmt.Sprintf("%s:%d", ingress.Hostname, portNum),
Protocol: protocol,
})
}
endpointSet[endpointKey(ep)] = ep
}
} else if ingress.IP != "" {
endpoints = append(endpoints, v1.Endpoint{
ep := v1.Endpoint{
Target: containerName,
TargetPort: port.TargetPort.IntVal,
Address: fmt.Sprintf("%s:%d", ingress.IP, port.Port),
Protocol: protocol,
})
}
endpointSet[endpointKey(ep)] = ep
}
}

if len(service.Status.LoadBalancer.Ingress) == 0 {
endpoints = append(endpoints, v1.Endpoint{
ep := v1.Endpoint{
Target: containerName,
TargetPort: port.TargetPort.IntVal,
Address: fmt.Sprintf("<Pending Ingress>:%d", port.Port),
Protocol: protocol,
Pending: true,
})
}
endpointSet[endpointKey(ep)] = ep
}
}
}

return
result := make([]v1.Endpoint, 0, len(endpointSet))
for _, ep := range endpointSet {
result = append(result, ep)
}

return result, nil
}

func ingressEndpoints(ctx context.Context, c kclient.Client, app *v1.AppInstance) (endpoints []v1.Endpoint, _ error) {
Expand Down Expand Up @@ -204,3 +218,7 @@ func ingressTLSHosts(ctx context.Context, client kclient.Client, app *v1.AppInst

return ingressTLSHosts, nil
}

func endpointKey(ep v1.Endpoint) string {
return fmt.Sprintf("%v://%v", ep.Protocol, ep.Address)
}

0 comments on commit c337c56

Please sign in to comment.