blob: c719b4b6088fbea3f13c6e853b4fe7a1f8f2f7e8 [file] [log] [blame]
garciadeblas8d8cd992024-05-21 16:04:14 +02001#!/bin/bash
2#
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
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
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.
14#
15
16set -x
17
18# main
19while getopts ":D:d:G:M:-: " o; do
20 case "${o}" in
21 d)
22 OSM_HOME_DIR="${OPTARG}"
23 ;;
24 D)
25 OSM_DEVOPS="${OPTARG}"
26 ;;
27 M)
28 KUBECONFIG_MGMT_CLUSTER="${OPTARG}"
29 ;;
30 G)
31 KUBECONFIG_AUX_CLUSTER="${OPTARG}"
32 ;;
33 -)
34 [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="y" && continue
35 [ "${OPTARG}" == "no-mgmt-cluster" ] && INSTALL_MGMT_CLUSTER="" && continue
36 [ "${OPTARG}" == "no-aux-cluster" ] && INSTALL_AUX_CLUSTER="" && continue
37 [ "${OPTARG}" == "minio" ] && INSTALL_MINIO="y" && continue
38 [ "${OPTARG}" == "no-minio" ] && INSTALL_MINIO="" && continue
39 echo -e "Invalid option: '--$OPTARG'\n" >&2
40 exit 1
41 ;;
42 :)
43 echo "Option -$OPTARG requires an argument" >&2
44 exit 1
45 ;;
46 \?)
47 echo -e "Invalid option: '-$OPTARG'\n" >&2
48 exit 1
49 ;;
50 *)
51 exit 1
52 ;;
53 esac
54done
55
56DEBUG_INSTALL=${DEBUG_INSTALL:-}
57OSM_DEVOPS=${OSM_DEVOPS:-"/usr/share/osm-devops"}
58OSM_HOME_DIR=${OSM_HOME_DIR:-"$HOME/.osm"}
59OSM_MGMTCLUSTER_BASE_FOLDER="${OSM_DEVOPS}/installers/mgmt-cluster"
60INSTALL_MGMT_CLUSTER=${INSTALL_MGMT_CLUSTER:-"y"}
61INSTALL_AUX_CLUSTER=${INSTALL_AUX_CLUSTER:-"y"}
62KUBECONFIG_MGMT_CLUSTER=${KUBECONFIG_MGMT_CLUSTER:-"$HOME/.kube/config"}
63KUBECONFIG_AUX_CLUSTER=${KUBECONFIG_AUX_CLUSTER:-"$HOME/.kube/config"}
64KUBECONFIG_OLD=${KUBECONFIG:-"$HOME/.kube/config"}
65export CREDENTIALS_DIR="${OSM_HOME_DIR}/.credentials"
66export WORK_REPOS_DIR="${OSM_HOME_DIR}/repos"
garciadeblas10944e82024-05-21 16:04:14 +020067export INSTALL_MINIO=${INSTALL_MINIO:-"y"}
garciadeblas8d8cd992024-05-21 16:04:14 +020068echo "DEBUG_INSTALL=$DEBUG_INSTALL"
69echo "OSM_DEVOPS=$OSM_DEVOPS"
70echo "OSM_HOME_DIR=$OSM_HOME_DIR"
71echo "OSM_MGMTCLUSTER_BASE_FOLDER=$OSM_MGMTCLUSTER_BASE_FOLDER"
72echo "INSTALL_MGMT_CLUSTER=$INSTALL_MGMT_CLUSTER"
73echo "INSTALL_AUX_CLUSTER=$INSTALL_AUX_CLUSTER"
74echo "KUBECONFIG_MGMT_CLUSTER=$KUBECONFIG_MGMT_CLUSTER"
75echo "KUBECONFIG_AUX_CLUSTER=$KUBECONFIG_AUX_CLUSTER"
76echo "CREDENTIALS_DIR=$CREDENTIALS_DIR"
77echo "WORK_REPOS_DIR=$WORK_REPOS_DIR"
78
79source $OSM_DEVOPS/common/logging
80source $OSM_DEVOPS/common/track
81
82pushd $OSM_MGMTCLUSTER_BASE_FOLDER
83
84if [ -n "${INSTALL_AUX_CLUSTER}" ] || [ -n "${INSTALL_MGMT_CLUSTER}" ]; then
85
86 echo "Setup CLI tools for mgmt and aux cluster"
garciadeblas10944e82024-05-21 16:04:14 +020087 ./setup-cli-tools.sh || FATAL_TRACK mgmtcluster "setup-cli-tools.sh failed"
garciadeblas8d8cd992024-05-21 16:04:14 +020088 track mgmtcluster setupclitools_ok
89
90 echo "Creating folders under ${OSM_HOME_DIR} for credentials and repos"
91 mkdir -p "${CREDENTIALS_DIR}"
92 mkdir -p "${WORK_REPOS_DIR}"
93 track mgmtcluster folders_ok
94
95 # Test if the user exists. Otherwise, create a git user
96 echo "Test if there is a git user. Otherwise, create it."
garciadeblas10944e82024-05-21 16:04:14 +020097 if [ ! -n "$(git config user.name)" ]; then
98 git config --global user.name osm_user
99 git config --global user.email osm_user@mydomain.com
garciadeblas8d8cd992024-05-21 16:04:14 +0200100 fi
101
102 # Test if the user exists. Otherwise, create a git user
103 echo "Checking if the user has an SSH key pair"
104 if [ ! -f "$HOME/.ssh/id_rsa" ]; then
105 echo "Generating an SSH key pair for the user"
106 ssh-keygen -t rsa -f "$HOME/.ssh/id_rsa" -N "" -q
107 fi
108
109 echo "Loading env variables from 00-base-config.rc"
110 source 00-base-config.rc
111
112fi
113
garciadeblas10944e82024-05-21 16:04:14 +0200114set +x
115
garciadeblas8d8cd992024-05-21 16:04:14 +0200116# "aux-svc" cluster
117if [ -n "${INSTALL_AUX_CLUSTER}" ]; then
118 echo "Provisioning auxiliary cluster with Gitea"
119 export KUBECONFIG="${KUBECONFIG_AUX_CLUSTER}"
garciadeblas10944e82024-05-21 16:04:14 +0200120 ./01-provision-aux-svc.sh || FATAL_TRACK mgmtcluster "provision-aux-svc.sh failed"
garciadeblas8d8cd992024-05-21 16:04:14 +0200121 track mgmtcluster aux_cluster_ok
122
garciadeblas10944e82024-05-21 16:04:14 +0200123 ./02-provision-local-git-user.sh || FATAL_TRACK mgmtcluster "provision-local-git-user.sh failed"
garciadeblas8d8cd992024-05-21 16:04:14 +0200124 track mgmtcluster local_git_user_ok
125fi
126
127# "mgmt" cluster
128if [ -n "${INSTALL_MGMT_CLUSTER}" ]; then
129 echo "Provisioning mgmt cluster"
130 export KUBECONFIG="${KUBECONFIG_MGMT_CLUSTER}"
garciadeblas10944e82024-05-21 16:04:14 +0200131 ./03-provision-mgmt-cluster.sh || FATAL_TRACK mgmtcluster "provision-mgmt-cluster.sh failed"
garciadeblas8d8cd992024-05-21 16:04:14 +0200132 track mgmtcluster mgmt_cluster_ok
133fi
134
135export KUBECONFIG=${KUBECONFIG_OLD}
136if [ -n "${INSTALL_MGMT_CLUSTER}" ]; then
137 echo "Saving age keys in OSM cluster"
138 kubectl -n osm create secret generic mgmt-cluster-age-keys --from-file=privkey="${CREDENTIALS_DIR}/age.mgmt.key" --from-file=pubkey="${CREDENTIALS_DIR}/age.mgmt.pub"
139fi
140
141echo "Creating secrets with kubeconfig files"
142kubectl -n osm create secret generic auxcluster-secret --from-file=kubeconfig="${KUBECONFIG_AUX_CLUSTER}"
143kubectl -n osm create secret generic mgmtcluster-secret --from-file=kubeconfig="${KUBECONFIG_MGMT_CLUSTER}"
144
145popd
146