From f6e327973b3da37d8aa52d851d0704c84246cd5a Mon Sep 17 00:00:00 2001 From: Nanne Baars Date: Wed, 24 Nov 2021 09:21:45 +0100 Subject: [PATCH 1/3] Add checks to see if needed executable are available --- k8s-vault-minkube-start.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/k8s-vault-minkube-start.sh b/k8s-vault-minkube-start.sh index 1e9cd2738..04af63c76 100755 --- a/k8s-vault-minkube-start.sh +++ b/k8s-vault-minkube-start.sh @@ -3,6 +3,17 @@ # set -o pipefail # set -o nounset +function checkCommandAvailable() { + if ! [ -x "$(command -v "$1")" ]; then + echo "Error: ${1} is not installed." >&2 + exit 1 + fi +} + +checkCommandAvailable "helm" +checkCommandAvailable "minikube" +checkCommandAvailable "jq" + echo "This is only a script for demoing purposes. You need to have installed: minikube with docker (or comment out line 8 and work at your own k8s setup), helm, kubectl, jq, vault, grep, cat, sed and is only tested on mac and ubuntu" echo "This script is based on the steps defined in https://learn.hashicorp.com/tutorials/vault/kubernetes-minikube . Vault is awesome!" minikube start --kubernetes-version=v1.20.10 From 4c4b74cb1729b44afaaa96c7797d7d7a5ff28fcd Mon Sep 17 00:00:00 2001 From: Nanne Baars Date: Wed, 24 Nov 2021 09:26:54 +0100 Subject: [PATCH 2/3] Remove Vault from the list as it is installed as container --- k8s-vault-minkube-start.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/k8s-vault-minkube-start.sh b/k8s-vault-minkube-start.sh index 04af63c76..e6b64b976 100755 --- a/k8s-vault-minkube-start.sh +++ b/k8s-vault-minkube-start.sh @@ -14,7 +14,8 @@ checkCommandAvailable "helm" checkCommandAvailable "minikube" checkCommandAvailable "jq" -echo "This is only a script for demoing purposes. You need to have installed: minikube with docker (or comment out line 8 and work at your own k8s setup), helm, kubectl, jq, vault, grep, cat, sed and is only tested on mac and ubuntu" + +echo "This is only a script for demoing purposes. You need to have installed: minikube with docker (or comment out line 8 and work at your own k8s setup), helm, kubectl, jq, grep, cat, sed and is only tested on mac and ubuntu" echo "This script is based on the steps defined in https://learn.hashicorp.com/tutorials/vault/kubernetes-minikube . Vault is awesome!" minikube start --kubernetes-version=v1.20.10 From 374300142bb6220381ce9ea2261c041b0108d386 Mon Sep 17 00:00:00 2001 From: Nanne Baars Date: Wed, 24 Nov 2021 10:08:26 +0100 Subject: [PATCH 3/3] Rewrite function to check if commands are present --- k8s-vault-minkube-start.sh | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/k8s-vault-minkube-start.sh b/k8s-vault-minkube-start.sh index e6b64b976..97790ffaf 100755 --- a/k8s-vault-minkube-start.sh +++ b/k8s-vault-minkube-start.sh @@ -3,25 +3,27 @@ # set -o pipefail # set -o nounset -function checkCommandAvailable() { - if ! [ -x "$(command -v "$1")" ]; then - echo "Error: ${1} is not installed." >&2 - exit 1 - fi +function checkCommandsAvailable() { + for var in "$@" + do + if ! [ -x "$(command -v "$var")" ]; then + echo "🔥 ${var} is not installed." >&2 + exit 1 + else + echo "🏄 $var is installed..." + fi + done } -checkCommandAvailable "helm" -checkCommandAvailable "minikube" -checkCommandAvailable "jq" +checkCommandsAvailable helm minikube jq vault sed grep docker grep cat - -echo "This is only a script for demoing purposes. You need to have installed: minikube with docker (or comment out line 8 and work at your own k8s setup), helm, kubectl, jq, grep, cat, sed and is only tested on mac and ubuntu" +echo "This is only a script for demoing purposes. You can comment out line 22 and work with your own k8s setup" echo "This script is based on the steps defined in https://learn.hashicorp.com/tutorials/vault/kubernetes-minikube . Vault is awesome!" minikube start --kubernetes-version=v1.20.10 kubectl get configmaps | grep 'secrets-file' &> /dev/null if [ $? == 0 ]; then - echo "secrets config is already installed" + echo "secrets config is already installed" else kubectl apply -f k8s/secrets-config.yml fi