#!/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"
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 \
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"
}