3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 JUJU_AGENT_VERSION
=2.8.6
19 K8S_CLOUD_NAME
="k8s-cloud"
20 KUBECTL
="microk8s.kubectl"
22 IMAGES_OVERLAY_FILE
=~
/.osm
/images-overlay.yaml
23 PATH
=/snap
/bin
:${PATH}
25 function check_arguments
(){
26 while [ $# -gt 0 ] ; do
28 --bundle) BUNDLE
="$2" ;;
29 --k8s) KUBECFG
="$2" ;;
30 --vca) CONTROLLER
="$2" ;;
31 --lxd) LXD_CLOUD
="$2" ;;
32 --lxd-cred) LXD_CREDENTIALS
="$2" ;;
33 --microstack) MICROSTACK
=y
;;
34 --ha) BUNDLE
="cs:osm-ha" ;;
36 --registry) REGISTRY_INFO
="$2" ;;
41 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
44 function install_snaps
(){
45 if [ ! -v KUBECFG
]; then
46 sudo snap
install microk8s
--classic --channel=${MICROK8S_VERSION}/stable
47 sudo usermod
-a -G microk8s
`whoami`
49 sudo chown
-f -R `whoami` ~
/.kube
51 sg
${KUBEGRP} -c "microk8s status --wait-ready"
54 sudo snap
install kubectl
--classic
55 export KUBECONFIG
=${KUBECFG}
58 sudo snap
install juju
--classic --channel=2.8/stable
61 function bootstrap_k8s_lxd
(){
62 [ -v CONTROLLER
] && ADD_K8S_OPTS
="--controller ${CONTROLLER}" && CONTROLLER_NAME
=$CONTROLLER
63 [ ! -v CONTROLLER
] && ADD_K8S_OPTS
="--client" && BOOTSTRAP_NEEDED
="yes" && CONTROLLER_NAME
="osm-vca"
65 if [ -v BOOTSTRAP_NEEDED
]; then
66 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
67 if [ $CONTROLLER_PRESENT -ge 1 ]; then
69 Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
70 You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
73 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
75 Please retry the installation once this conflict has been resolved.
80 CONTROLLER_PRESENT
=$
(juju controllers
2>/dev
/null|
grep ${CONTROLLER_NAME} |
wc -l)
81 if [ $CONTROLLER_PRESENT -le 0 ]; then
83 Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
84 that exists, or remove the --vca ${CONTROLLER_NAME} option.
86 Please retry the installation with one of the solutions applied.
92 if [ -v KUBECFG
]; then
93 cat $KUBECFG | juju add-k8s
$K8S_CLOUD_NAME $ADD_K8S_OPTS
94 [ -v BOOTSTRAP_NEEDED
] && juju bootstrap
$K8S_CLOUD_NAME $CONTROLLER_NAME \
95 --config controller-service-type
=loadbalancer \
96 --agent-version=$JUJU_AGENT_VERSION
98 sg
${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.
enable metallb
"
99 sg ${KUBEGRP} -c "microk8s.
enable ingress
"
100 sg ${KUBEGRP} -c "microk8s.
enable storage dns
"
102 start_time="$
(date -u +%s
)"
106 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
107 echo "Microk8s storage failed to
enable"
108 sg ${KUBEGRP} -c "microk8s.status
"
111 storage_status=`sg ${KUBEGRP} -c "microk8s.status
-a storage
"`
112 if [[ $storage_status == "enabled
" ]]; then
118 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config
" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
119 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
120 "juju bootstrap microk8s
$CONTROLLER_NAME --config controller-service-type
=loadbalancer
--agent-version=$JUJU_AGENT_VERSION" \
121 && K8S_CLOUD_NAME=microk8s
124 if [ -v LXD_CLOUD ]; then
125 if [ ! -v LXD_CREDENTIALS ]; then
126 echo "The installer needs the LXD server certificate
if the LXD is external
"
130 LXDENDPOINT=$DEFAULT_IP
131 LXD_CLOUD=~/.osm/lxd-cloud.yaml
132 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
133 # Apply sysctl production values for optimal performance
134 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
137 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
138 sudo snap install lxd
140 sudo usermod -a -G lxd `whoami`
141 cat /usr/share/osm-devops/installers/lxd-preseed.conf | sed 's/^config: {}/config:\n core.https_address: '$LXDENDPOINT':8443/' | sg lxd -c "lxd init
--preseed"
142 sg lxd -c "lxd waitready
"
143 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
144 sg lxd -c "lxc profile device
set default eth0 mtu
$DEFAULT_MTU"
145 sg lxd -c "lxc network
set lxdbr0 bridge.mtu
$DEFAULT_MTU"
147 cat << EOF > $LXD_CLOUD
151 auth-types: [certificate]
152 endpoint: "https
://$LXDENDPOINT:8443"
154 ssl-hostname-verification: false
156 openssl req -nodes -new -x509 -keyout ~/.osm/client.key -out ~/.osm/client.crt -days 365 -subj "/C
=FR
/ST
=Nice
/L
=Nice
/O
=ETSI
/OU
=OSM
/CN
=osm.etsi.org
"
157 local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
158 local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'`
159 local client_key=`cat ~/.osm/client.key | sed 's/^/ /'`
161 cat << EOF > $LXD_CREDENTIALS
165 auth-type: certificate
173 lxc config trust add local: ~/.osm/client.crt
176 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
177 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
178 sg lxd -c "lxd waitready
"
179 juju controller-config features=[k8s-operators]
182 function wait_for_port(){
186 start_time="$
(date -u +%s
)"
190 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
191 echo "Failed to expose external
${SERVICE} interface port
"
195 if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingresses.networking -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then
202 function deploy_charmed_osm(){
203 if [ -v REGISTRY_INFO ] ; then
204 registry_parts=(${REGISTRY_INFO//@/ })
205 if [ ${#registry_parts[@]} -eq 1 ] ; then
206 # No credentials supplied
209 REGISTRY_URL=${registry_parts[0]}
211 credentials=${registry_parts[0]}
212 credential_parts=(${credentials//:/ })
213 REGISTRY_USERNAME=${credential_parts[0]}
214 REGISTRY_PASSWORD=${credential_parts[1]}
215 REGISTRY_URL=${registry_parts[1]}
217 # Ensure the URL ends with a /
218 case $REGISTRY_URL in
220 *) REGISTRY_URL=${REGISTRY_URL}/
225 echo "Creating OSM model
"
226 if [ -v KUBECFG ]; then
227 juju add-model osm $K8S_CLOUD_NAME
229 sg ${KUBEGRP} -c "juju add-model osm
$K8S_CLOUD_NAME"
231 echo "Deploying OSM with charms
"
233 if [ -v REGISTRY_URL ]; then
234 [ ! -v TAG ] && TAG='latest'
236 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
238 if [ -v BUNDLE ]; then
239 juju deploy $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
241 juju deploy cs:osm --channel edge --overlay ~/.osm/vca-overlay.yaml $images_overlay
244 echo "Waiting
for deployment to finish...
"
246 echo "OSM with charms deployed
"
247 if [ ! -v KUBECFG ]; then
248 API_SERVER=${DEFAULT_IP}
250 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
251 proto="$
(echo $API_SERVER |
grep :// |
sed -e's,^\(.*://\).*,\1,g')"
252 url="$
(echo ${API_SERVER/$proto/})"
253 user="$
(echo $url |
grep @ | cut
-d@
-f1)"
254 hostport="$
(echo ${url/$user@/} | cut
-d/ -f1)"
255 API_SERVER="$
(echo $hostport |
sed -e 's,:.*,,g')"
258 # Expose OSM services
260 juju config grafana-k8s juju-external-hostname=grafana.${API_SERVER}.xip.io
261 juju expose grafana-k8s
262 wait_for_port grafana-k8s 0
265 juju config nbi-k8s juju-external-hostname=nbi.${API_SERVER}.xip.io
267 wait_for_port nbi-k8s 1
270 juju config ng-ui juju-external-hostname=ui.${API_SERVER}.xip.io
272 wait_for_port ng-ui 2
275 juju config prometheus-k8s juju-external-hostname=prometheus.${API_SERVER}.xip.io
276 juju expose prometheus-k8s
277 wait_for_port prometheus-k8s 3
280 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io
/backend-protocol
=HTTPS
-n osm
-l juju-app
=nbi-k8s
"
281 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io
/proxy-body-size
=0 -n osm
-l juju-app
=nbi-k8s
"
282 sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io
/proxy-body-size
=0 -n osm
-l juju-app
=ng-ui
"
285 function check_osm_deployed() {
287 start_time="$
(date -u +%s
)"
288 total_service_count=14
292 service_count=$(juju status | grep kubernetes | grep active | wc -l)
293 echo "$service_count / $total_service_count services active
"
294 if [ $service_count -eq $total_service_count ]; then
297 if [ $service_count -ne $previous_count ]; then
298 previous_count=$service_count
299 start_time="$
(date -u +%s
)"
302 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
303 echo "Timed out waiting
for OSM services to become ready
"
310 function create_overlay() {
312 sudo apt install python3-pip -y
313 python3 -m pip install yq
314 PATH=$PATH:$HOME/.local/bin # make yq command available
315 local HOME=/home/$USER
316 local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].user')
317 local vca_password=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].password')
318 local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["api-endpoints
"][0]' --raw-output | cut -d ":" -f 1)
319 local vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["api-endpoints
"][0]' --raw-output | cut -d ":" -f 2)
320 local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
321 local vca_cloud="lxd-cloud
"
322 # Get the VCA Certificate
323 local vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["ca-cert
"]' --raw-output | base64 | tr -d \\n)
325 # Calculate the default route of this machine
326 local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
328 # Generate a new overlay.yaml, overriding any existing one
329 cat << EOF > /tmp/vca-overlay.yaml
334 vca_password: $vca_password
337 vca_pubkey: $vca_pubkey
338 vca_cacert: $vca_cacert
339 vca_cloud: $vca_cloud
340 vca_k8s_cloud: $K8S_CLOUD_NAME
344 vca_password: $vca_password
346 vca_cacert: $vca_cacert
348 mv /tmp/vca-overlay.yaml ~/.osm/
349 OSM_VCA_HOST=$vca_host
352 function generate_images_overlay(){
353 if [ ! -z "$REGISTRY_USERNAME" ] ; then
354 REGISTRY_CREDENTIALS=$(cat <<EOF
356 image_username: $REGISTRY_USERNAME
357 image_password: $REGISTRY_PASSWORD
362 cat << EOF > /tmp/images-overlay.yaml
366 image: ${REGISTRY_URL}opensourcemano/lcm:$TAG ${REGISTRY_CREDENTIALS}
369 image: ${REGISTRY_URL}opensourcemano/mon:$TAG ${REGISTRY_CREDENTIALS}
372 image: ${REGISTRY_URL}opensourcemano/ro:$TAG ${REGISTRY_CREDENTIALS}
375 image: ${REGISTRY_URL}opensourcemano/nbi:$TAG ${REGISTRY_CREDENTIALS}
378 image: ${REGISTRY_URL}opensourcemano/pol:$TAG ${REGISTRY_CREDENTIALS}
381 image: ${REGISTRY_URL}opensourcemano/pla:$TAG ${REGISTRY_CREDENTIALS}
384 image: ${REGISTRY_URL}opensourcemano/ng-ui:$TAG ${REGISTRY_CREDENTIALS}
387 image: ${REGISTRY_URL}opensourcemano/keystone:$TAG ${REGISTRY_CREDENTIALS}
389 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
392 function install_osmclient() {
393 sudo snap install osmclient
394 sudo snap alias osmclient.osm osm
398 function install_microstack() {
399 sudo snap install microstack --classic --beta
400 sudo microstack.init --auto
401 wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
402 microstack.openstack image create \
404 --disk-format qcow2 \
405 --container-format bare \
406 --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
408 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
409 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
410 export OSM_HOSTNAME=`juju status --format json | jq -rc '.applications."nbi-k8s
".address'`
411 osm vim-create --name microstack-site \
413 --password keystone \
414 --auth_url http://10.20.20.1:5000/v3 \
416 --account_type openstack \
417 --config='{security_groups: default,
420 user_domain_name: default,
421 region_name: microstack,
423 availability_zone: nova,
427 DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
428 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
436 if [ -v MICROSTACK ]; then
440 OSM_HOSTNAME=$(juju config nbi-k8s juju-external-hostname):443
442 echo "Your installation is now complete
, follow these steps
for configuring the osmclient
:"
444 echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP
"
446 echo "export OSM_HOSTNAME
=$OSM_HOSTNAME"
448 echo "2. Add the previous
command to your .bashrc
for other Shell sessions
"
450 echo "echo \"export OSM_HOSTNAME
=$OSM_HOSTNAME\" >> ~
/.bashrc
"