From 856f6d7f0d3945bc365c7d24259e9b015c798130 Mon Sep 17 00:00:00 2001 From: so0k Date: Tue, 12 Dec 2017 22:10:00 +0800 Subject: [PATCH] Initial commit --- README.md | 21 +++++++++++++++++++++ helmns | 24 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 README.md create mode 100755 helmns diff --git a/README.md b/README.md new file mode 100644 index 0000000..1ca21b5 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# Helmns + +helmns is a [Helm](http://helm.sh) cli wrapper forcing `--tiller-namespace` to match kubectl context. + +This is meant to simplify management for Kubernetes clusters with RBAC enabled and where tiller is heavily locked down per namespace. + +----- + +## Installation + +Since `helmns` is written in Bash, it can run in shells that support POSIX standards. + +- Download the `helmns` script +- Either: + - save to somewhere in your `PATH`, + - or save to a directory, then create symlinks to `helmns` from somewhere in your `PATH`, like `/usr/local/bin` +- Make `helmns` executable (`chmod +x ...`) + +----- + +Heavily based on [ahmetb/kubens](https://github.com/ahmetb/kubectx) diff --git a/helmns b/helmns new file mode 100755 index 0000000..f0d1421 --- /dev/null +++ b/helmns @@ -0,0 +1,24 @@ +#!/bin/bash +# +# helmns(1) is a utility to force tiller-namespace to current namespace + +[[ -n $DEBUG ]] && set -x + +set -eou pipefail +IFS=$'\n\t' + +current_context() { + kubectl config view -o=jsonpath='{.current-context}' +} + +current_namespace() { + local cur_ctx=$(current_context) + ns="$(kubectl config view -o=jsonpath="{.contexts[?(@.name==\"${cur_ctx}\")].context.namespace}")" + if [[ -z "${ns}" ]]; then + echo "default" + else + echo "${ns}" + fi +} + +exec helm --tiller-namespace "$(current_namespace)" "$@"