Files
userspace/updateprojectspace.sh
2021-12-24 15:42:07 -04:00

38 lines
942 B
Bash
Executable File

#!/bin/bash
# Use
# ./updateprojectspace <server_fqdn> <user> <project>
export SERVER=$1
export USER=$2
export PROJECT=$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"