Skip to content

Commit

Permalink
Merge pull request #160 from mintel/create-all-ns
Browse files Browse the repository at this point in the history
Create local namespaces from rendered manifests
  • Loading branch information
jtdoepke authored Jul 26, 2023
2 parents 1d0f4b0 + 4684e28 commit 8dbdc3e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions modules/k8s/local/create-ns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

K3D_CLUSTER_NAME=${K3D_CLUSTER_NAME:-"local"}

if [ "$(k3d cluster list | grep -o -E "^${K3D_CLUSTER_NAME}")" ]; then
if k3d cluster list | grep -q -o -E "^${K3D_CLUSTER_NAME}"; then
set +e
namespaces=$(tk env list --json | jq -r '.[].spec.namespace' | sort | uniq)
namespaces="$(find rendered -type f -path '*/manifests/*.yaml' -print0 | xargs -0 -P1 yq eval-all --output-format csv '[.metadata.namespace] | map(select(. != null))' | tr ',' '\n' | sort -u)"
while IFS= read -r namespace; do
echo "Creating namespace $namespace ....."
out=$(kubectl --context k3d-${K3D_CLUSTER_NAME} create namespace $namespace 2>&1)
out=$(kubectl --context "k3d-${K3D_CLUSTER_NAME}" create namespace "$namespace" 2>&1)
if [[ "$out" == *"AlreadyExists"* ]]; then
echo "Namespace $namespace already exists, skipping"
else
Expand Down

0 comments on commit 8dbdc3e

Please sign in to comment.