Skip to content

Commit

Permalink
Fix the pod name for comDetails
Browse files Browse the repository at this point in the history
Modifies the function for creating comDetails,
so the pod name will be more accurate.

Signed-off-by: Lior Noy <[email protected]>
  • Loading branch information
liornoy committed Jun 20, 2024
1 parent d97ed0f commit 9cc612a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion endpointslices/endpointslices.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package endpointslices
import (
"context"
"fmt"
"strings"

log "github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -200,6 +201,24 @@ func getContainerName(portNum int, pods []corev1.Pod) (string, error) {
return res, nil
}

func getPodName(pod *corev1.Pod) string {
var res string
name := pod.OwnerReferences[0].Name

switch pod.OwnerReferences[0].Kind {
case "Node":
res, _ = strings.CutSuffix(pod.Name, pod.OwnerReferences[0].Name)

case "ReplicaSet":
a := strings.Split(name, "-")
res = strings.Join(a[:len(a)-1], "-")
default:
res = name
}

return res
}

func (epSliceinfo *EndpointSlicesInfo) toComDetails(nodes []corev1.Node) ([]types.ComDetails, error) {
if len(epSliceinfo.EndpointSlice.OwnerReferences) == 0 {
return nil, fmt.Errorf("empty OwnerReferences in EndpointSlice %s/%s. skipping", epSliceinfo.EndpointSlice.Namespace, epSliceinfo.EndpointSlice.Name)
Expand All @@ -209,7 +228,7 @@ func (epSliceinfo *EndpointSlicesInfo) toComDetails(nodes []corev1.Node) ([]type

// Get the Namespace and Pod's name from the service.
namespace := epSliceinfo.Service.Namespace
name := epSliceinfo.EndpointSlice.OwnerReferences[0].Name
name := getPodName(&epSliceinfo.Pods[0])

// Get the node roles of this endpointslice. (master or worker or both).
roles := getEndpointSliceNodeRoles(epSliceinfo, nodes)
Expand Down

0 comments on commit 9cc612a

Please sign in to comment.