forked from SAP-archive/teched2020-developer-keynote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
k
executable file
·129 lines (110 loc) · 2.54 KB
/
k
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env bash
# Kubernetes/Kyma utilities - k
set -o errexit
declare namespace dockerserver user repository
self=$(basename "$0")
namespace=default
dockerserver=https://docker.pkg.github.com
secretname=regcred
# Helper functions -----------------------------------------------------
usage() {
cat <<EOF
Usage: $self <options> <action>
with options:
-u | --user <GitHub user>
-r | --repository <GitHub repository>
with actions:
- deploy: make deployment (needs -u and -r)
- configmap: create and deploy config map
- secret: create secret for GitHub Package registry access
EOF
}
checkval() {
while (( $# )); do
if [[ -z "$1" ]]; then
usage
exit 1
fi
shift
done
}
# Action functions -----------------------------------------------------
deploy() {
checkval "$user" "$repository"
echo Deploying to k8s
sed -e "s/OWNER/$user/; s/REPOSITORY/$repository/" deployment.yaml \
| kubectl apply -n $namespace -f -
}
configmap() {
local json
if [ ! -f default-env.json ]; then
echo No default-env.json file
exit 1
fi
echo Creating and deploying config map to k8s
json=$(jq -r .VCAP_SERVICES default-env.json | tr '\n' ' ')
cat <<EOF | kubectl apply -f -
kind: ConfigMap
apiVersion: v1
metadata:
name: appconfigcap
data:
VCAP_SERVICES: |
$json
EOF
}
secret() {
local email user pass
echo Setting up docker-registry secret $secretname for access to $dockerserver
if kubectl get secret $secretname >/dev/null 2>&1; then
read -rp "Secret $secretname exists - will remove first (hit enter to continue)"
kubectl delete secret $secretname
fi
read -r -p "Enter email: " email
read -r -p "Enter username: " user
read -r -s -p "Enter password / token: " pass
echo
kubectl create secret docker-registry $secretname \
--docker-server=$dockerserver \
--docker-email="$email" \
--docker-username="$user" \
--docker-password="$pass"
}
# Main function --------------------------------------------------------
main() {
local action
local arg
if [[ $# -eq 0 ]]; then
usage
exit 1
fi
while (( $# )); do
arg=$1
case $arg in
-u|--user)
shift
user=$1
;;
-r|--repository)
shift
repository=$1
;;
deploy|secret|configmap)
action=$arg
shift $(( $# - 1 ))
;;
*)
usage
exit 1
;;
esac
shift
done
if [[ -z "$action" ]]; then
usage
exit 1
fi
$action
}
# Execution start ------------------------------------------------------
main "$@"