Files
userspace/updateprojectspace.sh
2021-02-05 14:52:08 -05:00

34 lines
880 B
Bash
Executable File

#!/bin/bash
export PROJECT=$1
export USER=$2
export SERVER=$3
export SERVER_PROJECT_DIR="~/.kube/projects/$PROJECT"
echo "Checking if project namespace exists"
exists=$(ssh $SERVER "kubectl get namespace --output=jsonpath=\"{.items[?(@.metadata.name=='$PROJECT')].metadata.name}\"")
if [ -z $exists ]; then
echo "Namespace not found, nothing to update"
exit 1
else
echo "Namespace exists, updating"
fi
echo "Templating namespace with helm and copying to server"
helm template $PROJECT ./namespace --set user=$USER | ssh $SERVER "cat - > $SERVER_PROJECT_DIR/namespace.yaml"
if [ $? -ne 0 ]; then
echo "Failed to template namespace. Is helm installed?"
exit 1
fi
echo "Updating namespace with template"
ssh $SERVER "kubectl apply -f $SERVER_PROJECT_DIR/namespace.yaml"
if [ $? -ne 0 ]; then
echo "Failed to update namespace"
exit 1
fi
echo "done"