-
Notifications
You must be signed in to change notification settings - Fork 3
/
install_cnp.sh
executable file
·181 lines (147 loc) · 4.54 KB
/
install_cnp.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
# Author : Sergio Romera
# Created : 10/03/2022
# Description : Install CNP cluster
. ./config_cnp.sh
function check_deployment()
{
status=0
sp="/-\|"
while [ $status -ne 1 ]
do
printf "\b${sp:i++%${#sp}:1}"
status=`kubectl get deploy -n postgresql-operator-system postgresql-operator-controller-manager | sed -n 2p | awk '{print $4}'`
sleep 1
done
printf "\b"
msg "kubectl get deploy -n postgresql-operator-system postgresql-operator-controller-manager"
kubectl get deploy -n postgresql-operator-system postgresql-operator-controller-manager -o wide
}
function check_cluster()
{
status=0
counter=1
instances=0
instances=`grep instances ${cluster_file1} | awk '{print $2}' | cut -c1`
sp="/-\|"
#sleep 5
#msg "kubectl cnp status ${cluster_name}"
while [ $status -ne $instances ]
do
sleep 1
status=`echo $status | xargs`
printf "\rNumber of pods created: $status ${sp:i++%${#sp}:1}"
#"^[[32m3^[[0m"
if [ `expr $counter % 5` -eq 0 ]; then
status=`kubectl cnp status ${cluster_name} | grep 'Ready' | awk '{print $3}' | cut -c6`
if [ -z "$status" ]; then
status=0
fi
#status=${status:5:1}
#echo "yes"
fi
(( counter++ ))
done
status=`echo $status | xargs`
printf "\b\rNumber of pods created: $status"
printf "\n"
}
function install_plugin()
{
msg "curl -sSfL ${plugging} | sh -s -- -b /usr/local/bin"
curl -sSfL ${plugging} | sh -s -- -b /usr/local/bin
}
function install_cnp_operator()
{
msg "kubectl apply -f ${operator}"
kubectl apply -f ${operator}
sleep 2
}
function msg()
{
printf "${c_green}$1${c_r}\n"
}
function install_minio_client()
{
if [ "${OBJECT_STORAGE}" == "MINIO" ]; then
#cat install_minio_docker_client.sh | \
#docker run --name my-mc --hostname my-mc -e hostname=`hostname` -i --entrypoint /bin/bash --rm minio/mc
if [ `ps -edf | grep minio/minio | grep -v grep | wc -l` -eq 0 ]; then
printf "/!\ MINIO not started\n"
printf "Please, start MINIO (start_minio_docker_server.sh) and execute again\n"
exit
fi
fi
}
function object_storage_config ()
{
if [ ${OBJECT_STORAGE} == "MINIO" ]; then
install_minio_client
printf "MinIO started\n"
cp ${S3_MINIO_DIRECTORY}/*.yaml .
fi
if [ ${OBJECT_STORAGE} == "AWS" ]; then
echo "AWS S3 config"
cp ${S3_AWS_DIRECTORY}/*.yaml .
fi
}
function replace_config()
{
# MINIO
sed -i '' -e "s|###IMAGENAME###|${IMAGENAME}|g" cluster*.yaml
sed -i '' -e "s|###MINIO_DESTINATIONPATH###|${MINIO_DESTINATIONPATH}|g" cluster*.yaml
sed -i '' -e "s|###MINIO_ENDPOINTURL###|${MINIO_ENDPOINTURL}|g" cluster*.yaml
#S3
sed -i '' -e "s|###IMAGENAME###|${IMAGENAME}|g" cluster*.yaml
sed -i '' -e "s|###S3_DESTINATIONPATH###|${S3_DESTINATIONPATH}|g" cluster*.yaml
}
#Install CNP
start=$SECONDS
echo "********************************"
echo "*** Configure Object Storage ***"
echo "********************************"
object_storage_config
echo "*******************************"
echo "*** Installing CNP Plugging ***"
echo "*******************************"
install_plugin
echo "*******************************"
echo "*** Installing CNP Operator ***"
echo "*******************************"
install_cnp_operator
echo "***********************************"
echo "*** Verify install CNP Operator ***"
echo "***********************************"
check_deployment
echo "***************************"
echo "*** Install secrets AWS ***"
echo "***************************"
. ./install_secrets.sh
sleep 2
echo "**********************"
echo "*** Replace config ***"
echo "**********************"
replace_config
echo "***********************"
echo "*** Install cluster ***"
echo "***********************"
msg "kubectl apply -f ${cluster_file1}"
kubectl apply -f ${cluster_file1}
check_cluster
echo "***************************"
echo "*** Show cluster status ***"
echo "***************************"
kubectl cnp status ${cluster_name}
end=$SECONDS
echo "Duration: "
echo "***********************************************"
echo "*** Installation successfully in $((end-start)) seconds ***"
echo "***********************************************"
echo "Execute this command to check the cluster status:"
echo ""
msg "kubectl cnp status ${cluster_name}"
echo ""
# curl -sSfL https://github.com/EnterpriseDB/kubectl-cnp/raw/main/install.sh | sh -s -- -b /usr/local/bin
# kubectl apply -f https://get.enterprisedb.io/cnp/postgresql-operator-1.14.0.yaml
# kubectl get deploy -n postgresql-operator-system postgresql-operator-controller-manager
# kubectl apply -f cluster1.yaml