-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdeploy-cima.sh
executable file
·161 lines (135 loc) · 4.18 KB
/
deploy-cima.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
DOCKER_REPO=docker.io/library
NFD_NAME=node-feature-discovery
NFD_NS=node-feature-discovery
NFD_URL=https://kubernetes-sigs.github.io/node-feature-discovery/charts
CERT_MANAGER_URL=https://github.com/cert-manager/cert-manager/releases/download/v1.14.5/cert-manager.yaml
WORK_DIR=$(cd "$(dirname "$0")" || exit; pwd)
tag=latest
delete_force=false
function usage {
cat << EOM
usage: $(basename "$0") [OPTION]...
-r <registry prefix> the prefix string for registry
-g <tag> container image tag
-d Delete existing CIMA and install new CIMA
EOM
exit 1
}
function process_args {
while getopts ":r:g:hd" option; do
case "${option}" in
r) registry=${OPTARG};;
g) tag=${OPTARG};;
d) delete_force=true;;
h) usage;;
*) echo "Invalid option: -${OPTARG}" >&2
usage
;;
esac
done
if [[ -z "$registry" ]]; then
echo "Error: Please specify your docker registry via -r <registry prefix>."
exit 1
fi
}
function check_env {
if ! command -v helm &> /dev/null
then
echo "Helm could not be found. Please install Helm."
exit
fi
if ! command -v kubectl &> /dev/null
then
echo "Kubectl could not be found. Please install K8S."
exit
fi
}
function delete_cima {
pushd "${WORK_DIR}/../../.." || exit
echo "-----------Delete cima webhook and server..."
kubectl delete -f deployment/kubernetes/manifests/cima-webhook-deployment.yaml
kubectl delete -f deployment/kubernetes/manifests/cima-server-deployment.yaml
echo "-----------Delete cima namespace..."
kubectl delete -f deployment/kubernetes/manifests/namespace.yaml
echo "-----------Delete NFD, cert-manager..."
helm uninstall $NFD_NAME --namespace $NFD_NS
kubectl delete -f $CERT_MANAGER_URL
popd || exit
}
function deploy_cima {
pushd "${WORK_DIR}/../../.." || exit
# Generate temporary yaml files for deployment
mkdir -p temp_manifests
cp -r deployment/kubernetes/manifests/* temp_manifests/
# If private repo is used, modify the images' names in the yaml files
if [[ -n "$registry" ]]; then
sed -i "s#${DOCKER_REPO}#${registry}#g" temp_manifests/*.yaml
fi
if [[ "$tag" != "latest" ]]; then
sed -i "s#latest#${tag}#g" temp_manifests/*.yaml
fi
# Deploy CIMA Dependencies
helm repo add nfd $NFD_URL
helm repo update
helm install $NFD_NAME nfd/node-feature-discovery --namespace $NFD_NS --create-namespace
kubectl create -f $CERT_MANAGER_URL
# Check the cert manager
curl -fsSL -o cmctl https://github.com/cert-manager/cmctl/releases/download/v2.0.0/cmctl_linux_amd64
chmod +x cmctl
while :
do
CMCTL=$(./cmctl check api | grep "is ready")
if [[ -z "$CMCTL" ]]
then
echo "cert-manager is not ready, try again..."
sleep 5
else
break
fi
done
rm cmctl
# Deploy CIMA webhook
echo "-----------Deploy cima namespace..."
kubectl create -f temp_manifests/namespace.yaml
kubectl create -f temp_manifests/cima-webhook-deployment.yaml
# Deploy CIMA services
echo "-----------Deploy cima server..."
kubectl create -f temp_manifests/cima-server-deployment.yaml
rm -rf temp_manifests
popd || exit
}
function check_cima_deployment {
# Check CIMA server pod
echo "-----------Checking cima server pod..."
for i in {1..10}
do
CIMA_SERVER_POD=$(kubectl get po -n cima | grep cima-server | grep Running | awk '{ print $1 }')
if [[ -z "$CIMA_SERVER_POD" ]]
then
sleep 3
echo "Retrying $i time ..."
else
break
fi
done
if [ -z "$CIMA_SERVER_POD" ]; then
echo "Error: CIMA server pod is not Running."
exit 1
fi
echo "CIMA server pod $CIMA_SERVER_POD is Running."
}
check_env
process_args "$@"
echo ""
echo "-------------------------"
echo "tag: ${tag}"
echo "registry: ${registry}"
echo "delete_force: ${delete_force}"
echo "-------------------------"
echo ""
if [[ $delete_force == true ]]; then
delete_cima
fi
deploy_cima
check_cima_deployment