Ensures we get consistent kubernetes cgroup container names, regardless of whether netdata runs from within a kubernetes pod, or directly on the host machine. (#9303)
Fixes #8044 Ensures we get consistent kubernetes cgroup container names, regardless of whether netdata runs from within a kubernetes pod, or directly on the host machine. Additional Information Fixes a bug that was originally fixed in #6885 and re-introduced in #7416. Fixes the seemingly non-functional selector in #7416
Chris Akritidis committed
Jun 10, 2020 at 09:57 UTC
7e001d6069b9679b87c96add581137f3c5a51ad7
1 file changed
+6
-3
collectors/cgroups.plugin/cgroup-name.sh.in
+6
-3
@@ -91,7 +91,7 @@ function k8s_get_name() {
91
KUBE_TOKEN="$(</var/run/secrets/kubernetes.io/serviceaccount/token)"
92
NAME="$(
93
curl -sSk -H "Authorization: Bearer $KUBE_TOKEN" "https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/pods" |
94
- jq -r '.items[] | "k8s_\(.metadata.namespace)_\(.metadata.name)_\(.metadata.uid)_\(.status.containerStatuses[0].name) \(.status.containerStatuses[0].containerID)"' |
94
+ jq -r '.items[] | "k8s_\(.metadata.namespace)_\(.metadata.name)_\(.metadata.uid)_" + (.status.containerStatuses[]? | "\(.name) \(.containerID)")' |
95
grep "$id" |
96
cut -d' ' -f1
97
)"
@@ -101,8 +101,11 @@ function k8s_get_name() {
101
fi
102
if kubectl --kubeconfig=$KUBE_CONFIG get pod --all-namespaces >/dev/null 2>&1; then
103
#shellcheck disable=SC2086
104
- NAME="$(kubectl --kubeconfig=$KUBE_CONFIG get pod --all-namespaces --output='json' | \
105
- jq -r '.items[] | select(.metadata.uid == "'$id'") | .metadata.name')"
104
+ NAME="$(kubectl --kubeconfig=$KUBE_CONFIG get pod --all-namespaces --output='json' |
105
+ jq -r '.items[] | "k8s_\(.metadata.namespace)_\(.metadata.name)_\(.metadata.uid)_" + (.status.containerStatuses[]? | "\(.name) \(.containerID)")' |
106
+ grep "$id" |
107
+ cut -d' ' -f1
108
+ )"
109
else
110
warning "kubectl cannot get pod list, check for configuration file in $KUBE_CONFIG, or set this path to env \$KUBE_CONFIG"
111
fi