-
Notifications
You must be signed in to change notification settings - Fork 0
/
istioctl
executable file
·72 lines (60 loc) · 1.81 KB
/
istioctl
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
#/bin/bash
# set -e
## Pre-req check
##Check to see if Heptio is installed and in the user's path:
which heptio-authenticator-aws &>/dev/null
if [ $? -ne 0 ]; then
echo "Heptio not installed or not in your PATH. Please see README.md for instructions."
exit 1
fi
##Check to see if aws is installed and in the user's path:
aws eks list-clusters &>/dev/null
if [ $? -ne 0 ]; then
echo "AWS CLI has errored. Either it's not installed, the eks module is missing, \
or you are not authorized. Please see README.md for instructions."
exit 1
fi
## Variables
CONFIG_FILE=~/.kube/config-istio
EXPIRETIME=600
CLUSTER=$(kubectl config view --minify -o jsonpath='{.users[0].user.exec.args[2]}')
FILEAGE=0
## Function
get_token () {
PASSED_CLUSTER=$1
## Get a token, cluster url, and certificate and strip the uninteresting bits
TOKEN=$(heptio-authenticator-aws token -i $PASSED_CLUSTER | awk -F: {'print $6'} | cut -d } -f 1)
CLUSTERURL=$(aws eks describe-cluster --name $PASSED_CLUSTER --query='cluster.endpoint')
CLUSTERCA=$(aws eks describe-cluster --name $PASSED_CLUSTER --query='cluster.certificateAuthority.data')
cat > $CONFIG_FILE << EOF
apiVersion: v1
clusters:
- cluster:
server: $CLUSTERURL
certificate-authority-data: $CLUSTERCA
name: eks
contexts:
- context:
cluster: eks
user: aws
name: aws
current-context: aws
kind: Config
preferences: {}
users:
- name: aws
user:
token: $TOKEN
EOF
}
## If ~/.kube/config-istio exists, check its timestamp
if [ -e $CONFIG_FILE ]; then
CONFIG_FILE_TIMESTAMP=$(date -r $CONFIG_FILE +%s)
CURRENT_TIME=$(date +%s)
FILEAGE=$(($CURRENT_TIME-$CONFIG_FILE_TIMESTAMP))
fi
if [ $FILEAGE -gt $EXPIRETIME ] || [ ! -e $CONFIG_FILE ]; then
get_token $CLUSTER
fi
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
$DIR/command/istioctl.`uname` -c $CONFIG_FILE "$@"