check for required settings

This commit is contained in:
Myers Carpenter 2019-01-08 15:41:10 -05:00
parent b11aafd170
commit de25cfb60d
1 changed files with 46 additions and 28 deletions

View File

@ -1,52 +1,70 @@
#!/bin/bash #!/bin/bash
set -e set -euo pipefail
export KUBECONFIG=/tmp/kubeconfig export KUBECONFIG=/tmp/kubeconfig
if [ -z ${PLUGIN_NAMESPACE} ]; then if [ -z "${PLUGIN_KUBERNETES_TOKEN:-}" ]; then
echo "ERROR: You must set 'kubernetes_token'"
exit 1
fi
if [ -z "${PLUGIN_TAG:-}" ]; then
echo "ERROR: You must set 'tag'"
exit 1
fi
if [ -z "${PLUGIN_REPO:-}" ]; then
echo "ERROR: You must set 'repo'"
exit 1
fi
if [ -z "${PLUGIN_KUBERNETES_SERVER:-}" ]; then
echo "ERROR: You must set 'kubernetes_server'"
exit 1
fi
if [ -z "${PLUGIN_DEPLOYMENT:-}" ]; then
echo "ERROR: You must set 'deployment'"
exit 1
fi
if [ -z "${PLUGIN_CONTAINER:-}" ]; then
echo "ERROR: You must set 'container'"
exit 1
fi
if [ -z "${PLUGIN_NAMESPACE:-}" ]; then
PLUGIN_NAMESPACE="default" PLUGIN_NAMESPACE="default"
fi fi
if [ -z ${PLUGIN_KUBERNETES_USER} ]; then if [ -z "${PLUGIN_KUBERNETES_USER:-}" ]; then
PLUGIN_KUBERNETES_USER="default" PLUGIN_KUBERNETES_USER="default"
fi fi
if [ ! -z ${PLUGIN_KUBERNETES_TOKEN} ]; then kubectl config set-credentials default --token=${PLUGIN_KUBERNETES_TOKEN}
KUBERNETES_TOKEN=$PLUGIN_KUBERNETES_TOKEN if [ -z "${PLUGIN_KUBERNETES_CERT:-}" ]; then
fi
if [ ! -z ${PLUGIN_KUBERNETES_SERVER} ]; then
KUBERNETES_SERVER=$PLUGIN_KUBERNETES_SERVER
fi
if [ ! -z ${PLUGIN_KUBERNETES_CERT} ]; then
KUBERNETES_CERT=${PLUGIN_KUBERNETES_CERT}
fi
kubectl config set-credentials default --token=${KUBERNETES_TOKEN}
if [ ! -z ${KUBERNETES_CERT} ]; then
echo ${KUBERNETES_CERT} | base64 -d > ca.crt
kubectl config set-cluster default --server=${KUBERNETES_SERVER} --certificate-authority=ca.crt
else
echo "WARNING: Using insecure connection to cluster" echo "WARNING: Using insecure connection to cluster"
kubectl config set-cluster default --server=${KUBERNETES_SERVER} --insecure-skip-tls-verify=true kubectl config set-cluster default --server=${PLUGIN_KUBERNETES_SERVER} --insecure-skip-tls-verify=true
else
echo "${PLUGIN_KUBERNETES_CERT}" | base64 -d > ca.crt
kubectl config set-cluster default --server=${PLUGIN_KUBERNETES_SERVER} --certificate-authority=ca.crt
fi fi
kubectl config set-context default --cluster=default --user=${PLUGIN_KUBERNETES_USER} kubectl config set-context default --cluster=default --user=${PLUGIN_KUBERNETES_USER}
kubectl config use-context default kubectl config use-context default
# kubectl version IFS=',' read -r -a DEPLOYMENTS <<< "${PLUGIN_DEPLOYMENT:-}"
IFS=',' read -r -a DEPLOYMENTS <<< "${PLUGIN_DEPLOYMENT}" IFS=',' read -r -a CONTAINERS <<< "${PLUGIN_CONTAINER:-}"
IFS=',' read -r -a CONTAINERS <<< "${PLUGIN_CONTAINER}"
for DEPLOY in ${DEPLOYMENTS[@]}; do for DEPLOY in ${DEPLOYMENTS[@]}; do
echo Deploying to $KUBERNETES_SERVER echo Deploying to $PLUGIN_KUBERNETES_SERVER
for CONTAINER in ${CONTAINERS[@]}; do for CONTAINER in ${CONTAINERS[@]}; do
if [[ ${PLUGIN_FORCE} == "true" ]]; then if [ ${PLUGIN_FORCE:-} == "true" ]; then
# force changing the image by changing it to the TAG + FORCE then changing it back
kubectl -n ${PLUGIN_NAMESPACE} set image deployment/${DEPLOY} \ kubectl -n ${PLUGIN_NAMESPACE} set image deployment/${DEPLOY} \
${CONTAINER}=${PLUGIN_REPO}:${PLUGIN_TAG}FORCE ${CONTAINER}=${PLUGIN_REPO}:${PLUGIN_TAG:-}FORCE
fi fi
kubectl -n ${PLUGIN_NAMESPACE} set image deployment/${DEPLOY} \ kubectl -n ${PLUGIN_NAMESPACE} set image deployment/${DEPLOY} \
${CONTAINER}=${PLUGIN_REPO}:${PLUGIN_TAG} --record ${CONTAINER}=${PLUGIN_REPO}:${PLUGIN_TAG:-} --record
done done
done done