gitpod/scripts/branch-namespace.sh
2020-08-25 09:25:15 +00:00

9 lines
452 B
Bash
Executable File

#!/bin/bash
branch=`git symbolic-ref HEAD 2>&1` || error "cannot set kubectl namespace: no branch"
currentContext=`kubectl config current-context 2>&1` || error "cannot set kubectl namespace: no current context"
namespace=staging-`echo "$branch" | awk '{ sub(/^refs\/heads\//, ""); $0 = tolower($0); gsub(/[^-a-z0-9]/, "-"); print }'`
echo "Setting kubectl namespace: $namespace"
kubectl config set-context "$currentContext" --namespace "$namespace"