-
Notifications
You must be signed in to change notification settings - Fork 15
/
test_gke_entrypoint.sh
executable file
·88 lines (71 loc) · 2.2 KB
/
test_gke_entrypoint.sh
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash -ex
set -o pipefail
# expects
# TEST_PLATFORM GCLOUD_CLUSTER_NAME GCLOUD_ZONE GCLOUD_PROJECT_NAME GCLOUD_SERVICE_KEY
# CONJUR_NAMESPACE_NAME CONJUR_APPLIANCE_IMAGE
# to exist
export PLATFORM=kubernetes
export TEMPLATE_TAG=gke.
export LOCAL_DEV_VOLUME=$(cat <<- ENDOFLINE
emptyDir: {}
ENDOFLINE
)
function finish {
echo 'Finishing'
echo '-----'
kubectl get events
{
pod_name="$(kubectl get pods -l role=master --no-headers | awk '{print $1}')"
if [[ -z "$pod_name" ]]; then
pod_name="$(kubectl get pods -l role=unset --no-headers | awk '{print $1}')"
fi
kubectl logs $pod_name > "output/$TEST_PLATFORM-authn-k8s-logs.txt"
} || {
echo "Logs could not be extracted from pod '$pod_name'"
touch "output/$TEST_PLATFORM-authn-k8s-logs.txt" # so Jenkins artifact collection doesn't fail
}
./stop
deleteRegistryImage "$DOCKER_REGISTRY_PATH/haproxy:$CONJUR_NAMESPACE_NAME"
deleteRegistryImage "$DOCKER_REGISTRY_PATH/conjur-appliance:$CONJUR_NAMESPACE_NAME"
}
trap finish EXIT
function main() {
getGKEVersion
initialize
runScripts
}
function initialize() {
gcloud auth activate-service-account --key-file $GCLOUD_SERVICE_KEY
gcloud container clusters get-credentials $GCLOUD_CLUSTER_NAME --zone $GCLOUD_ZONE --project $GCLOUD_PROJECT_NAME
set +x
docker login $DOCKER_REGISTRY_URL -u oauth2accesstoken -p $(gcloud auth print-access-token)
set -x
}
function runScripts() {
cmd="./start"
if [ $CONJUR_DEPLOYMENT == "oss" ]; then
cmd="$cmd --oss"
fi
$cmd
}
function relaunchMaster() {
echo 'Relaunching master to test persistent volume restore'
./relaunch_master.sh
}
# Delete an image from GCR, unless it is has multiple tags pointing to it
# This means another parallel build is using the image and we should
# just untag it to be deleted by the later job
function deleteRegistryImage() {
local image_and_tag=$1
IFS=':' read -r -a array <<< $image_and_tag
local image="${array[0]}"
local tag="${array[1]}"
if gcloud container images list-tags $image | grep $tag; then
gcloud container images delete --force-delete-tags -q $image_and_tag
fi
}
function getGKEVersion() {
echo "GKE version"
kubectl version --client=true
}
main