From 4d38d12e060eac5024272d2a38d658faecf832ea Mon Sep 17 00:00:00 2001 From: Lior Noy Date: Wed, 8 May 2024 17:12:57 +0300 Subject: [PATCH] ss: Log warning instead of return error This commit changes the logic of `parseComDetail` function to log warning when can't extract service name, and set it to empty, instead of returning an error. This is to prevent the matrix generation from failing due to an `SS` entry without a service name like the following: `UNCONN 0 0 [::]:6081 [::]:* ` Signed-off-by: Lior Noy --- ss/ss.go | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/ss/ss.go b/ss/ss.go index 320fdd3..060fea8 100644 --- a/ss/ss.go +++ b/ss/ss.go @@ -45,14 +45,8 @@ func CreateComDetailsFromNode(debugPod *debug.DebugPod, node *corev1.Node, tcpFi ssOutFilteredTCP := filterEntries(splitByLines(ssOutTCP)) ssOutFilteredUDP := filterEntries(splitByLines(ssOutUDP)) - tcpComDetails, err := toComDetails(debugPod, ssOutFilteredTCP, "TCP", node) - if err != nil { - return nil, err - } - udpComDetails, err := toComDetails(debugPod, ssOutFilteredUDP, "UDP", node) - if err != nil { - return nil, err - } + tcpComDetails := toComDetails(debugPod, ssOutFilteredTCP, "TCP", node) + udpComDetails := toComDetails(debugPod, ssOutFilteredUDP, "UDP", node) res := []types.ComDetails{} res = append(res, udpComDetails...) @@ -66,15 +60,13 @@ func splitByLines(bytes []byte) []string { return strings.Split(str, "\n") } -func toComDetails(debugPod *debug.DebugPod, ssOutput []string, protocol string, node *corev1.Node) ([]types.ComDetails, error) { +func toComDetails(debugPod *debug.DebugPod, ssOutput []string, protocol string, node *corev1.Node) []types.ComDetails { res := make([]types.ComDetails, 0) nodeRoles := nodes.GetRole(node) for _, ssEntry := range ssOutput { - cd, err := parseComDetail(ssEntry) - if err != nil { - return nil, err - } + cd := parseComDetail(ssEntry) + name, err := getContainerName(debugPod, ssEntry) if err != nil { log.Debugf("failed to identify container for ss entry: %serr: %s", ssEntry, err) @@ -87,7 +79,7 @@ func toComDetails(debugPod *debug.DebugPod, ssOutput []string, protocol string, res = append(res, *cd) } - return res, nil + return res } // getContainerName receives an ss entry and gets the name of the container exposing this port. @@ -188,10 +180,10 @@ func filterEntries(ssEntries []string) []string { return res } -func parseComDetail(ssEntry string) (*types.ComDetails, error) { +func parseComDetail(ssEntry string) *types.ComDetails { serviceName, err := extractServiceName(ssEntry) if err != nil { - return nil, err + log.Debugf(err.Error()) } fields := strings.Fields(ssEntry) @@ -202,7 +194,7 @@ func parseComDetail(ssEntry string) (*types.ComDetails, error) { Direction: consts.IngressLabel, Port: port, Service: serviceName, - Optional: false}, nil + Optional: false} } func extractServiceName(ssEntry string) (string, error) {