From add2875fb36d19401fe2f8c614ebd2e837a44e06 Mon Sep 17 00:00:00 2001 From: HumbertoPeluso Date: Fri, 13 Aug 2021 10:00:29 -0300 Subject: [PATCH] refactoring external-dns formula --- vkpr/external-dns/install/config.json | 4 ++-- .../install/src/unix/formula/formula.sh | 23 +++++++++++++++---- .../install/src/utils/external-dns.sh | 11 --------- .../install/src/utils/external-dns.yaml | 9 ++++++++ 4 files changed, 29 insertions(+), 18 deletions(-) delete mode 100644 vkpr/external-dns/install/src/utils/external-dns.sh create mode 100644 vkpr/external-dns/install/src/utils/external-dns.yaml diff --git a/vkpr/external-dns/install/config.json b/vkpr/external-dns/install/config.json index 0e37199e..ba57c02e 100644 --- a/vkpr/external-dns/install/config.json +++ b/vkpr/external-dns/install/config.json @@ -8,12 +8,12 @@ "AWS" ], "label": "What is your cloud provider? ", - "name": "input_cloud_provider", + "name": "provider", "required": true, "type": "text" }, { - "name": "digitalocean_apitoken", + "name": "token", "type": "CREDENTIAL_DIGITALOCEAN_APITOKEN" } ], diff --git a/vkpr/external-dns/install/src/unix/formula/formula.sh b/vkpr/external-dns/install/src/unix/formula/formula.sh index cf11b1b5..e4fd5adc 100755 --- a/vkpr/external-dns/install/src/unix/formula/formula.sh +++ b/vkpr/external-dns/install/src/unix/formula/formula.sh @@ -6,7 +6,9 @@ runFormula() { VKPR_EXTERNAL_DNS_LOCAL=$VKPR_HOME/values/external-dns VKPR_EXTERNAL_DNS_VALUES=$VKPR_EXTERNAL_DNS_LOCAL/external-dns.yaml mkdir -p $VKPR_EXTERNAL_DNS_LOCAL + VKPR_EXTERNAL_DNS_VALUES=$(dirname "$0")/utils/external-dns.yaml + getProvider $PROVIDER add_repo_external_dns install_external_dns } @@ -17,17 +19,28 @@ add_repo_external_dns() { } install_external_dns() { - getProvider $INPUT_CLOUD_PROVIDER - if [[ ! -e $VKPR_EXTERNAL_DNS_VALUES ]]; then - . $(dirname "$0")/utils/external-dns.sh $VKPR_EXTERNAL_DNS_VALUES $DO_AUTH_TOKEN - fi $VKPR_HOME/bin/helm upgrade -i vkpr -f $VKPR_EXTERNAL_DNS_VALUES bitnami/external-dns } +get_credentials() { + # CREDENTIAL INPUT NOT WORKING IN SHELL FORMULA + # PARSING FILE DIRECTLY AND IGNORING INPUT ("-r" is important!!!) + #VKPR_ACCESS_TOKEN_INPUT=$(jq -r .credential.token ~/.rit/credentials/default/digitalocean) + if [ -z "$TOKEN" ]; then + echo "yellow" "No digitalocean token found in rit credentials. Falling back to DO_AUTH_TOKEN env variable." + TOKEN="$DO_AUTH_TOKEN" + fi + if [ -z "$TOKEN" ]; then + echoColor "red" "No digitalocean token found in both rit credentials or DO_AUTH_TOKEN env variable." + echoColor "red" "Cert-manager will fail to negotiate certificates unless you provide the digitalocean-dns secret manually." + echoColor "red" "Please check https://cert-manager.io/docs/configuration/acme/dns01/digitalocean/" + fi +} + getProvider(){ case $1 in DIGITALOCEAN) - export DO_AUTH_TOKEN=$DIGITALOCEAN_APITOKEN + get_credentials ;; AWS) echoColor "yellow" "AWS is a working in progress." diff --git a/vkpr/external-dns/install/src/utils/external-dns.sh b/vkpr/external-dns/install/src/utils/external-dns.sh deleted file mode 100644 index 55812c3b..00000000 --- a/vkpr/external-dns/install/src/utils/external-dns.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -printf \ - "rbac: - create: true -sources: - - ingress - - service -provider: digitalocean -interval: '"1m"' -digitalocean: - apiToken: $2" > $1 \ No newline at end of file diff --git a/vkpr/external-dns/install/src/utils/external-dns.yaml b/vkpr/external-dns/install/src/utils/external-dns.yaml new file mode 100644 index 00000000..5f40f555 --- /dev/null +++ b/vkpr/external-dns/install/src/utils/external-dns.yaml @@ -0,0 +1,9 @@ +rbac: + create: true +sources: + - ingress + - service +provider: digitalocean +interval: "1m" +digitalocean: + apiToken: $Token \ No newline at end of file