Skip to content
This repository has been archived by the owner on Jan 21, 2025. It is now read-only.

Commit

Permalink
Make failure to get node name non-fatal and cache container metadata …
Browse files Browse the repository at this point in the history
…lookup failures
  • Loading branch information
nsavoire committed May 22, 2024
1 parent 29c2692 commit 1392fad
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions containermetadata/containermetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ func createKubernetesClient(ctx context.Context, instance *Handler) error {

instance.nodeName, err = getNodeName()
if err != nil {
return fmt.Errorf("failed to get kubernetes node name; %v", err)
log.Errorf("failed to get kubernetes node name; %v", err)
instance.nodeName = "UNKNOWN"
}

instance.containerMetadataCache, err = getContainerMetadataCache(ctx, instance)
Expand Down Expand Up @@ -492,7 +493,9 @@ func (h *Handler) getKubernetesPodMetadata(pidContainerID string) (
FieldSelector: "spec.nodeName=" + h.nodeName,
})
if err != nil {
return ContainerMetadata{}, fmt.Errorf("failed to retrieve kubernetes pods, %v", err)
containerMetadata := ContainerMetadata{}
h.containerMetadataCache.Add(pidContainerID, containerMetadata)
return containerMetadata, fmt.Errorf("failed to retrieve kubernetes pods, %v", err)
}

for j := range pods.Items {
Expand Down Expand Up @@ -520,7 +523,9 @@ func (h *Handler) getKubernetesPodMetadata(pidContainerID string) (
}
}

return ContainerMetadata{},
containerMetadata := ContainerMetadata{}
h.containerMetadataCache.Add(pidContainerID, containerMetadata)
return containerMetadata,
fmt.Errorf("failed to find matching kubernetes pod/container metadata for "+
"containerID '%v' in %d pods", pidContainerID, len(pods.Items))
}
Expand Down

0 comments on commit 1392fad

Please sign in to comment.