Make things pretty

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
Marcus Noble 2022-03-11 18:38:32 +00:00
parent b9647b569d
commit 381adefe87
Signed by: AverageMarcus
GPG Key ID: B8F2DB8A7AEBAF78
18 changed files with 161 additions and 63 deletions

39
home/.bin/.utils Normal file
View File

@ -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

View File

@ -1,17 +1,20 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source .utils
ACCOUNT_ID=${AWS_ACCOUNTID} ACCOUNT_ID=${AWS_ACCOUNTID}
ROLE=GiantSwarmAdmin ROLE=GiantSwarmAdmin
MFA= MFA=
MFA_ARN=arn:aws:iam::${AWS_ACCOUNTID}:mfa/marcus@giantswarm.io MFA_ARN=arn:aws:iam::${AWS_ACCOUNTID}:mfa/marcus@giantswarm.io
print_usage() { print_usage() {
echo "gs-aws - set up AWS credentials" orange "gs-aws - set up AWS credentials"
echo " " echo " "
underline "Usage:"
echo "gs-aws" echo "gs-aws"
echo " " echo " "
echo " " echo " "
echo "Options:" underline "Options:"
echo "-h, --help show this help text" echo "-h, --help show this help text"
echo "-a, --account the AWS account number (default: \$AWS_ACCOUNTID)" echo "-a, --account the AWS account number (default: \$AWS_ACCOUNTID)"
echo "-r, --role the role to assume (default: GiantSwarmAdmin)" echo "-r, --role the role to assume (default: GiantSwarmAdmin)"

View File

@ -1,17 +1,20 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source .utils
NAMESPACE="org-giantswarm" NAMESPACE="org-giantswarm"
RELEASE="20.0.0-alpha1" RELEASE="20.0.0-alpha1"
PROVIDER="aws" PROVIDER="aws"
AZS="eu-west-1a" AZS="eu-west-1a"
print_usage() { 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 " " echo " "
underline "Usage:"
echo "gs-create-cluster [cluster-name]" echo "gs-create-cluster [cluster-name]"
echo " " echo " "
echo " " echo " "
echo "Options:" underline "Options:"
echo "-h, --help show this help text" echo "-h, --help show this help text"
echo "-n, --namespace the namespace the cluster is in (default: org-giantswarm)" 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)" echo "-r, --release the namespace the cluster is in (default: 20.0.0-alpha1)"

View File

@ -1,16 +1,19 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source .utils
set -e set -e
NAMESPACE="org-giantswarm" NAMESPACE="org-giantswarm"
print_usage() { 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 " " echo " "
underline "Usage:"
echo "gs-get-cluster [cluster-name]" echo "gs-get-cluster [cluster-name]"
echo " " echo " "
echo " " echo " "
echo "Options:" underline "Options:"
echo "-h, --help show this help text" echo "-h, --help show this help text"
echo "-n, --namespace the namespace the cluster is in (default: org-giantswarm)" echo "-n, --namespace the namespace the cluster is in (default: org-giantswarm)"
} }

View File

@ -1,17 +1,20 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source .utils
DEBUG="" DEBUG=""
print_usage() { print_usage() {
echo "gs-login - login to Giant Swarm managed clusters" orange "gs-login - login to Giant Swarm managed clusters"
echo " " echo " "
underline "Usage:"
echo "gs-login [INSTALLATION] [WORKLOAD CLUSTER] [ORGANISATION]" echo "gs-login [INSTALLATION] [WORKLOAD CLUSTER] [ORGANISATION]"
echo " " echo " "
echo "Examples:" underline "Examples:"
echo "> gs-login gauss" echo "> gs-login gauss"
echo "> gs-login gauss mywc1" echo "> gs-login gauss mywc1"
echo " " echo " "
echo "Options:" underline "Options:"
echo "-h, --help show this help text" echo "-h, --help show this help text"
} }

View File

@ -1,19 +1,25 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source .utils
DEBUG="" DEBUG=""
SUPPORTED_APPS="alertmanager argocd grafana happa kibana kyverno prometheus" SUPPORTED_APPS="alertmanager cloudprovider grafana happa kibana kyverno prometheus"
print_usage() { print_usage() {
echo "gs-open - open apps on Giant Swarm clusters" orange "gs-open - open apps on Giant Swarm clusters"
echo " " echo " "
underline "Usage:"
echo "gs-open [APP] [INSTALLATION] [WORKLOAD CLUSTER] " echo "gs-open [APP] [INSTALLATION] [WORKLOAD CLUSTER] "
echo " " echo " "
echo "Examples:" underline "Supported apps:"
italic "${SUPPORTED_APPS}"
echo " "
underline "Examples:"
echo "> gs-open prometheus gauss" echo "> gs-open prometheus gauss"
echo "> gs-open alertmanager gauss mywc1" echo "> gs-open alertmanager gauss mywc1"
echo " " echo " "
echo "Options:" underline "Options:"
echo "-h, --help show this help text" echo "-h, --help show this help text"
echo " --debug show debug log output" echo " --debug show debug log output"
} }
@ -48,17 +54,25 @@ if [ ${#POS_ARGS[@]} -eq 1 ]; then
POS_ARGS+=(`opsctl list installations --short | tr ' ' '\n' | fzf`) POS_ARGS+=(`opsctl list installations --short | tr ' ' '\n' | fzf`)
fi fi
APP=${POS_ARGS[0]}
if [[ "${APP}" == "cloud" ]]; then
APP=cloudprovider
fi
if [[ "${APP}" == "prom" ]]; then
APP=prometheus
fi
case ${#POS_ARGS[@]} in case ${#POS_ARGS[@]} in
0) 0)
print_usage print_usage
exit 1 exit 1
;; ;;
2) 2)
echo "✨ Opening ${POS_ARGS[0]} on ${POS_ARGS[1]}" echo "✨ Opening ${APP} on ${POS_ARGS[1]}"
opsctl open ${DEBUG} --app ${POS_ARGS[0]} --installation ${POS_ARGS[1]} opsctl open ${DEBUG} --app ${APP} --installation ${POS_ARGS[1]}
;; ;;
3) 3)
echo "✨ Opening ${POS_ARGS[0]} on ${POS_ARGS[1]}/${POS_ARGS[2]}" echo "✨ Opening ${APP} on ${POS_ARGS[1]} / ${POS_ARGS[2]}"
opsctl open ${DEBUG} --app ${POS_ARGS[0]} --installation ${POS_ARGS[1]} --workload-cluster ${POS_ARGS[2]} opsctl open ${DEBUG} --app ${APP} --installation ${POS_ARGS[1]} --workload-cluster ${POS_ARGS[2]}
;; ;;
esac esac

