From 381adefe8707836b8e5830d32bffb9e2d5a76c66 Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Fri, 11 Mar 2022 18:38:32 +0000 Subject: [PATCH] Make things pretty Signed-off-by: Marcus Noble --- home/.bin/.utils | 39 ++++++++++++++++++++++++++++++++ home/.bin/gs-aws | 7 ++++-- home/.bin/gs-create-cluster | 7 ++++-- home/.bin/gs-get-cluster | 7 ++++-- home/.bin/gs-login | 9 +++++--- home/.bin/gs-open | 32 ++++++++++++++++++-------- home/.bin/gs-release | 7 ++++-- home/.bin/kube-all | 10 ++++---- home/.bin/kube-clean-replicasets | 11 +++++---- home/.bin/kube-exec | 11 +++++---- home/.bin/kube-force-delete | 10 ++++---- home/.bin/kube-forward-all | 12 ++++++---- home/.bin/kube-logs | 11 +++++---- home/.bin/kube-restarting | 11 +++++---- home/.bin/kube-shell | 11 +++++---- home/.bin/kube-ssh | 10 ++++---- home/.bin/kube-template | 9 +++++--- home/.bin/kube-trigger-cronjob | 10 ++++---- 18 files changed, 161 insertions(+), 63 deletions(-) create mode 100644 home/.bin/.utils diff --git a/home/.bin/.utils b/home/.bin/.utils new file mode 100644 index 0000000..89b0e36 --- /dev/null +++ b/home/.bin/.utils @@ -0,0 +1,39 @@ +END_CHARS="\e[0m\n" +tput colors &>/dev/null +if [ $? -eq 0 ]; then + bold() { + printf "\e[1m$@${END_CHARS}" + } + + italic() { + printf "\e[3m$@${END_CHARS}" + } + + underline() { + printf "\e[4m$@${END_CHARS}" + } + + orange() { + printf "\e[38;5;208m$@${END_CHARS}" + } + + blue() { + printf "\e[38;5;75m$@${END_CHARS}" + } +else + bold() { + echo $@ + } + + italic() { + echo $@ + } + + underline() { + echo $@ + } + + orange() { + echo $@ + } +fi diff --git a/home/.bin/gs-aws b/home/.bin/gs-aws index d1a665c..b8c0baa 100755 --- a/home/.bin/gs-aws +++ b/home/.bin/gs-aws @@ -1,17 +1,20 @@ #!/usr/bin/env bash +source .utils + ACCOUNT_ID=${AWS_ACCOUNTID} ROLE=GiantSwarmAdmin MFA= MFA_ARN=arn:aws:iam::${AWS_ACCOUNTID}:mfa/marcus@giantswarm.io print_usage() { - echo "gs-aws - set up AWS credentials" + orange "gs-aws - set up AWS credentials" echo " " + underline "Usage:" echo "gs-aws" echo " " echo " " - echo "Options:" + underline "Options:" echo "-h, --help show this help text" echo "-a, --account the AWS account number (default: \$AWS_ACCOUNTID)" echo "-r, --role the role to assume (default: GiantSwarmAdmin)" diff --git a/home/.bin/gs-create-cluster b/home/.bin/gs-create-cluster index 6e41d33..254ace3 100755 --- a/home/.bin/gs-create-cluster +++ b/home/.bin/gs-create-cluster @@ -1,17 +1,20 @@ #!/usr/bin/env bash +source .utils + NAMESPACE="org-giantswarm" RELEASE="20.0.0-alpha1" PROVIDER="aws" AZS="eu-west-1a" print_usage() { - echo "gs-create-cluster - create a Giant Swarm managed workload cluster" + orange "gs-create-cluster - create a Giant Swarm managed workload cluster" echo " " + underline "Usage:" echo "gs-create-cluster [cluster-name]" echo " " echo " " - echo "Options:" + underline "Options:" echo "-h, --help show this help text" echo "-n, --namespace the namespace the cluster is in (default: org-giantswarm)" echo "-r, --release the namespace the cluster is in (default: 20.0.0-alpha1)" diff --git a/home/.bin/gs-get-cluster b/home/.bin/gs-get-cluster index 4f09324..f395cb0 100755 --- a/home/.bin/gs-get-cluster +++ b/home/.bin/gs-get-cluster @@ -1,16 +1,19 @@ #!/usr/bin/env bash +source .utils + set -e NAMESPACE="org-giantswarm" print_usage() { - echo "gs-get-cluster - get a Giant Swarm managed workload cluster" + orange "gs-get-cluster - get a Giant Swarm managed workload cluster" echo " " + underline "Usage:" echo "gs-get-cluster [cluster-name]" echo " " echo " " - echo "Options:" + underline "Options:" echo "-h, --help show this help text" echo "-n, --namespace the namespace the cluster is in (default: org-giantswarm)" } diff --git a/home/.bin/gs-login b/home/.bin/gs-login index 7252795..9985bc5 100755 --- a/home/.bin/gs-login +++ b/home/.bin/gs-login @@ -1,17 +1,20 @@ #!/usr/bin/env bash +source .utils + DEBUG="" print_usage() { - echo "gs-login - login to Giant Swarm managed clusters" + orange "gs-login - login to Giant Swarm managed clusters" echo " " + underline "Usage:" echo "gs-login [INSTALLATION] [WORKLOAD CLUSTER] [ORGANISATION]" echo " " - echo "Examples:" + underline "Examples:" echo "> gs-login gauss" echo "> gs-login gauss mywc1" echo " " - echo "Options:" + underline "Options:" echo "-h, --help show this help text" } diff --git a/home/.bin/gs-open b/home/.bin/gs-open index c848c74..9e49078 100755 --- a/home/.bin/gs-open +++ b/home/.bin/gs-open @@ -1,21 +1,27 @@ #!/usr/bin/env bash +source .utils + DEBUG="" -SUPPORTED_APPS="alertmanager argocd grafana happa kibana kyverno prometheus" +SUPPORTED_APPS="alertmanager cloudprovider grafana happa kibana kyverno prometheus" print_usage() { - echo "gs-open - open apps on Giant Swarm clusters" + orange "gs-open - open apps on Giant Swarm clusters" echo " " + underline "Usage:" echo "gs-open [APP] [INSTALLATION] [WORKLOAD CLUSTER] " echo " " - echo "Examples:" + underline "Supported apps:" + italic "${SUPPORTED_APPS}" + echo " " + underline "Examples:" echo "> gs-open prometheus gauss" echo "> gs-open alertmanager gauss mywc1" echo " " - echo "Options:" + underline "Options:" echo "-h, --help show this help text" - echo "--debug show debug log output" + echo " --debug show debug log output" } POS_ARGS=() @@ -48,17 +54,25 @@ if [ ${#POS_ARGS[@]} -eq 1 ]; then POS_ARGS+=(`opsctl list installations --short | tr ' ' '\n' | fzf`) fi +APP=${POS_ARGS[0]} +if [[ "${APP}" == "cloud" ]]; then + APP=cloudprovider +fi +if [[ "${APP}" == "prom" ]]; then + APP=prometheus +fi + case ${#POS_ARGS[@]} in 0) print_usage exit 1 ;; 2) - echo "✨ Opening ${POS_ARGS[0]} on ${POS_ARGS[1]}" - opsctl open ${DEBUG} --app ${POS_ARGS[0]} --installation ${POS_ARGS[1]} + echo "✨ Opening ${APP} on ${POS_ARGS[1]}" + opsctl open ${DEBUG} --app ${APP} --installation ${POS_ARGS[1]} ;; 3) - echo "✨ Opening ${POS_ARGS[0]} on ${POS_ARGS[1]}/${POS_ARGS[2]}" - opsctl open ${DEBUG} --app ${POS_ARGS[0]} --installation ${POS_ARGS[1]} --workload-cluster ${POS_ARGS[2]} + echo "✨ Opening ${APP} on ${POS_ARGS[1]} / ${POS_ARGS[2]}" + opsctl open ${DEBUG} --app ${APP} --installation ${POS_ARGS[1]} --workload-cluster ${POS_ARGS[2]} ;; esac diff --git a/home/.bin/gs-release b/home/.bin/gs-release index 9c690a7..30e37e1 100755 --- a/home/.bin/gs-release +++ b/home/.bin/gs-release @@ -1,14 +1,17 @@ #!/usr/bin/env bash +source .utils + set -e print_usage() { - echo "gs-release - create a new release of a Giant Swarm repo" + orange "gs-release - create a new release of a Giant Swarm repo" echo " " + underline "Usage:" echo "gs-release [SEMVER LEVEL]" echo " " echo " " - echo "Options:" + underline "Options:" echo "-h, --help show this help text" } diff --git a/home/.bin/kube-all b/home/.bin/kube-all index f971236..c8597ec 100755 --- a/home/.bin/kube-all +++ b/home/.bin/kube-all @@ -1,18 +1,20 @@ #!/usr/bin/env bash -set -e +source .utils -NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}')" +NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}' &>/dev/null)" +set -e NAMESPACE=${NAMESPACE:-default} LABEL="" ALL_NAMESPACES=false print_usage() { - echo "kube-all - A better 'kubectl get all' - actually get all Kubernetes resources, including custom resources" + blue "kube-all - A better 'kubectl get all' - actually get all Kubernetes resources, including custom resources" echo " " + underline "Usage:" echo "kube-all [options]" echo " " - echo "Options:" + underline "Options:" echo "-h, --help show this help text" echo "-n, --namespace the namespace the to search in" echo "-l, --selector the label selector to match on" diff --git a/home/.bin/kube-clean-replicasets b/home/.bin/kube-clean-replicasets index d48aff4..7193438 100755 --- a/home/.bin/kube-clean-replicasets +++ b/home/.bin/kube-clean-replicasets @@ -1,17 +1,20 @@ #!/usr/bin/env bash -set -e +source .utils -NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}')" +NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}' &>/dev/null)" +set -e +NAMESPACE=${NAMESPACE:-default} LABEL="" ALL_NAMESPACES=false print_usage() { - echo "kube-clean-replicasets - Remove all olf ReplicaSets with 0 desired pods" + blue "kube-clean-replicasets - Remove all olf ReplicaSets with 0 desired pods" echo " " + underline "Usage:" echo "kube-clean-replicasets [options]" echo " " - echo "Options:" + underline "Options:" echo "-h, --help show this help text" echo "-n, --namespace the namespace the to search in" echo "-l, --selector the label selector to match on" diff --git a/home/.bin/kube-exec b/home/.bin/kube-exec index 22b98bb..d078695 100755 --- a/home/.bin/kube-exec +++ b/home/.bin/kube-exec @@ -1,17 +1,20 @@ #!/usr/bin/env bash -set -e +source .utils -NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}')" +NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}' &>/dev/null)" +set -e +NAMESPACE=${NAMESPACE:-default} POD="" CMD="sh" print_usage() { - echo "kube-exec - execute commands within a pod" + blue "kube-exec - execute commands within a pod" echo " " + underline "Usage:" echo "kube-exec [options]" echo " " - echo "Options:" + underline "Options:" echo "-h, --help show this help text" echo "-n, --namespace the namespace the pod is in" echo "-p, --pod the name of the pod" diff --git a/home/.bin/kube-force-delete b/home/.bin/kube-force-delete index 471602e..44deb92 100755 --- a/home/.bin/kube-force-delete +++ b/home/.bin/kube-force-delete @@ -1,16 +1,18 @@ #!/usr/bin/env bash -set -e +source .utils -NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}')" +NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}' &>/dev/null)" +set -e NAMESPACE=${NAMESPACE:-default} print_usage() { - echo "kube-force-delete - Force delete resources, even those with finalizers" + blue "kube-force-delete - Force delete resources, even those with finalizers" echo " " + underline "Usage:" echo "kube-force-delete [RESOURCE_TYPE] [RESOURCE_NAME]" echo " " - echo "Options:" + underline "Options:" echo "-h, --help show this help text" echo "-n, --namespace the namespace the resource is in (default: current namespace)" } diff --git a/home/.bin/kube-forward-all b/home/.bin/kube-forward-all index 06fae86..1bb961f 100755 --- a/home/.bin/kube-forward-all +++ b/home/.bin/kube-forward-all @@ -1,16 +1,20 @@ #!/usr/bin/env bash -set -e -NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}')" +source .utils + +NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}' &>/dev/null)" +set -e +NAMESPACE=${NAMESPACE:-default} HOST_PORT=10001 print_usage() { - echo "kube-forward-all - create port-forwards for all pods in the given namespace" + blue "kube-forward-all - create port-forwards for all pods in the given namespace" echo " " + underline "Usage:" echo "kube-forward-all [options]" echo " " - echo "Options:" + underline "Options:" echo "-h, --help show this help text" echo "-n, --namespace the namespace to launch the pod in" echo "-p, --port the port to start at (and increment from for each service) (default: 10001)" diff --git a/home/.bin/kube-logs b/home/.bin/kube-logs index c82ad98..eccbceb 100755 --- a/home/.bin/kube-logs +++ b/home/.bin/kube-logs @@ -1,17 +1,20 @@ #!/usr/bin/env bash -set -e +source .utils -NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}')" +NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}' &>/dev/null)" +set -e +NAMESPACE=${NAMESPACE:-default} POD="" ARGS="" print_usage() { - echo "kube-logs - tail logs from a pod" + blue "kube-logs - tail logs from a pod" echo " " + underline "Usage:" echo "kube-logs [options]" echo " " - echo "Options:" + underline "Options:" echo "-h, --help show this help text" echo "-n, --namespace the namespace the pod is in" echo "-p, --pod the name of the pod to get logs for" diff --git a/home/.bin/kube-restarting b/home/.bin/kube-restarting index f836fec..acd2617 100755 --- a/home/.bin/kube-restarting +++ b/home/.bin/kube-restarting @@ -1,16 +1,19 @@ #!/usr/bin/env bash -set -e +source .utils -NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}')" +NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}' &>/dev/null)" +set -e +NAMESPACE=${NAMESPACE:-default} NAMESPACE="-A" print_usage() { - echo "kube-restarting - Show all pods with restarts" + blue "kube-restarting - Show all pods with restarts" echo " " + underline "Usage:" echo "kube-restarting [options]" echo " " - echo "Options:" + underline "Options:" echo "-h, --help show this help text" echo "-n, --namespace the namespace the to search in (searches all if not set)" } diff --git a/home/.bin/kube-shell b/home/.bin/kube-shell index 0ccca34..897fb62 100755 --- a/home/.bin/kube-shell +++ b/home/.bin/kube-shell @@ -1,18 +1,21 @@ #!/usr/bin/env bash -set -e +source .utils -NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}')" +NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}' &>/dev/null)" +set -e +NAMESPACE=${NAMESPACE:-default} POD="shell" IMAGE="bash" CMD="sh" print_usage() { - echo "kube-shell - create a new pod and exec into it's shell" + blue "kube-shell - create a new pod and exec into it's shell" echo " " + underline "Usage:" echo "kube-shell [options]" echo " " - echo "Options:" + underline "Options:" echo "-h, --help show this help text" echo "-n, --namespace the namespace the pod should launch in" echo "-p, --pod the name of the pod to get logs for (default: shell)" diff --git a/home/.bin/kube-ssh b/home/.bin/kube-ssh index 8ba6d57..6365238 100755 --- a/home/.bin/kube-ssh +++ b/home/.bin/kube-ssh @@ -1,18 +1,20 @@ #!/usr/bin/env bash -set -e +source .utils -NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}')" +NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}' &>/dev/null)" +set -e NAMESPACE=${NAMESPACE:-default} POD="kube-ssh" NODE="" print_usage() { - echo "kube-ssh - gain access to a Kubernetes host node (ssh-like for when a host doesn't have ssh)" + blue "kube-ssh - gain access to a Kubernetes host node (ssh-like for when a host doesn't have ssh)" echo " " + underline "Usage:" echo "kube-ssh [options]" echo " " - echo "Options:" + underline "Options:" echo "-h, --help show this help text" echo "-n, --namespace the namespace to launch the pod in" echo "-p, --pod the name of the pod to launch (default: kube-ssh)" diff --git a/home/.bin/kube-template b/home/.bin/kube-template index 5d16b41..0038644 100755 --- a/home/.bin/kube-template +++ b/home/.bin/kube-template @@ -1,15 +1,18 @@ #!/usr/bin/env bash -NAMESPACE="" +source .utils +NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}' &>/dev/null)" set -e +NAMESPACE=${NAMESPACE:-default} print_usage() { - echo "kube-template - Quickly template up kubernetes resources" + blue "kube-template - Quickly template up kubernetes resources" echo " " + underline "Usage:" echo "kube-template [options] RESOURCE_KIND NAME [extra arguments]" echo " " - echo "Options:" + underline "Options:" echo "-h, --help show this help text" echo "-n, --namespace the namespace the to search in" } diff --git a/home/.bin/kube-trigger-cronjob b/home/.bin/kube-trigger-cronjob index 115c963..a0d3cff 100755 --- a/home/.bin/kube-trigger-cronjob +++ b/home/.bin/kube-trigger-cronjob @@ -1,16 +1,18 @@ #!/usr/bin/env bash -set -e +source .utils -NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}')" +NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}' &>/dev/null)" +set -e NAMESPACE=${NAMESPACE:-default} print_usage() { - echo "kube-trigger-cronjob - Triggers a CronJob by creating a new job based on it" + blue "kube-trigger-cronjob - Triggers a CronJob by creating a new job based on it" echo " " + underline "Usage:" echo "kube-trigger-cronjob [options] CRONJOB_NAME" echo " " - echo "Options:" + underline "Options:" echo "-h, --help show this help text" echo "-n, --namespace the namespace the to search in" }