Skip to content

Commit

Permalink
Merge pull request #1105 from amazeeio/feature/idle-all-cli
Browse files Browse the repository at this point in the history
idle all clis
  • Loading branch information
Schnitzel authored May 28, 2019
2 parents c074b9b + 0cb7bc4 commit 63e2a6c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions services/auto-idler/idle-clis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ API_ADMIN_JWT_TOKEN=$(./create_jwt.sh)
BEARER="Authorization: bearer $API_ADMIN_JWT_TOKEN"

# Load all projects and their environments
GRAPHQL='query developmentEnvironments {
developmentEnvironments:allProjects {
GRAPHQL='query environments {
environments:allProjects {
name
autoIdle
openshift {
consoleUrl
token
name
}
environments(type: DEVELOPMENT) {
environments {
openshiftProjectName
name
}
Expand All @@ -28,7 +28,7 @@ ALL_ENVIRONMENTS=$(curl -s -XPOST -H 'Content-Type: application/json' -H "$BEARE

# Filter only projects that actually have an environment
# Loop through each found project
echo "$ALL_ENVIRONMENTS" | jq -c '.data.developmentEnvironments[] | select((.environments|length)>=1)' | while read project
echo "$ALL_ENVIRONMENTS" | jq -c '.data.environments[] | select((.environments|length)>=1)' | while read project
do
PROJECT_NAME=$(echo "$project" | jq -r '.name')
OPENSHIFT_URL=$(echo "$project" | jq -r '.openshift.consoleUrl')
Expand Down Expand Up @@ -91,6 +91,7 @@ echo "$ALL_ENVIRONMENTS" | jq -c '.data.developmentEnvironments[] | select((.env
NO_PROCESSES=true
else
echo "$OPENSHIFT_URL - $PROJECT_NAME: $ENVIRONMENT_NAME: $deploymentconfig: has $RUNNING_PROCESSES running processes, skipping"
continue
fi

# Check for cronjobs present
Expand All @@ -103,6 +104,7 @@ echo "$ALL_ENVIRONMENTS" | jq -c '.data.developmentEnvironments[] | select((.env
NO_CRONJOBS=true
else
echo "$OPENSHIFT_URL - $PROJECT_NAME: $ENVIRONMENT_NAME: $deploymentconfig: has cronjobs defined, skipping"
continue
fi

# Check for any running builds
Expand All @@ -116,11 +118,12 @@ echo "$ALL_ENVIRONMENTS" | jq -c '.data.developmentEnvironments[] | select((.env
NO_BUILDS=true
else
echo "$OPENSHIFT_URL - $PROJECT_NAME: $ENVIRONMENT_NAME: $deploymentconfig: has $RUNNING_BUILDS running builds, skipping"
continue
fi

## If there are no builds AND no processes, then we can idle the pods
if [[ "$NO_BUILDS" == "true" && "$NO_PROCESSES" == "true" && "$NO_CRONJOBS" == "true" ]]; then
echo "$OPENSHIFT_URL - $PROJECT_NAME: $ENVIRONMENT_NAME: $deploymentconfig: not busy, scaling to 0"
echo "$OPENSHIFT_URL - $PROJECT_NAME: $ENVIRONMENT_NAME: $deploymentconfig: scaling to 0"
oc --insecure-skip-tls-verify --token="$OPENSHIFT_TOKEN" --server="$OPENSHIFT_URL" -n "$ENVIRONMENT_OPENSHIFT_PROJECTNAME" scale --replicas=0 $deploymentconfig
fi
else
Expand Down

0 comments on commit 63e2a6c

Please sign in to comment.