local TARGET_NAME="$2"
local OPERATION="$3"
local PATCH_PATH="$4"
- # Gathers all optional parameters for transformer funcion (if any) and puts them into an array for further use
+ # Gathers all optional parameters for transformer function (if any) and puts them into an array for further use
local ALL_PARAMS=( "${@}" )
local VALUES=( "${ALL_PARAMS[@]:4}" )
# Calculates key folders
## Base folder with Kustomizations for the new cluster
- local CLUSTER_FOLDER="${FLEET_REPO_DIR}/clusters/${CLUSTER_KUSTOMIZATION_NAME}"
+ # 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 synchronized 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"
local APPS_DIR="${8:-"${FLEET_REPO_DIR}/${PROJECT_NAME}/app-profiles/${CLUSTER_KUSTOMIZATION_NAME}"}"
local CLUSTER_DIR="${9:-"${FLEET_REPO_DIR}/clusters/${CLUSTER_KUSTOMIZATION_NAME}"}"
+ # Optional input: Do I need a purge operation first?
+ local PURGE="${10:-"false"}"
+
+
+ # Perform the purge if needed
+ if [[ "${PURGE,,}" == "true" ]]; then
+ echo "Purging the remote Flux instalation..."
+ flux uninstall -s --namespace=flux-system
+ fi
+
+ echo "Deleting cluster profiles and (when applicable) its cloud resources..."
+
# Delete profile folders
rm -rf "${INFRA_CONTROLLERS_DIR}"
rm -rf "${INFRA_CONFIGS_DIR}"
# Delete base cluster Kustomizations
rm -rf "${CLUSTER_DIR}"
- # Delete cluster resources
+ # Delete cluster resources if managed by OSM (otherwise, this will be ignored)
rm -rf "${MGMT_RESOURCES_DIR}/${CLUSTER_KUSTOMIZATION_NAME}"
}
# fsGroup: 10000
- # TODO: Deprecated - To be removed
- # Create a PaaS cluster in Azure
- - name: create-cluster-aks
- inputs:
- parameters:
- # Volumes with cloned repos
- - name: fleet_volume_name
- - name: fleet_mount_path
- value: "/fleet"
- - name: sw_catalogs_volume_name
- - name: sw_catalogs_mount_path
- value: "/sw-catalogs"
-
- # Specific parameters
- - name: cluster_name
- - name: vm_size
- - name: node_count
- - name: cluster_location
- - name: rg_name
- - name: k8s_version
- - name: providerconfig_name
- - name: cluster_kustomization_name
- - name: mgmt_project_name
- value: "osm_admin"
-
- # Other parameters - Recommended to keep defaults
- - name: fleet_repo_dir
- value: "/fleet/fleet-osm/"
- - name: sw_catalogs_repo_dir
- value: "/sw-catalogs/sw-catalogs-osm/"
- - name: target_folder
- value: "{{inputs.parameters.fleet_repo_dir}}/{{inputs.parameters.mgmt_project_name}}/managed-resources/_management"
- - name: manifest_filename
- value: "{{inputs.parameters.cluster_name}}.yaml"
- - name: templates
- value: "{{inputs.parameters.sw_catalogs_repo_dir}}/cloud-resources/aks/templates/"
- - name: template_manifest_filename
- value: "aks01.yaml"
- volumes:
- - name: fleet-repo-volume
- persistentVolumeClaim:
- claimName: '{{inputs.parameters.fleet_volume_name}}'
- - name: sw-catalogs-repo-volume
- persistentVolumeClaim:
- claimName: '{{inputs.parameters.sw_catalogs_volume_name}}'
- container:
- image: opensourcemano/osm-krm-functions:testing-daily
- # imagePullPolicy: Always
- # securityContext:
- # runAsUser: 10000
- # runAsGroup: 10000
- # fsGroup: 10000
- volumeMounts:
- - name: fleet-repo-volume
- mountPath: '{{inputs.parameters.fleet_mount_path}}'
- - name: sw-catalogs-repo-volume
- mountPath: '{{inputs.parameters.sw_catalogs_mount_path}}'
- command: ["/app/scripts/entrypoint.sh"]
- args:
- - create_cluster_aks
- - "{{inputs.parameters.cluster_name}}"
- - "{{inputs.parameters.vm_size}}"
- - "{{inputs.parameters.node_count}}"
- - "{{inputs.parameters.cluster_location}}"
- - "{{inputs.parameters.rg_name}}"
- - "{{inputs.parameters.k8s_version}}"
- - "{{inputs.parameters.providerconfig_name}}"
- - "{{inputs.parameters.cluster_kustomization_name}}"
- - "{{inputs.parameters.target_folder}}"
- - "{{inputs.parameters.manifest_filename}}"
- - "{{inputs.parameters.templates}}"
- - "{{inputs.parameters.template_manifest_filename}}"
-
-
# Bootstrap remote cluster running in **ANY cloud**
- name: bootstrap-remote-cluster
inputs:
runAsUser: 10000
# runAsGroup: 10000
# fsGroup: 10000
+
+
+ # Purge and delete cluster from **ANY** cloud
+ - name: purge-delete-cluster
+ inputs:
+ parameters:
+ # Volumes with cloned repos
+ - name: fleet_volume_name
+ - name: fleet_mount_path
+ value: "/fleet"
+
+ # Specific parameters
+ - name: cluster_kustomization_name
+ - name: project_name
+ value: "osm_admin"
+
+ # Is a purge needed before deleting?
+ - name: purge
+ value: "true"
+ ## Secret where the kubeconfig is stored (may not exist)
+ - name: temp_kubeconfig_secret_name
+ valueFrom:
+ expression: "kubeconfig-{{inputs.parameters.cluster_kustomization_name}}"
+
+ # Other parameters - Recommended to keep defaults
+ - name: temp_kubeconfig_secret_key
+ value: "kubeconfig"
+ - name: fleet_repo_dir
+ value: "/fleet/fleet-osm/"
+ - name: mgmt_resources_dir
+ value: "{{inputs.parameters.fleet_repo_dir}}/{{inputs.parameters.project_name}}/managed-resources/_management"
+
+ container:
+ image: ttl.sh/osm-krm-functions:24h
+ # imagePullPolicy: Always
+ command: ["/app/scripts/entrypoint.sh"]
+ args:
+ - delete_remote_cluster
+ - "{{inputs.parameters.cluster_kustomization_name}}"
+ - "{{inputs.parameters.project_name}}"
+ - "{{inputs.parameters.fleet_repo_dir}}"
+ - "{{inputs.parameters.mgmt_resources_dir}}"
+ - ''
+ - ''
+ - ''
+ - ''
+ - ''
+ - "{{inputs.parameters.purge}}"
+
+ volumeMounts:
+ - name: fleet-repo-volume
+ mountPath: '{{inputs.parameters.fleet_mount_path}}'
+ - name: kubeconfig-volume
+ mountPath: '/app/.kube'
+ volumes:
+ - name: fleet-repo-volume
+ persistentVolumeClaim:
+ claimName: '{{inputs.parameters.fleet_volume_name}}'
+ - name: kubeconfig-volume
+ secret:
+ secretName: '{{inputs.parameters.temp_kubeconfig_secret_name}}'
+ optional: true
+ items:
+ - key: '{{inputs.parameters.temp_kubeconfig_secret_key}}'
+ path: 'config'
+ securityContext:
+ fsGroup: 10000
+ # runAsUser: 10000
+ # runAsGroup: 10000
--- /dev/null
+#######################################################################################
+# 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
+#
+# 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.
+#######################################################################################
+
+apiVersion: argoproj.io/v1alpha1
+kind: WorkflowTemplate
+metadata:
+ name: full-purge-delete-cluster-wft
+ namespace: osm-workflows
+
+spec:
+ arguments:
+ parameters:
+
+ # Fleet repo
+ - name: git_fleet_url
+ - name: fleet_destination_folder
+ - name: git_fleet_cred_secret
+
+ # Specific parameters
+ - name: cluster_kustomization_name
+ - name: project_name
+ value: "osm_admin"
+ - name: temp_kubeconfig_secret_name
+ - name: purge
+ value: "true"
+
+ # Debugging
+ - name: dry_run
+ value: false
+
+
+ # # Cleanup policy
+ # ttlStrategy:
+ # secondsAfterCompletion: 100 # Time to live after workflow is completed, replaces ttlSecondsAfterFinished
+ # secondsAfterSuccess: 50 # Time to live after workflow is successful
+ # secondsAfterFailure: 50 # Time to live after workflow fails
+
+ entrypoint: delete-cluster
+
+ templates:
+
+ # Main template
+ - name: delete-cluster
+ inputs:
+ parameters:
+ # Git repos
+ - name: git_fleet_url
+ - name: fleet_destination_folder
+ - name: git_fleet_cred_secret
+
+ # Specific parameters
+ - name: cluster_kustomization_name
+ - name: project_name
+ - name: purge
+ - name: temp_kubeconfig_secret_name
+
+ # Debugging
+ - name: dry_run
+
+ steps:
+
+ # ------ Preparations for transaction
+ - - name: generate-fleet-volume-repo
+ templateRef:
+ name: k8s-resources-wft
+ template: generate-volume
+ arguments:
+ parameters:
+ - name: pvc-size
+ value: '100Mi'
+ - - name: clone-fleet
+ templateRef:
+ name: git-wft
+ template: git-clone
+ arguments:
+ parameters:
+ - name: mount_path
+ value: "/fleet"
+ - name: repo_url
+ value: "{{inputs.parameters.git_fleet_url}}"
+ - name: destination_folder
+ value: "{{inputs.parameters.fleet_destination_folder}}"
+ - name: git_cred_secret
+ value: "{{inputs.parameters.git_fleet_cred_secret}}"
+ - name: git_volume_name
+ value: '{{steps.generate-fleet-volume-repo.outputs.parameters.pvc-name}}'
+ # ------ end of preparations for transaction
+
+ # ------ Transformations
+ - - name: purge-delete-cluster
+ templateRef:
+ name: cluster-management-wft
+ template: purge-delete-cluster
+ arguments:
+ parameters:
+ # Volumes with cloned repos
+ - name: fleet_volume_name
+ value: '{{steps.generate-fleet-volume-repo.outputs.parameters.pvc-name}}'
+ - name: fleet_mount_path
+ value: "/fleet"
+ # Specific parameters
+ - name: cluster_kustomization_name
+ value: "{{inputs.parameters.cluster_kustomization_name}}"
+ - name: project_name
+ value: "{{inputs.parameters.project_name}}"
+ - name: purge
+ value: "{{inputs.parameters.purge}}"
+ - name: temp_kubeconfig_secret_name
+ value: "{{inputs.parameters.temp_kubeconfig_secret_name}}"
+ # ------ end of transformations
+
+ # ------ Commit transaction
+ - - name: push-to-fleet
+ templateRef:
+ name: git-wft
+ template: git-commit-merge-push
+ arguments:
+ parameters:
+ - name: mount_path
+ value: "/fleet"
+ - name: repo_folder
+ value: "{{inputs.parameters.fleet_destination_folder}}"
+ - name: git_cred_secret
+ value: "{{inputs.parameters.git_fleet_cred_secret}}"
+ - name: git_volume_name
+ value: '{{steps.generate-fleet-volume-repo.outputs.parameters.pvc-name}}'
+ - name: commit_message
+ value: "Delete cluster {{inputs.parameters.cluster_kustomization_name}}"
+ - name: main_branch
+ value: main
+ - name: contrib_branch
+ value: osm_contrib
+ - name: dry_run
+ value: "{{inputs.parameters.dry_run}}"
+# ------ end of commit transaction
+++ /dev/null
-#######################################################################################
-# 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
-#
-# 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.
-#######################################################################################
-
-apiVersion: argoproj.io/v1alpha1
-kind: WorkflowTemplate
-metadata:
- name: full-uninstall-flux-remote-cluster-wft
- namespace: osm-workflows
-
-spec:
- arguments:
- parameters:
-
- # Fleet repo
- - name: git_fleet_url
- - name: fleet_destination_folder
- - name: git_fleet_cred_secret
-
- # Specific parameters
- - name: cluster_kustomization_name
- - name: project_name
- value: "osm_admin"
-
- # Debugging
- - name: dry_run
- value: false
-
-
- # # Cleanup policy
- # ttlStrategy:
- # secondsAfterCompletion: 100 # Time to live after workflow is completed, replaces ttlSecondsAfterFinished
- # secondsAfterSuccess: 50 # Time to live after workflow is successful
- # secondsAfterFailure: 50 # Time to live after workflow fails
-
- entrypoint: uninstall-flux
-
- templates:
-
- # Main template
- - name: uninstall-flux
- inputs:
- parameters:
- # Git repos
- - name: git_fleet_url
- - name: fleet_destination_folder
- - name: git_fleet_cred_secret
-
- # Specific parameters
- - name: cluster_kustomization_name
- - name: project_name
-
- # Debugging
- - name: dry_run
-
- steps:
-
- # ------ Preparations for transaction
- - - name: generate-fleet-volume-repo
- templateRef:
- name: k8s-resources-wft
- template: generate-volume
- arguments:
- parameters:
- - name: pvc-size
- value: '100Mi'
- - - name: clone-fleet
- templateRef:
- name: git-wft
- template: git-clone
- arguments:
- parameters:
- - name: mount_path
- value: "/fleet"
- - name: repo_url
- value: "{{inputs.parameters.git_fleet_url}}"
- - name: destination_folder
- value: "{{inputs.parameters.fleet_destination_folder}}"
- - name: git_cred_secret
- value: "{{inputs.parameters.git_fleet_cred_secret}}"
- - name: git_volume_name
- value: '{{steps.generate-fleet-volume-repo.outputs.parameters.pvc-name}}'
- # ------ end of preparations for transaction
-
- # ------ Transformations
- - - name: delete-cluster
- templateRef:
- name: cluster-management-wft
- template: delete-cluster
- arguments:
- parameters:
- # Volumes with cloned repos
- - name: fleet_volume_name
- value: '{{steps.generate-fleet-volume-repo.outputs.parameters.pvc-name}}'
- - name: fleet_mount_path
- value: "/fleet"
- # Specific parameters
- - name: cluster_kustomization_name
- value: "{{inputs.parameters.cluster_kustomization_name}}"
- - name: project_name
- value: "{{inputs.parameters.project_name}}"
- # ------ end of transformations
-
- # ------ Commit transaction
- - - name: push-to-fleet
- templateRef:
- name: git-wft
- template: git-commit-merge-push
- arguments:
- parameters:
- - name: mount_path
- value: "/fleet"
- - name: repo_folder
- value: "{{inputs.parameters.fleet_destination_folder}}"
- - name: git_cred_secret
- value: "{{inputs.parameters.git_fleet_cred_secret}}"
- - name: git_volume_name
- value: '{{steps.generate-fleet-volume-repo.outputs.parameters.pvc-name}}'
- - name: commit_message
- value: "Delete cluster {{inputs.parameters.cluster_kustomization_name}}"
- - name: main_branch
- value: main
- - name: contrib_branch
- value: osm_contrib
- - name: dry_run
- value: "{{inputs.parameters.dry_run}}"
-# ------ end of commit transaction