-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
scheduler-app-status
executable file
·47 lines (39 loc) · 1.49 KB
/
scheduler-app-status
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
source "$PLUGIN_AVAILABLE_PATH/scheduler-kubernetes/internal-functions"
scheduler-app-status() {
declare desc="fetches the status for a given app"
declare trigger="scheduler-kubernetes scheduler-app-status"
declare DOKKU_SCHEDULER="$1" APP="$2"
local KUBE_OUTPUT
if [[ "$DOKKU_SCHEDULER" != "kubernetes" ]]; then
return
fi
export KUBECONFIG="${DOKKU_ROOT}/.kube/config"
KUBE_ARGS=()
NAMESPACE="$(fn-plugin-property-get "scheduler-kubernetes" "$APP" "namespace" "default")"
KUBE_ARGS+=("--namespace=$NAMESPACE")
fn-scheduler-kubernetes-ensure-namespace "$NAMESPACE" >/dev/null
local PROCS=0 RUNNING=""
KUBE_OUTPUT="$("${DOKKU_LIB_ROOT}/data/scheduler-kubernetes/kubectl" "${KUBE_ARGS[@]}" get pods --selector app="$APP" -o custom-columns="STATUS:.status.conditions[?(@.type=='Ready')].status" --no-headers 2>/dev/null || true)"
while IFS= read -r line; do
if [[ "$line" == "True" ]]; then
RUNNING+="0"
else
RUNNING+="1"
fi
PROCS=$((PROCS + 1))
done < <(printf '%s\n' "$KUBE_OUTPUT")
if [[ "${#RUNNING}" -eq 0 ]] || [[ "${#RUNNING}" -ne 0 ]] && [[ "$RUNNING" != *"0"* ]]; then
RUNNING="false"
elif [[ "$RUNNING" != *"1"* ]] && [[ "${#RUNNING}" -ne 0 ]]; then
RUNNING="true"
else
RUNNING="mixed"
fi
echo "$PROCS $RUNNING"
}
scheduler-app-status "$@"