blob: a7ab60822319f68888138fb8935c8601bd22e5c3 [file] [log] [blame]
garciadeblas8d8cd992024-05-21 16:04:14 +02001#!/bin/bash
2#######################################################################################
3# Copyright ETSI Contributors and Others.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14# implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#######################################################################################
18
19set -e -o pipefail
20
21# Warning!!!: Remember to select the desired kubeconfig profile before launching this script
22
garciadeblascf603f52025-06-04 11:57:28 +020023HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
24source "${HERE}/../library/functions.sh"
25source "${HERE}/../library/trap.sh"
garciadeblas8d8cd992024-05-21 16:04:14 +020026
garciadeblascf603f52025-06-04 11:57:28 +020027source "${HERE}/00-default-install-options.rc"
28[ ! -f "${OSM_HOME_DIR}/user-install-options.rc" ] || source "${OSM_HOME_DIR}/user-install-options.rc"
29echo "Loading env variables from 20-base-config.rc"
30source "${HERE}/20-base-config.rc"
31source "${CREDENTIALS_DIR}/git_environment.rc"
32
33# TODO: check git config
34# TODO: move this to a parent script that creates the VM
35mkdir -p "${OSM_HOME_DIR}/clusters"
36if [ -n "${KUBECONFIG_MGMT_CLUSTER}" ]; then
37 cp "${KUBECONFIG_MGMT_CLUSTER}" "${OSM_HOME_DIR}/clusters/kubeconfig-mgmt.yaml"
38else
39 cp "${HOME}/.kube/config" "${OSM_HOME_DIR}/clusters/kubeconfig-mgmt.yaml"
40fi
41
42export KUBECONFIG="${OSM_HOME_DIR}/clusters/kubeconfig-mgmt.yaml"
garciadeblas8d8cd992024-05-21 16:04:14 +020043
44############################ Clone repos
45m "\n#####################################################################" "${CYAN}"
46m "(1/8) Cloning relevant repos..." "${CYAN}"
47m "#####################################################################\n" "${CYAN}"
48
garciadeblas8d8cd992024-05-21 16:04:14 +020049# clone the relevant repos to well-known local folders
50"${HERE}/flux/scripts/clone-relevant-repos.sh"
51
52#####################################################################
53
54
55############################ Flux bootstrap
56m "\n#####################################################################" "${CYAN}"
57m "(2/8) Running Flux bootstrap on the management cluster..." "${CYAN}"
58m "#####################################################################\n" "${CYAN}"
59
60# Bootstrap
61"${HERE}/flux/scripts/mgmt-cluster-bootstrap.sh"
62
63# Pull the latest changes from the `fleet` repo
64git -C "${FLEET_REPO_DIR}" pull origin main
65
66#####################################################################
67
68
69############################ SOPS setup for the management cluster
70m "\n#####################################################################" "${CYAN}"
71m "(3/8) Setting up SOPS in the management cluster..." "${CYAN}"
72m "#####################################################################\n" "${CYAN}"
73
74# Create a new `age` key pair for the management cluster
75"${HERE}/flux/scripts/create-age-keypair.sh" "${AGE_KEY_NAME_MGMT}"
76
77# Add the `age` key pair to the cluster
78"${HERE}/flux/scripts/add-age-key-to-cluster.sh" \
79 "${AGE_KEY_NAME_MGMT}" \
80 "${FLEET_REPO_DIR}/clusters/_management"
81
82#####################################################################
83
84
85############################ Base kustomizations and default cluster profiles
86m "\n#####################################################################" "${CYAN}"
87m "(4/8) Creating base kustomizations and default cluster profiles..." "${CYAN}"
88m "#####################################################################\n" "${CYAN}"
89
garciadeblascf603f52025-06-04 11:57:28 +020090TEMPLATES_DIR="${HERE}/flux/templates/fleet/clusters/_management"
garciadeblas8d8cd992024-05-21 16:04:14 +020091TEMPLATES_DIR=$(readlink -f "${TEMPLATES_DIR}")
92
93# ARGUMENTS:
94# 1: Cluster folder
95# 2: Project folder
96# 3: Profile name
97# 4: Templates folder
98"${HERE}/flux/scripts/create-new-cluster-folder-structure.sh" \
99 "${FLEET_REPO_DIR}/clusters/_management" \
100 "${FLEET_REPO_DIR}/${MGMT_PROJECT_NAME}" \
101 "_management" \
102 "${TEMPLATES_DIR}" \
103 $(<"${CREDENTIALS_DIR}/${AGE_KEY_NAME_MGMT}.pub")
104
105
106#####################################################################
107
108
109############################ Populate the SW-Catalogs repo folder
110m "\n#####################################################################" "${CYAN}"
111m "(5/8) Populating the SW-Catalogs repo folder..." "${CYAN}"
112m "#####################################################################\n" "${CYAN}"
113
garciadeblascf603f52025-06-04 11:57:28 +0200114TEMPLATES_DIR="${HERE}/flux/templates/sw-catalogs"
garciadeblas8d8cd992024-05-21 16:04:14 +0200115TEMPLATES_DIR=$(readlink -f "${TEMPLATES_DIR}")
116# rsync -varhP "${TEMPLATES_DIR}" "${SW_CATALOGS_REPO_DIR}/"
117cp -r "${TEMPLATES_DIR}"/* "${SW_CATALOGS_REPO_DIR}/"
garciadeblasb7c82672025-08-05 11:15:03 +0200118if [ -n "${OSM_DOCKER_TAG}" ]; then
119 # Replace the OSM Docker tag in the WF templates
120 find "${SW_CATALOGS_REPO_DIR}/infra-configs/osm-workflows/templates/wf-templates/building-blocks" -type f -name "*.yaml" -exec sed -i "s|opensourcemano/osm-krm-functions:testing-daily|${DOCKER_REGISTRY_URL}${DOCKER_USER}/osm-krm-functions:${OSM_DOCKER_TAG}|g" {} +
121fi
garciadeblasa8e273c2025-09-09 13:47:40 +0200122if [ -n "${MGMT_CLUSTER_CA_FILE}" ]; then
123 # Update secret-template for Flux bootstrap to add CA file
124 echo "data:" >> "${SW_CATALOGS_REPO_DIR}/cloud-resources/flux-remote-bootstrap/bootstrap/manifests/secret/secret-template.yaml"
125 echo " ca.crt: $(base64 -w 0 "${MGMT_CLUSTER_CA_FILE}")" >> "${SW_CATALOGS_REPO_DIR}/cloud-resources/flux-remote-bootstrap/bootstrap/manifests/secret/secret-template.yaml"
126fi
garciadeblas8d8cd992024-05-21 16:04:14 +0200127
128#####################################################################
129
130
131############################ Add all the required operators and CRDs
132m "\n#####################################################################" "${CYAN}"
133m "(6/8) Add all the required operators and CRDs..." "${CYAN}"
134m "#####################################################################\n" "${CYAN}"
135
136# ARGUMENTS:
137# 1: Project folder
138# 2: Profile name
139"${HERE}/mgmt-operators-and-crds/add-operators-and-crds.sh" \
140 "${FLEET_REPO_DIR}/${MGMT_PROJECT_NAME}" \
141 "_management"
142
143#####################################################################
144
145
146############################ Configure for running OSM workflows
147m "\n#####################################################################" "${CYAN}"
148m "(7/8) Configure for running OSM workflows..." "${CYAN}"
149m "#####################################################################\n" "${CYAN}"
150
151# ARGUMENTS:
152# 1: Project folder
153# 2: Profile name
154
155"${HERE}/mgmt-operators-and-crds/configure-workflows.sh" \
156 "${FLEET_REPO_DIR}/${MGMT_PROJECT_NAME}" \
157 "_management" \
158 $(<"${CREDENTIALS_DIR}/${AGE_KEY_NAME_MGMT}.pub")
159
160
161#####################################################################
162
163
164############################ Push changes to Git repos
165m "\n#####################################################################" "${CYAN}"
166m "(8/8) Pushing all changes to Git repos..." "${CYAN}"
167m "#####################################################################\n" "${CYAN}"
168
169# SW Catalogs
170pushd "${SW_CATALOGS_REPO_DIR}" > /dev/null
171# git status
172git add -A
173git commit -m "Sync from sw-catalogs template"
174git push -u origin main
175popd > /dev/null
176
177# Fleet
178pushd "${FLEET_REPO_DIR}" > /dev/null
179# git status
180git add -A
181git commit -m "Full profile structure after bootstrap + SOPS config + operators and CRDs"
182git push -u origin main
183popd > /dev/null
184
185#####################################################################