summaryrefslogtreecommitdiffstats
path: root/collectors/cgroups.plugin
diff options
context:
space:
mode:
authorIlya Mashchenko <ilya@netdata.cloud>2023-04-13 01:02:11 +0300
committerGitHub <noreply@github.com>2023-04-13 01:02:11 +0300
commit068ae1cfac921313c7d60f8a3fea5f19600c1f38 (patch)
tree2ae097eb6f1842090e9e51d0c61d6679c59279a5 /collectors/cgroups.plugin
parent299502b6dab3fa9d9cbccce5ba1c404469f77335 (diff)
cgroups: add option to use Kubelet for pods metadata (#14891)
Diffstat (limited to 'collectors/cgroups.plugin')
-rwxr-xr-xcollectors/cgroups.plugin/cgroup-name.sh14
1 files changed, 12 insertions, 2 deletions
diff --git a/collectors/cgroups.plugin/cgroup-name.sh b/collectors/cgroups.plugin/cgroup-name.sh
index 096d9c81b3..9a5812f35f 100755
--- a/collectors/cgroups.plugin/cgroup-name.sh
+++ b/collectors/cgroups.plugin/cgroup-name.sh
@@ -306,8 +306,14 @@ function k8s_get_kubepod_name() {
fi
fi
- url="https://$host/api/v1/pods"
- [ -n "$MY_NODE_NAME" ] && url+="?fieldSelector=spec.nodeName==$MY_NODE_NAME"
+ local url
+ if [ -n "${USE_KUBELET_FOR_PODS_METADATA}" ]; then
+ url="${KUBELET_URL:-https://localhost:10250}/pods"
+ else
+ url="https://$host/api/v1/pods"
+ [ -n "$MY_NODE_NAME" ] && url+="?fieldSelector=spec.nodeName==$MY_NODE_NAME"
+ fi
+
# FIX: check HTTP response code
if ! pods=$(curl --fail -sSk -H "$header" "$url" 2>&1); then
warning "${fn}: error on curl '${url}': ${pods}."
@@ -404,6 +410,10 @@ function k8s_get_kubepod_name() {
# jq filter nonexistent field and nonexistent label value is 'null'
if [[ $name =~ _null(_|$) ]]; then
warning "${fn}: invalid name: $name (cgroup '$id')"
+ if [ -n "${USE_KUBELET_FOR_PODS_METADATA}" ]; then
+ # local data is cached and may not contain the correct id
+ return 2
+ fi
return 1
fi