2021-11-29 08:07:17 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
TTL="24h"
|
|
|
|
CERTIFICATE_GROUP="system:masters"
|
2021-12-07 10:08:44 +00:00
|
|
|
DEBUG=""
|
2021-11-29 08:07:17 +00:00
|
|
|
|
|
|
|
print_usage() {
|
|
|
|
echo "gs-login - login to Giant Swarm managed clusters"
|
|
|
|
echo " "
|
|
|
|
echo "gs-login [INSTALLATION] [WORKLOAD CLUSTER] [ORGANISATION]"
|
|
|
|
echo " "
|
|
|
|
echo "Examples:"
|
|
|
|
echo "> gs-login gauss"
|
|
|
|
echo "> gs-login gauss mywc1"
|
|
|
|
echo " "
|
|
|
|
echo "Options:"
|
|
|
|
echo "-h, --help show this help text"
|
|
|
|
echo "-t, --ttl the certificate ttl for the workload cluster login (default: 24h)"
|
|
|
|
echo "-g, --certificate-group the certificate group to login as on the workload cluster (default: system:masters)"
|
|
|
|
}
|
|
|
|
|
2021-12-07 10:08:44 +00:00
|
|
|
POS_ARGS=()
|
|
|
|
|
2021-11-29 08:07:17 +00:00
|
|
|
while test $# -gt 0; do
|
|
|
|
case "$1" in
|
|
|
|
-t|--ttl)
|
|
|
|
shift
|
|
|
|
TTL=$1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-g|--certificate-group)
|
|
|
|
shift
|
|
|
|
CERTIFICATE_GROUP=$1
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-h|--help)
|
|
|
|
print_usage
|
|
|
|
exit 0
|
|
|
|
;;
|
2021-12-07 10:08:44 +00:00
|
|
|
--debug)
|
|
|
|
DEBUG="--debug"
|
|
|
|
shift
|
|
|
|
/)
|
|
|
|
# We want to ignore slash seperators between MC and WC
|
|
|
|
shift
|
|
|
|
;;
|
2021-11-29 08:07:17 +00:00
|
|
|
*)
|
2021-12-07 10:08:44 +00:00
|
|
|
POS_ARGS+=(`echo $1 | tr '/' ' '`)
|
|
|
|
shift
|
2021-11-29 08:07:17 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2021-12-07 10:08:44 +00:00
|
|
|
case ${#POS_ARGS[@]} in
|
2021-11-29 08:07:17 +00:00
|
|
|
1)
|
2021-12-07 10:08:44 +00:00
|
|
|
kubectl gs login ${POS_ARGS[0]} ${DEBUG} 2>/dev/null || opsctl kgs login -i ${POS_ARGS[0]}
|
2021-11-29 08:07:17 +00:00
|
|
|
;;
|
|
|
|
2)
|
2021-12-07 10:08:44 +00:00
|
|
|
kubectl gs login ${POS_ARGS[0]} --workload-cluster ${POS_ARGS[1]} --certificate-group ${CERTIFICATE_GROUP} --certificate-ttl ${TTL} ${DEBUG}
|
2021-11-29 08:07:17 +00:00
|
|
|
;;
|
|
|
|
3)
|
2021-12-07 10:08:44 +00:00
|
|
|
kubectl gs login ${POS_ARGS[0]} --workload-cluster ${POS_ARGS[1]} --certificate-group ${CERTIFICATE_GROUP} --certificate-ttl ${TTL} --organization ${POS_ARGS[2]} ${DEBUG}
|
2021-11-29 08:07:17 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
print_usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|