This repository has been archived by the owner on Dec 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-entrypoint.sh
executable file
·71 lines (65 loc) · 2.13 KB
/
docker-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
#!/bin/bash
set -e
set -x
# EKS cluster kubectl configs
#
# The AWS_EKS_CLUSTER_CONFIG environment variable is used to configure target EKS clusters. The information must be
# provided as an array of fields.
#
# AWS_EKS_CLUSTER_CONFIG fields (in order):
# * AWS Region - Target AWS Region.
# * Cluster Name - EKS Cluster name.
# * Kubeconfig - Kubeconfig filename.
#
# Notes:
# * All fields are required.
# * Fields are separated by commas.
# * Kubeconfig files will be stored in the running user's home .kube directory.
#
# Cluster name
# ↓
# Example: AWS_EKS_CLUSTER_CONFIG="us-east-1,test-cluster,config_test_cluster"
# ↑ ↑
# Region Cluster config name
#
# To support multiple clusters, you can define multiple configurations and separate them by semicolons.
CheckOK() {
if [ $1 -ne 0 ]; then
OK=0
fi
}
if [ -n "$AWS_EKS_CLUSTER_CONFIG" ]; then
echo "Parsing EKS cluster configurations."
# Get the set of cluster configurations
OK=1
IFS=';' read -ra CLUSTERS <<< "$AWS_EKS_CLUSTER_CONFIG"
for i in "${!CLUSTERS[@]}"; do
echo -e "\nParsing configuration $((i+1))"
# Parse config values
IFS=',' read -ra CONFIG <<< "${CLUSTERS[i]}"
if [ ${#CONFIG[@]} -ne 3 ]; then
echo " Invalid cluster config values:" "${CONFIG[@]}"
CheckOK 1
continue
fi
read -r REGION CLUSTER_NAME CONFIG_NAME <<< "${CONFIG[@]}"
echo " Region: ${REGION}"
echo " Cluster Name: ${CLUSTER_NAME}"
echo " Config Name: ${CONFIG_NAME}"
# Get the EKS kubeconfig
aws eks update-kubeconfig \
--region ${REGION} \
--name ${CLUSTER_NAME} \
--kubeconfig $HOME/.kube/${CONFIG_NAME} \
> /dev/null
CheckOK $?
done
if [ $OK -ne 1 ]; then
echo -e "\nCluster configuration failed. Exiting"
exit 1
fi
else
echo "No EKS cluster configurations provided."
exit 1
fi
exec "$@"