forked from nholuongut/devops-basics
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopenstack-helm.sh
152 lines (128 loc) · 4.3 KB
/
openstack-helm.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
#!/bin/bash
set -e
# All in one scipt following this document: 'https://docs.openstack.org/openstack-helm/latest/install/index.html'
# Custom console log
GREEN='\033[0;32m'
# ANSI escape code to reset text color to default
RESET='\033[0m'
console_log() {
echo -e "${GREEN}>>> [Openstack] [Setup] $1${RESET}"
}
check_and_delete() {
namespace_name=$1
# Check if the namespace exists
if kubectl get namespace "$namespace_name" &>/dev/null; then
echo "Namespace '$namespace_name' exists. Deleting resources..."
kubectl delete --all --namespace "$namespace_name" || true
kubectl delete namespace "$namespace_name" || true
else
echo "Namespace '$namespace_name' does not exist."
# Add any handling or exit commands here if needed
fi
}
cleanup_namespaces() {
kubectl get namespaces
check_and_delete ceph
check_and_delete openstack
check_and_delete osh-infra
check_and_delete rook-ceph
}
format_and_execute() {
echo "Working on $1"
script_path=$1
sed -i -e 's/\r$//' $script_path
"${script_path}"
}
check_dos2unix() {
# Check if dos2unix is installed
if ! command -v dos2unix &>/dev/null; then
echo "dos2unix is not installed. Attempting to install..."
# Check the package manager and install dos2unix
if command -v apt-get &>/dev/null; then
sudo apt-get update
sudo apt-get install dos2unix -y
elif command -v yum &>/dev/null; then
sudo yum install dos2unix -y
elif command -v brew &>/dev/null; then
brew install dos2unix
else
echo "Unable to install dos2unix. Please install it manually."
exit 1
fi
fi
}
format_all_files() {
folder=$1
check_dos2unix
cd $folder
find ./tools/deployment -type f -exec dos2unix {} \;
}
DEPLOYMENT_DIR="/tmp/osh"
console_log "[Init] Before deployment"
mkdir -p $DEPLOYMENT_DIR
console_log "[Init] Cleanup previous k8s resources"
./cleanup.sh
console_log "[Init] Cleanup environment"
rm -rf "$DEPLOYMENT_DIR/openstack-helm/"
rm -rf "$DEPLOYMENT_DIR/openstack-helm-infra/"
cd $DEPLOYMENT_DIR
git clone https://opendev.org/openstack/openstack-helm.git
git clone https://opendev.org/openstack/openstack-helm-infra.git
pwd
ls -la
console_log "[Init] Configure environment"
export OPENSTACK_RELEASE=2023.2
export CONTAINER_DISTRO_NAME=ubuntu
export CONTAINER_DISTRO_VERSION=jammy
console_log "[Init] dos2unix formatting"
format_all_files "$DEPLOYMENT_DIR/openstack-helm"
format_all_files "$DEPLOYMENT_DIR/openstack-helm-infra"
# Prepare Kubernetes
console_log "Prepare Kubernetes"
cd "$DEPLOYMENT_DIR/openstack-helm"
ls -la
pwd
format_and_execute ./tools/deployment/common/prepare-k8s.sh
# Deploy Ceph
console_log "Deploy Ceph"
cd "$DEPLOYMENT_DIR/openstack-helm-infra"
ls -la
format_and_execute ./tools/deployment/ceph/ceph-rook.sh
format_and_execute ./tools/deployment/ceph/ceph-adapter-rook.sh
#Setup OpenStack client
console_log "Setup OpenStack client"
cd "$DEPLOYMENT_DIR/openstack-helm"
format_and_execute ./tools/deployment/common/setup-client.sh
# Traffic Routing to Ceph Rados Gateway Service
console_log "Traffic Routing to Ceph Rados Gateway Service"
cd "$DEPLOYMENT_DIR/openstack-helm"
format_and_execute ./tools/deployment/component/common/ingress.sh
# Deploy OpenStack backend
console_log "Deploy OpenStack backend"
cd "$DEPLOYMENT_DIR/openstack-helm"
format_and_execute ./tools/deployment/component/common/rabbitmq.sh
format_and_execute ./tools/deployment/component/common/mariadb.sh
format_and_execute ./tools/deployment/component/common/memcached.sh
# Deploy OpenStack
# Keystone
console_log "Keystone"
cd "$DEPLOYMENT_DIR/openstack-helm"
format_and_execute ./tools/deployment/component/keystone/keystone.sh
# Heat
console_log "Heat"
cd "$DEPLOYMENT_DIR/openstack-helm"
format_and_execute ./tools/deployment/component/heat/heat.sh
# Glance
cd "$DEPLOYMENT_DIR/openstack-helm"
format_and_execute ./tools/deployment/component/glance/glance.sh
# Placement, Nova, Neutron
console_log "Placement, Nova, Neutron"
cd "$DEPLOYMENT_DIR/openstack-helm"
format_and_execute ./tools/deployment/component/compute-kit/openvswitch.sh
format_and_execute ./tools/deployment/component/compute-kit/libvirt.sh
format_and_execute ./tools/deployment/component/compute-kit/compute-kit.sh
# Cinder
console_log "Cinder"
cd "$DEPLOYMENT_DIR/openstack-helm"
format_and_execute ./tools/deployment/component/cinder/cinder.sh
console_log "Congrats!"