#!/bin/bash # Use # ./updateprojectspace 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"