View File

@ -1,14 +1,17 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source .utils
set -e set -e
print_usage() { 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 " " echo " "
underline "Usage:"
echo "gs-release [SEMVER LEVEL]" echo "gs-release [SEMVER LEVEL]"
echo " " echo " "
echo " " echo " "
echo "Options:" underline "Options:"
echo "-h, --help show this help text" echo "-h, --help show this help text"
} }

View File

@ -1,18 +1,20 @@
#!/usr/bin/env bash #!/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=${NAMESPACE:-default}
LABEL="" LABEL=""
ALL_NAMESPACES=false ALL_NAMESPACES=false
print_usage() { 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 " " echo " "
underline "Usage:"
echo "kube-all [options]" echo "kube-all [options]"
echo " " echo " "
echo "Options:" underline "Options:"
echo "-h, --help show this help text" echo "-h, --help show this help text"
echo "-n, --namespace the namespace the to search in" echo "-n, --namespace the namespace the to search in"
echo "-l, --selector the label selector to match on" echo "-l, --selector the label selector to match on"

View File

@ -1,17 +1,20 @@
#!/usr/bin/env bash #!/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="" LABEL=""
ALL_NAMESPACES=false ALL_NAMESPACES=false
print_usage() { 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 " " echo " "
underline "Usage:"
echo "kube-clean-replicasets [options]" echo "kube-clean-replicasets [options]"
echo " " echo " "
echo "Options:" underline "Options:"
echo "-h, --help show this help text" echo "-h, --help show this help text"
echo "-n, --namespace the namespace the to search in" echo "-n, --namespace the namespace the to search in"
echo "-l, --selector the label selector to match on" echo "-l, --selector the label selector to match on"

View File

@ -1,17 +1,20 @@
#!/usr/bin/env bash #!/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="" POD=""
CMD="sh" CMD="sh"
print_usage() { print_usage() {
echo "kube-exec - execute commands within a pod" blue "kube-exec - execute commands within a pod"
echo " " echo " "
underline "Usage:"
echo "kube-exec [options]" echo "kube-exec [options]"
echo " " echo " "
echo "Options:" underline "Options:"
echo "-h, --help show this help text" echo "-h, --help show this help text"
echo "-n, --namespace the namespace the pod is in" echo "-n, --namespace the namespace the pod is in"
echo "-p, --pod the name of the pod" echo "-p, --pod the name of the pod"

View File

@ -1,16 +1,18 @@
#!/usr/bin/env bash #!/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=${NAMESPACE:-default}
print_usage() { 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 " " echo " "
underline "Usage:"
echo "kube-force-delete [RESOURCE_TYPE] [RESOURCE_NAME]" echo "kube-force-delete [RESOURCE_TYPE] [RESOURCE_NAME]"
echo " " echo " "
echo "Options:" underline "Options:"
echo "-h, --help show this help text" echo "-h, --help show this help text"
echo "-n, --namespace the namespace the resource is in (default: current namespace)" echo "-n, --namespace the namespace the resource is in (default: current namespace)"
} }

View File

@ -1,16 +1,20 @@
#!/usr/bin/env bash #!/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 HOST_PORT=10001
print_usage() { 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 " " echo " "
underline "Usage:"
echo "kube-forward-all [options]" echo "kube-forward-all [options]"
echo " " echo " "
echo "Options:" underline "Options:"
echo "-h, --help show this help text" echo "-h, --help show this help text"
echo "-n, --namespace the namespace to launch the pod in" 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)" echo "-p, --port the port to start at (and increment from for each service) (default: 10001)"

View File

@ -1,17 +1,20 @@
#!/usr/bin/env bash #!/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="" POD=""
ARGS="" ARGS=""
print_usage() { print_usage() {
echo "kube-logs - tail logs from a pod" blue "kube-logs - tail logs from a pod"
echo " " echo " "
underline "Usage:"
echo "kube-logs [options]" echo "kube-logs [options]"
echo " " echo " "
echo "Options:" underline "Options:"
echo "-h, --help show this help text" echo "-h, --help show this help text"
echo "-n, --namespace the namespace the pod is in" echo "-n, --namespace the namespace the pod is in"
echo "-p, --pod the name of the pod to get logs for" echo "-p, --pod the name of the pod to get logs for"

View File

@ -1,16 +1,19 @@
#!/usr/bin/env bash #!/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" NAMESPACE="-A"
print_usage() { print_usage() {
echo "kube-restarting - Show all pods with restarts" blue "kube-restarting - Show all pods with restarts"
echo " " echo " "
underline "Usage:"
echo "kube-restarting [options]" echo "kube-restarting [options]"
echo " " echo " "
echo "Options:" underline "Options:"
echo "-h, --help show this help text" echo "-h, --help show this help text"
echo "-n, --namespace the namespace the to search in (searches all if not set)" echo "-n, --namespace the namespace the to search in (searches all if not set)"
} }

View File

@ -1,18 +1,21 @@
#!/usr/bin/env bash #!/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" POD="shell"
IMAGE="bash" IMAGE="bash"
CMD="sh" CMD="sh"
print_usage() { 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 " " echo " "
underline "Usage:"
echo "kube-shell [options]" echo "kube-shell [options]"
echo " " echo " "
echo "Options:" underline "Options:"
echo "-h, --help show this help text" echo "-h, --help show this help text"
echo "-n, --namespace the namespace the pod should launch in" echo "-n, --namespace the namespace the pod should launch in"
echo "-p, --pod the name of the pod to get logs for (default: shell)" echo "-p, --pod the name of the pod to get logs for (default: shell)"

View File

@ -1,18 +1,20 @@
#!/usr/bin/env bash #!/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=${NAMESPACE:-default}
POD="kube-ssh" POD="kube-ssh"
NODE="" NODE=""
print_usage() { 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 " " echo " "
underline "Usage:"
echo "kube-ssh [options]" echo "kube-ssh [options]"
echo " " echo " "
echo "Options:" underline "Options:"
echo "-h, --help show this help text" echo "-h, --help show this help text"
echo "-n, --namespace the namespace to launch the pod in" echo "-n, --namespace the namespace to launch the pod in"
echo "-p, --pod the name of the pod to launch (default: kube-ssh)" echo "-p, --pod the name of the pod to launch (default: kube-ssh)"

View File

@ -1,15 +1,18 @@
#!/usr/bin/env bash #!/usr/bin/env bash
NAMESPACE="" source .utils
NAMESPACE="$(kubectl config view --minify --output 'jsonpath={..namespace}' &>/dev/null)"
set -e set -e
NAMESPACE=${NAMESPACE:-default}
print_usage() { print_usage() {
echo "kube-template - Quickly template up kubernetes resources" blue "kube-template - Quickly template up kubernetes resources"
echo " " echo " "
underline "Usage:"
echo "kube-template [options] RESOURCE_KIND NAME [extra arguments]" echo "kube-template [options] RESOURCE_KIND NAME [extra arguments]"
echo " " echo " "
echo "Options:" underline "Options:"
echo "-h, --help show this help text" echo "-h, --help show this help text"
echo "-n, --namespace the namespace the to search in" echo "-n, --namespace the namespace the to search in"
} }

View File

@ -1,16 +1,18 @@
#!/usr/bin/env bash #!/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=${NAMESPACE:-default}
print_usage() { 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 " " echo " "
underline "Usage:"
echo "kube-trigger-cronjob [options] CRONJOB_NAME" echo "kube-trigger-cronjob [options] CRONJOB_NAME"
echo " " echo " "
echo "Options:" underline "Options:"
echo "-h, --help show this help text" echo "-h, --help show this help text"
echo "-n, --namespace the namespace the to search in" echo "-n, --namespace the namespace the to search in"
} }