forked from dokku/dokku-scheduler-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduler-stop
executable file
·44 lines (37 loc) · 1.52 KB
/
scheduler-stop
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
#!/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-kubernetes-scheduler-stop() {
declare desc="scheduler-kubernetes scheduler-stop plugin trigger"
declare trigger="scheduler-kubernetes scheduler-stop"
declare DOKKU_SCHEDULER="$1" APP="$2" REMOVE_CONTAINERS="$3"
local KUBE_ARGS NAMESPACE
if [[ "$DOKKU_SCHEDULER" != "kubernetes" ]]; then
return
fi
local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE"
if [[ ! -f "$DOKKU_SCALE_FILE" ]]; then
return
fi
export KUBECONFIG="${DOKKU_ROOT}/.kube/config"
export KUBEDOG_KUBE_CONFIG="${DOKKU_ROOT}/.kube/config"
KUBE_ARGS=()
NAMESPACE="$(fn-plugin-property-get "scheduler-kubernetes" "$APP" "namespace" "")"
if [[ -n "$NAMESPACE" ]]; then
KUBE_ARGS+=("--namespace=$NAMESPACE")
fn-scheduler-kubernetes-ensure-namespace "$NAMESPACE" >/dev/null
fi
while read -r line || [[ -n "$line" ]]; do
[[ "$line" =~ ^#.* ]] && continue
line="$(strip_inline_comments "$line")"
PROC_TYPE=${line%%=*}
PROC_COUNT=${line#*=}
if "${DOKKU_LIB_ROOT}/data/scheduler-kubernetes/kubectl" get deployment "${APP}-${PROC_TYPE}" 2>/dev/null; then
"${DOKKU_LIB_ROOT}/data/scheduler-kubernetes/kubectl" "${KUBE_ARGS[@]}" scale --replicas=0 "deployment/${APP}-${PROC_TYPE}"
fi
done <"$DOKKU_SCALE_FILE"
}
scheduler-kubernetes-scheduler-stop "$@"