-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvauth.sh
executable file
·85 lines (68 loc) · 1.82 KB
/
vauth.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
#!/bin/bash
username=''
password=''
server=''
namespace=''
cluster=''
trap 'catch' ERR
print_usage() {
# Display Help
echo
echo "The vauth application will authenticate to a VMware vCenter Supervisor Cluster for the DevOps container."
echo
echo "Syntax: reauth [-u|p|n|c]"
echo "options:"
echo "u Supervisor Cluster username"
echo "p Supervisor Cluster password"
echo "s Supervisor Cluster server"
echo "n Supervisor Cluster namespace"
echo "c Workload Cluster name"
echo
}
catch() {
# Make sure when authentication fails to clean up
unset KUBECTL_VSPHERE_PASSWORD
cp ~/.kube/config-tmp ~/.kube/config
}
while getopts 'u:p:s:n:c:' flag
do
case "${flag}" in
u) username=${OPTARG};;
p) password=${OPTARG};;
s) server=${OPTARG};;
n) namespace=${OPTARG};;
c) cluster=${OPTARG};;
*) # Invalid option
echo "Error: Invalid option"
print_usage
exit;;
esac
done
if [ -z "$username" ] ; then
echo 'Missing -u <username>' >&2
print_usage
exit 1
fi
if [ -z "$password" ] ; then
echo 'Missing -p <password>' >&2
print_usage
exit 1
fi
if [ -z "$server" ]; then
echo 'Missing -s or <server>' >&2
print_usage
exit 1
fi
_cmd="kubectl vsphere login --vsphere-username $username --server=$server --insecure-skip-tls-verify"
if [ ! -z "$namespace" ]; then
_cmd+=" --tanzu-kubernetes-cluster-namespace $namespace"
fi
if [ ! -z "$cluster" ]; then
_cmd+=" --tanzu-kubernetes-cluster-name $cluster"
fi
eval "mv ~/.kube/config ~/.kube/config-tmp \
&& export KUBECTL_VSPHERE_PASSWORD='$password' \
&& $_cmd \
&& unset KUBECTL_VSPHERE_PASSWORD \
&& cp ~/.kube/config ./config/kube.conf \
&& cp ~/.kube/config-tmp ~/.kube/config"