From: garciadeblas Date: Wed, 13 Nov 2024 13:58:53 +0000 (+0100) Subject: Update krm-functions to fix clutser registration issues X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F27%2F14727%2F1;p=osm%2Fdevops.git Update krm-functions to fix clutser registration issues Change-Id: I85cb8e6015e2e989cff8a0e1231bdeec6abdf837 Signed-off-by: garciadeblas --- diff --git a/docker/osm-krm-functions/scripts/library/krm-functions.rc b/docker/osm-krm-functions/scripts/library/krm-functions.rc index 98a43cc3..07a47f86 100644 --- a/docker/osm-krm-functions/scripts/library/krm-functions.rc +++ b/docker/osm-krm-functions/scripts/library/krm-functions.rc @@ -1,17 +1,22 @@ #!/bin/bash +####################################################################################### +# Copyright ETSI Contributors and Others. # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# http://www.apache.org/licenses/LICENSE-2.0 # +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################################################################### + + function generator_encrypted_secret_cloud_credentials() { local CLOUD_CREDENTIALS_FILENAME="$1" @@ -491,11 +496,12 @@ function create_bootstrap_for_remote_cluster() { local PUBLIC_KEY_MGMT="${8:-"${PUBLIC_KEY_MGMT}"}" local PUBLIC_KEY_NEW_CLUSTER="$9" local PRIVATE_KEY_NEW_CLUSTER="${10:-${PRIVATE_KEY_NEW_CLUSTER}}" + local IMPORTED_CLUSTER="${11:-"false"}" + # Calculates the folder where managed resources area defined local MGMT_RESOURCES_DIR="${FLEET_REPO_DIR}/${MGMT_PROJECT_NAME}/managed-resources/_management" - # Create profile folders echo "" | \ generator_profile_folders_new_cluster \ @@ -544,6 +550,42 @@ function create_bootstrap_for_remote_cluster() { prepend_folder_path "${CLUSTER_KUSTOMIZATION_NAME}/" | \ list2folder_cp_over \ "${MGMT_RESOURCES_DIR}" + + # If it is an imported cluster, we must create a placeholder Kustomization + if [[ "${IMPORTED_CLUSTER,,}" == "true" ]]; + then + TEMPLATES_DIR="${SW_CATALOGS_REPO_DIR}/cloud-resources/flux-remote-bootstrap/empty-kustomization/templates" + + export CLUSTER_KUSTOMIZATION_NAME + folder2list \ + "${TEMPLATES_DIR}" | \ + replace_env_vars \ + '${CLUSTER_KUSTOMIZATION_NAME}' | \ + prepend_folder_path "${CLUSTER_KUSTOMIZATION_NAME}/" | \ + list2folder_cp_over \ + "${MGMT_RESOURCES_DIR}" + fi +} + + +# Disconnect Flux of remote cluster +function disconnect_flux_remote_cluster() { + local CLUSTER_KUSTOMIZATION_NAME="$1" + local FLEET_REPO_DIR="${2:-"${FLEET_REPO_DIR}"}" + local MGMT_PROJECT_NAME="${3:-${MGMT_PROJECT_NAME}}" + + + # Calculates key folders + ## Base folder with Kustomizations for the new cluster + local CLUSTER_FOLDER="${FLEET_REPO_DIR}/clusters/${CLUSTER_KUSTOMIZATION_NAME}" + ## Folder where managed resources are defined in the management cluster + local MGMT_RESOURCES_CLUSTER_DIR="${FLEET_REPO_DIR}/${MGMT_PROJECT_NAME}/managed-resources/_management/${CLUSTER_KUSTOMIZATION_NAME}" + + # Delete Flux resources syncronized directly from remote cluster + rm -rf "${CLUSTER_FOLDER}/flux-system" + + # Delete Flux resources bootstraped remotely + rm -rf "${MGMT_RESOURCES_CLUSTER_DIR}/cluster-bootstrap-${CLUSTER_KUSTOMIZATION_NAME}.yaml" }