summaryrefslogtreecommitdiffstats
path: root/daemon/get-kubernetes-labels.sh.in
diff options
context:
space:
mode:
Diffstat (limited to 'daemon/get-kubernetes-labels.sh.in')
-rw-r--r--daemon/get-kubernetes-labels.sh.in17
1 files changed, 9 insertions, 8 deletions
diff --git a/daemon/get-kubernetes-labels.sh.in b/daemon/get-kubernetes-labels.sh.in
index 7e11ba3dd..bc82c2aee 100644
--- a/daemon/get-kubernetes-labels.sh.in
+++ b/daemon/get-kubernetes-labels.sh.in
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
+me="$(basename "${0}")"
# Checks if netdata is running in a kubernetes pod and fetches:
# - pod's labels
@@ -8,8 +9,8 @@ if [ -z "${KUBERNETES_SERVICE_HOST}" ] || [ -z "${KUBERNETES_PORT_443_TCP_PORT}"
exit 0
fi
-if ! command -v jq > /dev/null 2>&1; then
- echo "jq command not available. Please install jq to get host labels for kubernetes pods."
+if ! command -v jq >/dev/null 2>&1; then
+ echo >&2 "${me}: jq command not available. Please install jq to get host labels for kubernetes pods."
exit 1
fi
@@ -18,24 +19,24 @@ HEADER="Authorization: Bearer $TOKEN"
HOST="$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT"
URL="https://$HOST/api/v1/namespaces/$MY_POD_NAMESPACE/pods/$MY_POD_NAME"
-if ! POD_DATA=$(curl -sSk -H "$HEADER" "$URL" 2>&1); then
- echo "error on curl '${URL}': ${POD_DATA}."
+if ! POD_DATA=$(curl --fail -sSk -H "$HEADER" "$URL" 2>&1); then
+ echo >&2 "${me}: error on curl '${URL}': ${POD_DATA}."
exit 1
fi
URL="https://$HOST/api/v1/namespaces/kube-system"
-if ! KUBE_SYSTEM_NS_DATA=$(curl -sSk -H "$HEADER" "$URL" 2>&1); then
- echo "error on curl '${URL}': ${KUBE_SYSTEM_NS_DATA}."
+if ! KUBE_SYSTEM_NS_DATA=$(curl --fail -sSk -H "$HEADER" "$URL" 2>&1); then
+ echo >&2 "${me}: error on curl '${URL}': ${KUBE_SYSTEM_NS_DATA}."
exit 1
fi
if ! POD_LABELS=$(jq -r '.metadata.labels' <<< "$POD_DATA" | grep ':' | tr -d '," ' 2>&1); then
- echo "error on 'jq' parse pod data: ${POD_LABELS}."
+ echo >&2 "${me}: error on 'jq' parse pod data: ${POD_LABELS}."
exit 1
fi
if ! KUBE_SYSTEM_NS_UID=$(jq -r '.metadata.uid' <<< "$KUBE_SYSTEM_NS_DATA" 2>&1); then
- echo "error on 'jq' parse kube_system_ns: ${KUBE_SYSTEM_NS_UID}."
+ echo >&2 "${me}: error on 'jq' parse kube_system_ns: ${KUBE_SYSTEM_NS_UID}."
exit 1
fi