diff options
| author | Mehdi Sadeghi <mehdi@mehdix.org> | 2021-04-16 14:58:45 +0200 |
|---|---|---|
| committer | Mehdi Sadeghi <mehdi@mehdix.org> | 2021-04-16 14:58:45 +0200 |
| commit | 534744db72b63e9ab6a9ab3f35a6aa59d45d3b5b (patch) | |
| tree | 90c54fbe3fc30eee5da0763eb44966d66c91daf7 /.local/bin | |
Add dotfiles.
Diffstat (limited to '.local/bin')
| -rwxr-xr-x | .local/bin/kill-kube-ns | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/.local/bin/kill-kube-ns b/.local/bin/kill-kube-ns new file mode 100755 index 0000000..6fc9cc0 --- /dev/null +++ b/.local/bin/kill-kube-ns @@ -0,0 +1,48 @@ +#!/bin/bash + +############################################################################### +# Copyright (c) 2018 Red Hat Inc +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License 2.0 which is available at +# http://www.eclipse.org/legal/epl-2.0 +# +# SPDX-License-Identifier: EPL-2.0 +############################################################################### + +set -eo pipefail + +die() { echo "$*" 1>&2 ; exit 1; } + +need() { + which "$1" &>/dev/null || die "Binary '$1' is missing but required" +} + +# checking pre-reqs + +need "jq" +need "curl" +need "kubectl" + +PROJECT="$1" +shift + +test -n "$PROJECT" || die "Missing arguments: kill-ns <namespace>" + +kubectl proxy &>/dev/null & +PROXY_PID=$! +killproxy () { + kill $PROXY_PID +} +trap killproxy EXIT + +sleep 1 # give the proxy a second + +kubectl get namespace "$PROJECT" -o json | jq 'del(.spec.finalizers[] | select("kubernetes"))' | curl -s -k -H "Content-Type: application/json" -X PUT -o /dev/null --data-binary @- http://localhost:8001/api/v1/namespaces/$PROJECT/finalize && echo "Killed namespace: $PROJECT" + +# proxy will get killed by the trap + + |
