Skip to content

Commit

Permalink
fix using custom services (#122)
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Paskal <[email protected]>
  • Loading branch information
maksim-paskal authored Oct 18, 2023
1 parent ef765f1 commit 1949735
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions pkg/configstore/configStore.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ type envoyEndpoint struct {
Metadata map[string]string
}

func (e *envoyEndpoint) SetNode(address corev1.EndpointAddress) {
if address.NodeName != nil {
e.Node = *address.NodeName
}
}

func (cs *ConfigStore) getEnvoyLocalityLbEndpoint(envoyEndpoint *envoyEndpoint) *endpoint.LocalityLbEndpoints { //nolint:lll
priority := uint32(0)

Expand Down Expand Up @@ -366,15 +372,20 @@ func (cs *ConfigStore) getLocalityLbEndpoints() (map[string][]*endpoint.Locality

for _, subset := range endpoints.Subsets {
for _, address := range subset.Addresses {
// get envoy endpoint
lbEndpoints[kubernetes.ClusterName] = append(lbEndpoints[kubernetes.ClusterName], cs.getEnvoyLocalityLbEndpoint(&envoyEndpoint{ //nolint:lll
newEp := &envoyEndpoint{
IsCanary: false,
Node: *address.NodeName,
Address: address.IP,
Item: kubernetes,
Metadata: cs.getEnvoyMetaFromEndpoint(address),
},
))
}

newEp.SetNode(address)

// get envoy endpoint
lbEndpoints[kubernetes.ClusterName] = append(
lbEndpoints[kubernetes.ClusterName],
cs.getEnvoyLocalityLbEndpoint(newEp),
)
}
}

Expand All @@ -393,15 +404,20 @@ func (cs *ConfigStore) getLocalityLbEndpoints() (map[string][]*endpoint.Locality

for _, subset := range endpointsCanary.Subsets {
for _, address := range subset.Addresses {
// get envoy endpoint
lbEndpoints[kubernetes.ClusterName] = append(lbEndpoints[kubernetes.ClusterName], cs.getEnvoyLocalityLbEndpoint(&envoyEndpoint{ //nolint:lll
newEp := &envoyEndpoint{
IsCanary: true,
Node: *address.NodeName,
Address: address.IP,
Item: kubernetes,
Metadata: cs.getEnvoyMetaFromEndpoint(address),
},
))
}

newEp.SetNode(address)

// get envoy endpoint
lbEndpoints[kubernetes.ClusterName] = append(
lbEndpoints[kubernetes.ClusterName],
cs.getEnvoyLocalityLbEndpoint(newEp),
)
}
}
}
Expand Down Expand Up @@ -431,7 +447,7 @@ func (cs *ConfigStore) getEnvoyMetaFromPod(pod *corev1.Pod) map[string]string {
func (cs *ConfigStore) getEnvoyMetaFromEndpoint(address corev1.EndpointAddress) map[string]string {
labels := make(map[string]string)

if address.TargetRef.Kind == "Pod" {
if address.TargetRef != nil && address.TargetRef.Kind == "Pod" {
// add pod labels to envoy metadata
pod, err := api.GetPod(address.TargetRef.Namespace, address.TargetRef.Name)
if err != nil {
Expand All @@ -447,8 +463,11 @@ func (cs *ConfigStore) getEnvoyMetaFromEndpoint(address corev1.EndpointAddress)
labels[envoyMetaPodName] = address.TargetRef.Name
}

if address.NodeName != nil {
labels[envoyMetaNodeName] = *address.NodeName
}

labels[envoyMetaEndpointIP] = address.IP
labels[envoyMetaNodeName] = *address.NodeName

return labels
}
Expand Down

0 comments on commit 1949735

Please sign in to comment.