| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 1 | #!/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 | |
| 16 | set -x |
| 17 | |
| 18 | # main |
| 19 | while 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 |
| 54 | done |
| 55 | |
| 56 | DEBUG_INSTALL=${DEBUG_INSTALL:-} |
| 57 | OSM_DEVOPS=${OSM_DEVOPS:-"/usr/share/osm-devops"} |
| 58 | OSM_HOME_DIR=${OSM_HOME_DIR:-"$HOME/.osm"} |
| 59 | OSM_MGMTCLUSTER_BASE_FOLDER="${OSM_DEVOPS}/installers/mgmt-cluster" |
| 60 | INSTALL_MGMT_CLUSTER=${INSTALL_MGMT_CLUSTER:-"y"} |
| 61 | INSTALL_AUX_CLUSTER=${INSTALL_AUX_CLUSTER:-"y"} |
| 62 | KUBECONFIG_MGMT_CLUSTER=${KUBECONFIG_MGMT_CLUSTER:-"$HOME/.kube/config"} |
| 63 | KUBECONFIG_AUX_CLUSTER=${KUBECONFIG_AUX_CLUSTER:-"$HOME/.kube/config"} |
| 64 | KUBECONFIG_OLD=${KUBECONFIG:-"$HOME/.kube/config"} |
| 65 | export CREDENTIALS_DIR="${OSM_HOME_DIR}/.credentials" |
| 66 | export WORK_REPOS_DIR="${OSM_HOME_DIR}/repos" |
| garciadeblas | 10944e8 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 67 | export INSTALL_MINIO=${INSTALL_MINIO:-"y"} |
| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 68 | echo "DEBUG_INSTALL=$DEBUG_INSTALL" |
| 69 | echo "OSM_DEVOPS=$OSM_DEVOPS" |
| 70 | echo "OSM_HOME_DIR=$OSM_HOME_DIR" |
| 71 | echo "OSM_MGMTCLUSTER_BASE_FOLDER=$OSM_MGMTCLUSTER_BASE_FOLDER" |
| 72 | echo "INSTALL_MGMT_CLUSTER=$INSTALL_MGMT_CLUSTER" |
| 73 | echo "INSTALL_AUX_CLUSTER=$INSTALL_AUX_CLUSTER" |
| 74 | echo "KUBECONFIG_MGMT_CLUSTER=$KUBECONFIG_MGMT_CLUSTER" |
| 75 | echo "KUBECONFIG_AUX_CLUSTER=$KUBECONFIG_AUX_CLUSTER" |
| 76 | echo "CREDENTIALS_DIR=$CREDENTIALS_DIR" |
| 77 | echo "WORK_REPOS_DIR=$WORK_REPOS_DIR" |
| 78 | |
| 79 | source $OSM_DEVOPS/common/logging |
| 80 | source $OSM_DEVOPS/common/track |
| 81 | |
| 82 | pushd $OSM_MGMTCLUSTER_BASE_FOLDER |
| 83 | |
| 84 | if [ -n "${INSTALL_AUX_CLUSTER}" ] || [ -n "${INSTALL_MGMT_CLUSTER}" ]; then |
| 85 | |
| 86 | echo "Setup CLI tools for mgmt and aux cluster" |
| garciadeblas | 10944e8 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 87 | ./setup-cli-tools.sh || FATAL_TRACK mgmtcluster "setup-cli-tools.sh failed" |
| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 88 | 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." |
| garciadeblas | 10944e8 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 97 | 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 |
| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 100 | 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 | |
| 112 | fi |
| 113 | |
| garciadeblas | 10944e8 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 114 | set +x |
| 115 | |
| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 116 | # "aux-svc" cluster |
| 117 | if [ -n "${INSTALL_AUX_CLUSTER}" ]; then |
| 118 | echo "Provisioning auxiliary cluster with Gitea" |
| 119 | export KUBECONFIG="${KUBECONFIG_AUX_CLUSTER}" |
| garciadeblas | 10944e8 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 120 | ./01-provision-aux-svc.sh || FATAL_TRACK mgmtcluster "provision-aux-svc.sh failed" |
| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 121 | track mgmtcluster aux_cluster_ok |
| 122 | |
| garciadeblas | 10944e8 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 123 | ./02-provision-local-git-user.sh || FATAL_TRACK mgmtcluster "provision-local-git-user.sh failed" |
| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 124 | track mgmtcluster local_git_user_ok |
| 125 | fi |
| 126 | |
| 127 | # "mgmt" cluster |
| 128 | if [ -n "${INSTALL_MGMT_CLUSTER}" ]; then |
| 129 | echo "Provisioning mgmt cluster" |
| 130 | export KUBECONFIG="${KUBECONFIG_MGMT_CLUSTER}" |
| garciadeblas | 10944e8 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 131 | ./03-provision-mgmt-cluster.sh || FATAL_TRACK mgmtcluster "provision-mgmt-cluster.sh failed" |
| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 132 | track mgmtcluster mgmt_cluster_ok |
| 133 | fi |
| 134 | |
| 135 | export KUBECONFIG=${KUBECONFIG_OLD} |
| 136 | if [ -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" |
| 139 | fi |
| 140 | |
| 141 | echo "Creating secrets with kubeconfig files" |
| 142 | kubectl -n osm create secret generic auxcluster-secret --from-file=kubeconfig="${KUBECONFIG_AUX_CLUSTER}" |
| 143 | kubectl -n osm create secret generic mgmtcluster-secret --from-file=kubeconfig="${KUBECONFIG_MGMT_CLUSTER}" |
| 144 | |
| 145 | popd |
| 146 | |