From fafc1e272010aae9a0083616e4a7b9ddae545696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=A9o=20M=C3=A9vollon?= Date: Thu, 27 Oct 2022 18:12:22 +0200 Subject: [PATCH] fix: do not remove label --- nsplease.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nsplease.sh b/nsplease.sh index e07cd9f..8fc618c 100644 --- a/nsplease.sh +++ b/nsplease.sh @@ -11,18 +11,19 @@ out() { } main() { - info "waiting for 'nsplease/project' labelled namespaces..." + info "waiting for namespaces with label 'nsplease/done=false'..." - # watch namespace creations, only ADDED type and labelled with nsplease/project + # watch namespace creations, only ADDED type and labeled with nsplease/project kubectl get namespace --watch --output-watch-events -o json | jq --unbuffered --raw-output \ 'if (.object.metadata.labels | has("nsplease/project")) - and .type == "ADDED" then + and (.object.metadata.labels."nsplease/done" == "false") + and (.type == "ADDED") then [.object.metadata.name, .object.metadata.labels."nsplease/project"] | @tsv else empty end' | while read -r NAMESPACE PROJECT; do - info "got labelled namespace: $NAMESPACE $PROJECT" + info "got labeled namespace: $NAMESPACE $PROJECT" # create privileged role in requested namespace out kubectl create role nsplease-role \ @@ -37,7 +38,7 @@ main() { --serviceaccount="$PROJECT:nsplease-sa" # remove label to avoid doing this again for the same namespace - out kubectl label namespace "$NAMESPACE" nsplease/project- + out kubectl label namespace --overwrite "$NAMESPACE" nsplease/done=true done }