-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ACM - Wait for gatekeeper & Hub: expose module_depends_on (#689)
* wait for gatekeeper if policy controller is enabled * destroy command * forgot the var * use deployment ready * add context * more wait * webhook * depends_on * concat modules * depends on * terraform format * update docs * shell check
- Loading branch information
1 parent
c5d1e4d
commit 26ea28d
Showing
8 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
modules/k8s-operator-crd-support/scripts/wait_for_gatekeeper.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/bin/bash | ||
# Copyright 2018 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
is_deployment_ready() { | ||
kubectl --context "$1" -n "$2" get deploy "$3" &> /dev/null | ||
export exit_code=$? | ||
while [ ! " ${exit_code} " -eq 0 ] | ||
do | ||
sleep 5 | ||
echo -e "Waiting for deployment $3 in cluster $1 to be created..." | ||
kubectl --context "$1" -n "$2" get deploy "$3" &> /dev/null | ||
export exit_code=$? | ||
done | ||
echo -e "Deployment $3 in cluster $1 created." | ||
|
||
# Once deployment is created, check for deployment status.availableReplicas is greater than 0 | ||
availableReplicas=$(kubectl --context "$1" -n "$2" get deploy "$3" -o json | jq -r '.status.availableReplicas') | ||
while [[ " ${availableReplicas} " == " null " ]] | ||
do | ||
sleep 5 | ||
echo -e "Waiting for deployment $3 in cluster $1 to become ready..." | ||
availableReplicas=$(kubectl --context "$1" -n "$2" get deploy "$3" -o json | jq -r '.status.availableReplicas') | ||
done | ||
|
||
echo -e "$3 in cluster $1 is ready with replicas ${availableReplicas}." | ||
return "${availableReplicas}" | ||
} | ||
|
||
is_service_ready() { | ||
kubectl --context "$1" -n "$2" get service "$3" &> /dev/null | ||
export exit_code=$? | ||
while [ ! " ${exit_code} " -eq 0 ] | ||
do | ||
sleep 5 | ||
echo -e "Waiting for service $3 in cluster $1 to be created..." | ||
kubectl --context "$1" -n "$2" get service "$3" &> /dev/null | ||
export exit_code=$? | ||
done | ||
echo -e "Service $3 in cluster $1 created." | ||
|
||
# Once service is created, check endpoints is greater than 0 | ||
kubectl --context "$1" -n "$2" get endpoints "$3" | ||
export exit_code=$? | ||
|
||
while [ ! " ${exit_code} " -eq 0 ] | ||
do | ||
sleep 5 | ||
echo -e "Waiting for endpoints for service $3 in cluster $1 to become ready..." | ||
kubectl --context "$1" -n "$2" get endpoints "$3" | ||
export exit_code=$? | ||
done | ||
|
||
echo -e "Service $3 in cluster $1 is ready with endpoints." | ||
return | ||
} | ||
|
||
if [ "$#" -lt 3 ]; then | ||
>&2 echo "Not all expected arguments set." | ||
exit 1 | ||
fi | ||
|
||
PROJECT_ID=$1 | ||
CLUSTER_NAME=$2 | ||
CLUSTER_LOCATION=$3 | ||
|
||
# Gatekeeper causes issues if not ready | ||
is_deployment_ready gke_"${PROJECT_ID}"_"${CLUSTER_LOCATION}"_"${CLUSTER_NAME}" gatekeeper-system gatekeeper-controller-manager | ||
is_service_ready gke_"${PROJECT_ID}"_"${CLUSTER_LOCATION}"_"${CLUSTER_NAME}" gatekeeper-system gatekeeper-webhook-service |