-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·72 lines (61 loc) · 2.99 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·72 lines (61 loc) · 2.99 KB
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
#!/usr/bin/env bash
## Deploy the example controller to Kubernetes cluster.
##
## Requires a running Kubernetes cluster and kubectl to be installed.
set -u
YELLOW='\033[1;33m'
GREEN='\033[1;32m'
RED='\033[0;31m'
NC='\033[0m'
app=$(echo "$1" | tr '_' '-') # should be the controller's name (with words separated by dashes)
app_filename=$(echo "$app" | tr '-' '_')
cluster_name="${app}-e2e"
registry=$2 # should be either remote or local
kind get clusters | grep $cluster_name > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo -e "${YELLOW}A kind cluster named \"$cluster_name\" already exists. Deleting...${NC}"
kind delete cluster --name $cluster_name
fi
set -eu
# Set up the kind cluster and load the image into the cluster
kind create cluster --config deploy/kind.yaml --name $cluster_name
kind load docker-image local/$app-controller:v0.1.0 --name $cluster_name
# for VDeployment, need to deploy VReplicaSet as a dependency
if [ "$app" == "vdeployment" ]; then
kind load docker-image local/vreplicaset-controller:v0.1.0 --name $cluster_name
elif [ "$app" == "rabbitmq" ]; then
kind load docker-image local/vstatefulset-controller:v0.1.0 --name $cluster_name
fi
# admission controller has a different deployment process
if [ $(echo $app | awk -F'-' '{print $NF}') == "admission" ]; then
app=${app%-admission}
app_filename=${app_filename%_admission}
set -o pipefail
kubectl create -f deploy/${app_filename}/crd.yaml
echo "Creating Webhook Server Certs"
mkdir -p certs
openssl genrsa -out certs/tls.key 2048
openssl req -new -key certs/tls.key -out certs/tls.csr -subj "/CN=admission-server.default.svc"
openssl x509 -req -extfile <(printf "subjectAltName=DNS:admission-server.default.svc") -in certs/tls.csr -signkey certs/tls.key -out certs/tls.crt
echo "Creating Webhook Server TLS Secret"
kubectl create secret tls admission-server-tls \
--cert "certs/tls.crt" \
--key "certs/tls.key"
echo "Creating Webhook Server Deployment"
sed -e 's@${APP}@'"${app}-admission-controller"'@g' <"e2e/manifests/admission_server.yaml" | kubectl create -f -
CA_PEM64="$(openssl base64 -A < certs/tls.crt)"
echo "Creating K8s Webhooks"
sed -e 's@${CA_PEM_B64}@'"$CA_PEM64"'@g' -e 's@${RESOURCE}@'"${app#}"s'@g' <"e2e/manifests/admission_webhooks.yaml" | kubectl create -f -
exit 0
fi
if cd deploy/$app_filename && { for crd in $(ls crd*.yaml); do kubectl create -f "$crd"; done } && kubectl apply -f rbac.yaml && kubectl apply -f deploy_$registry.yaml; then
echo ""
echo -e "${GREEN}The $app controller is deployed in your Kubernetes cluster in namespace \"$app\".${NC}"
echo -e "${GREEN}Run \"kubectl get pod -n $app\" to check the controller pod.${NC}"
echo -e "${GREEN}Run \"kubectl apply -f deploy/$app_filename/$app_filename.yaml\" to deploy the cluster custom resource(s).${NC}"
else
echo ""
echo -e "${RED}Cannot deploy the controller.${NC}"
echo -e "${YELLOW}Please ensure kubectl can connect to a Kubernetes cluster.${NC}"
exit 3
fi