Debian Codegraph @

examples/kind-multinode/quickstart-kind.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 set -e
4
5 # DEFAULT ARGS
6 CLUSTER_NAME="knp-test-cluster"
7 AGENT_IMAGE="gcr.io/k8s-staging-kas-network-proxy/proxy-agent:master"
8 SERVER_IMAGE="gcr.io/k8s-staging-kas-network-proxy/proxy-server:master"
9 NUM_WORKER_NODES=1
10 NUM_KCP_NODES=2
11 OVERWRITE_CLUSTER=false
12 SIDELOAD_IMAGES=false
13 SERVER_COUNT_OVERRIDE=-1
14
15 # Provide usage info
16 usagescip-shell shell shell-project 0.0.0 usage().() {
17 printfscip-shell system . . printf. "USAGE:\n./quickstart-kind.sh\n\t[--cluster-name <NAME>]\n\t[--server-image <IMAGE_NAME>[:<IMAGE_TAG>]]\n\t[--agent-image <IMAGE_NAME>[:<IMAGE_TAG>]]\n\t[--num-worker-nodes <NUM>]\n\t[--num-kcp-nodes <NUM>]\n\t[--overwrite-cluster]\n"
18 }
19
20 # ARG PARSING
21 VALID_ARGS=$(getoptscip-shell system . . getopt. --options "h" --longoptions "sideload-images,cluster-name:,agent-image:,server-image:,num-worker-nodes:,num-kcp-nodes:,help,overwrite-cluster,server-count-override:" --name "$0" -- "$@") || exit 2
22
23 eval set -- "$VALID_ARGS"
24 while truescip-shell system . . true.; do
25 case "$1" in
26 --cluster-name)
27 CLUSTER_NAME=$2
28 shift 2
29 ;;
30 --agent-image)
31 AGENT_IMAGE=$2
32 shift 2
33 ;;
34 --server-image)
35 SERVER_IMAGE=$2
36 shift 2
37 ;;
38 --num-worker-nodes)
39 NUM_WORKER_NODES=$2
40 shift 2
41 ;;
42 --num-kcp-nodes)
43 NUM_KCP_NODES=$2
44 shift 2
45 ;;
46 --overwrite-cluster)
47 OVERWRITE_CLUSTER=true
48 shift 1
49 ;;
50 --sideload-images)
51 SIDELOAD_IMAGES=true
52 shift 1
53 ;;
54 --server-count-override)
55 SERVER_COUNT_OVERRIDE=$2
56 shift 2
57 ;;
58 --)
59 shift
60 break
61 ;;
62 *|-h|--help)
63 usagescip-shell shell shell-project 0.0.0 usage().
64 exit
65 ;;
66 esac
67 done
68
69 # RENDER CONFIG TEMPLATES
70 echoscip-shell system . . echo. "Rendering config templates..."
71 if [scip-shell system . . `[`. ! -d rendered ]; then
72 echoscip-shell system . . echo. "Creating ./rendered"
73 mkdirscip-shell system . . mkdir. rendered
74 fi
75 echoscip-shell system . . echo. "Adding $NUM_KCP_NODES control plane nodes and $NUM_WORKER_NODES worker nodes to kind.config..."
76 cpscip-shell system . . cp. templates/kind/kind.config rendered/kind.config
77 for i in $(seqscip-shell system . . seq. 1 "$NUM_KCP_NODES")
78 do
79 catscip-shell system . . cat. templates/kind/control-plane.config >> rendered/kind.config
80 done
81 for i in $(seqscip-shell system . . seq. 1 "$NUM_WORKER_NODES")
82 do
83 catscip-shell system . . cat. templates/kind/worker.config >> rendered/kind.config
84 done
85
86 SERVER_COUNT=$NUM_KCP_NODES
87 if [scip-shell system . . `[`. "$SERVER_COUNT_OVERRIDE" -ge 0 ]; then
88 echoscip-shell system . . echo. "Overriding default server count from $NUM_KCP_NODES to $SERVER_COUNT_OVERRIDE"
89 SERVER_COUNT=$SERVER_COUNT_OVERRIDE
90 fi
91
92 echoscip-shell system . . echo. "Setting server image to $SERVER_IMAGE, agent image to $AGENT_IMAGE, and --server-count flag on server to $SERVER_COUNT"
93 sedscip-shell system . . sed. -e "s|image: .*|image: $AGENT_IMAGE|" <templates/k8s/konnectivity-agent-ds.yaml >rendered/konnectivity-agent-ds.yaml
94 sedscip-shell system . . sed. -e "s|image: .*|image: $SERVER_IMAGE|" -e "s/--server-count=[0-9]\+/--server-count=$SERVER_COUNT/" <templates/k8s/konnectivity-server.yaml >rendered/konnectivity-server.yaml
95
96
97
98 # CLUSTER CREATION
99 if [scip-shell system . . `[`. $OVERWRITE_CLUSTER = true ] && kind get clusters | grepscip-shell system . . grep. -q "$CLUSTER_NAME"; then
100 echoscip-shell system . . echo. "Deleting old cluster $CLUSTER_NAME..."
101 kind delete clusters "$CLUSTER_NAME"
102 fi
103
104 echoscip-shell system . . echo. "Creating cluster $CLUSTER_NAME..."
105 kind create cluster --config rendered/kind.config --name $CLUSTER_NAME
106
107 echoscip-shell system . . echo. "Successfully created cluster. Switching kubectl context to kind-$CLUSTER_NAME"
108 kubectl cluster-info --context kind-$CLUSTER_NAME
109
110 # SIDELOAD IMAGES IF REQUESTED
111 if [scip-shell system . . `[`. $SIDELOAD_IMAGES = true ]; then
112 echoscip-shell system . . echo. "Sideloading images into the kind cluster..."
113 kind --name "$CLUSTER_NAME" load docker-image "$SERVER_IMAGE"
114 kind --name "$CLUSTER_NAME" load docker-image "$AGENT_IMAGE"
115 fi
116
117 # DEPLOY KONNECTIVITY
118 echoscip-shell system . . echo. "Requesting creation of konnectivity proxy servers on cluster $CLUSTER_NAME..."
119 kubectl apply -f rendered/konnectivity-server.yaml
120 echoscip-shell system . . echo. "Requesting creation of konnectivity proxy agents on cluster $CLUSTER_NAME..."
121 kubectl apply -f rendered/konnectivity-agent-ds.yaml