summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Akritidis <43294513+cakrit@users.noreply.github.com>2020-06-10 09:57:01 -0700
committerGitHub <noreply@github.com>2020-06-10 18:57:01 +0200
commit7e001d6069b9679b87c96add581137f3c5a51ad7 (patch)
treed87ee2251140d35d48cf34d8f745b7bae577de55
parent589dac6b98db99d905fbb5689d5c84433fd48c4b (diff)
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
-rwxr-xr-xcollectors/cgroups.plugin/cgroup-name.sh.in9
1 files changed, 6 insertions, 3 deletions
diff --git a/collectors/cgroups.plugin/cgroup-name.sh.in b/collectors/cgroups.plugin/cgroup-name.sh.in
index e704196ee4..ab16e673d9 100755
--- a/collectors/cgroups.plugin/cgroup-name.sh.in
+++ b/collectors/cgroups.plugin/cgroup-name.sh.in
@@ -91,7 +91,7 @@ function k8s_get_name() {
KUBE_TOKEN="$(</var/run/secrets/kubernetes.io/serviceaccount/token)"
NAME="$(
curl -sSk -H "Authorization: Bearer $KUBE_TOKEN" "https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/pods" |
- jq -r '.items[] | "k8s_\(.metadata.namespace)_\(.metadata.name)_\(.metadata.uid)_\(.status.containerStatuses[0].name) \(.status.containerStatuses[0].containerID)"' |
+ jq -r '.items[] | "k8s_\(.metadata.namespace)_\(.metadata.name)_\(.metadata.uid)_" + (.status.containerStatuses[]? | "\(.name) \(.containerID)")' |
grep "$id" |
cut -d' ' -f1
)"
@@ -101,8 +101,11 @@ function k8s_get_name() {
fi
if kubectl --kubeconfig=$KUBE_CONFIG get pod --all-namespaces >/dev/null 2>&1; then
#shellcheck disable=SC2086
- NAME="$(kubectl --kubeconfig=$KUBE_CONFIG get pod --all-namespaces --output='json' | \
- jq -r '.items[] | select(.metadata.uid == "'$id'") | .metadata.name')"
+ NAME="$(kubectl --kubeconfig=$KUBE_CONFIG get pod --all-namespaces --output='json' |
+ jq -r '.items[] | "k8s_\(.metadata.namespace)_\(.metadata.name)_\(.metadata.uid)_" + (.status.containerStatuses[]? | "\(.name) \(.containerID)")' |
+ grep "$id" |
+ cut -d' ' -f1
+ )"
else
warning "kubectl cannot get pod list, check for configuration file in $KUBE_CONFIG, or set this path to env \$KUBE_CONFIG"
fi