Iryna Shustava 3c70e14713
sidecar-proxy controller: L4 controller with explicit upstreams (NET-3988) (#18352)
* This controller generates and saves ProxyStateTemplate for sidecar proxies.
* It currently supports single-port L4 ports only.
* It keeps a cache of all destinations to make it easier to compute and retrieve destinations.
* It will update the status of the pbmesh.Upstreams resource if anything is invalid.
* This commit also changes service endpoints to include workload identity. This made the implementation a bit easier as we don't need to look up as many workloads and instead rely on endpoints data.
2023-09-07 09:37:15 -06:00

41 lines
898 B
Go

package catalogv1alpha1
import "golang.org/x/exp/slices"
func (w *Workload) GetMeshPortName() (string, bool) {
var meshPort string
for portName, port := range w.Ports {
if port.Protocol == Protocol_PROTOCOL_MESH {
meshPort = portName
return meshPort, true
}
}
return "", false
}
func (w *Workload) IsMeshEnabled() bool {
_, ok := w.GetMeshPortName()
return ok
}
func (w *Workload) GetNonExternalAddressesForPort(portName string) []*WorkloadAddress {
var addresses []*WorkloadAddress
for _, address := range w.Addresses {
if address.External {
// Skip external addresses.
continue
}
// If there are no ports, that means this port is selected.
// Otherwise, check if the port is explicitly selected by this address
if len(address.Ports) == 0 || slices.Contains(address.Ports, portName) {
addresses = append(addresses, address)
}
}
return addresses
}