-
Notifications
You must be signed in to change notification settings - Fork 251
/
Copy pathgenerate_k8s_yamls.sh
74 lines (61 loc) · 2.7 KB
/
generate_k8s_yamls.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
#!/bin/sh
#abort on error
set -e
function usage
{
echo "usage: sh tools/generate_k8s_yaml.sh --SOME_ARG ARG_VALUE"
echo " ";
echo " --app_name : app name";
echo " --image_name : image name";
echo " --workdir : workdir in image";
echo " --command : command to launch serving"
echo " --port : serving port"
echo " --pod_num : number of pod replicas"
echo " -h | --help : helper";
}
function parse_args
{
# positional args
args=()
# default
pod_num=1
# named args
while [ "$1" != "" ]; do
case "$1" in
--app_name ) app_name="$2"; shift;;
--image_name ) image_name="$2"; shift;;
--workdir ) workdir="$2"; shift;;
--command ) start_command="$2"; shift;;
--port ) port="$2"; shift;;
--pod_num ) pod_num="$2"; shift;;
-h | --help ) usage; exit;; # quit and show usage
* ) args+=("$1") # if no match, add it to the positional args
esac
shift # move to next kv pair
done
# restore positional args
set -- "${args[@]}"
# set positionals to vars
positional_1="${args[0]}"
positional_2="${args[1]}"
# validate required args
if [[ -z "${app_name}" || -z "${image_name}" || -z "${workdir}" || -z "${start_command}" || -z "${port}" || -z "${pod_num}"]]; then
echo "Invalid arguments. check your params again."
usage
exit;
fi
}
function run
{
parse_args "$@"
echo "named arg: app_name: $app_name"
echo "named arg: image_name: $image_name"
echo "named arg: workdir: $workdir"
echo "named arg: command: $start_command"
echo "named arg: port: $port"
echo "named arg: pod_num: $pod_num"
sed -e "s/<< APP_NAME >>/$app_name/g" -e "s/<< IMAGE_NAME >>/$(echo $image_name | sed -e 's/\\/\\\\/g; s/\//\\\//g; s/&/\\\&/g')/g" -e "s/<< WORKDIR >>/$(echo $workdir | sed -e 's/\\/\\\\/g; s/\//\\\//g; s/&/\\\&/g')/g" -e "s/<< COMMAND >>/\"$(echo $start_command | sed -e 's/\\/\\\\/g; s/\//\\\//g; s/&/\\\&/g')\"/g" -e "s/<< PORT >>/$port/g" tools/k8s_serving.yaml_template > k8s_serving.yaml
sed -e "s/<< APP_NAME >>/$app_name/g" -e "s/<< IMAGE_NAME >>/$(echo $image_name | sed -e 's/\\/\\\\/g; s/\//\\\//g; s/&/\\\&/g')/g" -e "s/<< WORKDIR >>/$(echo $workdir | sed -e 's/\\/\\\\/g; s/\//\\\//g; s/&/\\\&/g')/g" -e "s/<< COMMAND >>/\"$(echo $start_command | sed -e 's/\\/\\\\/g; s/\//\\\//g; s/&/\\\&/g')\"/g" -e "s/<< PORT >>/$port/g" tools/k8s_ingress.yaml_template > k8s_ingress.yaml
echo "check k8s_serving.yaml and k8s_ingress.yaml please."
}
run "$@";