From ba5f63a6385fed20c5251020ea907434dd19fe96 Mon Sep 17 00:00:00 2001 From: Keith Pine Date: Wed, 4 May 2022 11:21:42 -0700 Subject: [PATCH] CORTX-30141: Remove CORTX secrets custom template file Use kubectl to create the generic secret directly. Signed-off-by: Keith Pine --- .../other/secret-template.yaml | 7 ----- k8_cortx_cloud/deploy-cortx-cloud.sh | 30 +++++++------------ 2 files changed, 11 insertions(+), 26 deletions(-) delete mode 100644 k8_cortx_cloud/cortx-cloud-helm-pkg/cortx-configmap/other/secret-template.yaml diff --git a/k8_cortx_cloud/cortx-cloud-helm-pkg/cortx-configmap/other/secret-template.yaml b/k8_cortx_cloud/cortx-cloud-helm-pkg/cortx-configmap/other/secret-template.yaml deleted file mode 100644 index 00b8a4f1..00000000 --- a/k8_cortx_cloud/cortx-cloud-helm-pkg/cortx-configmap/other/secret-template.yaml +++ /dev/null @@ -1,7 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: <<.Values.secret.name>> -type: Opaque -stringData: -<<.Values.secret.content>> \ No newline at end of file diff --git a/k8_cortx_cloud/deploy-cortx-cloud.sh b/k8_cortx_cloud/deploy-cortx-cloud.sh index 576c5afe..594ed4ba 100755 --- a/k8_cortx_cloud/deploy-cortx-cloud.sh +++ b/k8_cortx_cloud/deploy-cortx-cloud.sh @@ -825,39 +825,31 @@ function deployCortxSecrets() printf "########################################################\n" printf "# Deploy CORTX Secrets \n" printf "########################################################\n" - # Parse secret from the solution file and create all secret yaml files + # Parse secret from the solution file and create all secret files # in the "auto-gen-secret" folder - secret_auto_gen_path="${cfgmap_path}/auto-gen-secret-${namespace}" + local secret_auto_gen_path="${cfgmap_path}/auto-gen-secret-${namespace}" mkdir -p "${secret_auto_gen_path}" - cortx_secret_name=$(getSolutionValue "solution.secrets.name") - cortx_secret_ext=$(getSolutionValue "solution.secrets.external_secret") + cortx_secret_name=$(getSolutionValue "solution.secrets.name") # This is a global variable if [[ -n "${cortx_secret_name}" ]]; then # Process secrets from solution.yaml - secrets=() for field in "${cortx_secret_fields[@]}"; do fcontent=$(getSolutionValue "solution.secrets.content.${field}") if [[ -z ${fcontent} ]]; then # No data for this field. Generate a password. - pw=$(pwgen) - fcontent=${pw} + fcontent=$(pwgen) printf "Generated secret for %s\n" "${field}" fi - secrets+=( " ${field}: ${fcontent}" ) + printf "%s" "${fcontent}" > "${secret_auto_gen_path}/${field}" done - secrets_block=$( printf "%s\n" "${secrets[@]}" ) - - new_secret_gen_file="${secret_auto_gen_path}/${cortx_secret_name}.yaml" - cp "${cfgmap_path}/other/secret-template.yaml" "${new_secret_gen_file}" - ./parse_scripts/subst.sh "${new_secret_gen_file}" "secret.name" "${cortx_secret_name}" - ./parse_scripts/subst.sh "${new_secret_gen_file}" "secret.content" "${secrets_block}" - kubectl_create_secret_cmd="kubectl create -f ${new_secret_gen_file} --namespace=${namespace}" - if ! ${kubectl_create_secret_cmd}; then + + if ! kubectl create secret generic "${cortx_secret_name}" \ + --from-file="${secret_auto_gen_path}" \ + --namespace="${namespace}"; then printf "Exit early. Failed to create Secret '%s'\n" "${cortx_secret_name}" exit 1 fi - - elif [[ -n "${cortx_secret_ext}" ]]; then - cortx_secret_name="${cortx_secret_ext}" + else + cortx_secret_name="$(getSolutionValue "solution.secrets.external_secret")" printf "Installing CORTX with existing Secret %s.\n" "${cortx_secret_name}" fi