Compare commits

...

2 Commits

Author SHA1 Message Date
4528e35872 Disable/enable webhooks
Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
2022-03-11 18:38:47 +00:00
381adefe87 Make things pretty
Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
2022-03-11 18:38:32 +00:00
20 changed files with 273 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
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)"

View File

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

View File

@@ -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)"
}

View File

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

View File

@@ -1,19 +1,25 @@
#!/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"
}
@@ -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

View File

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

View File

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

View File

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

61
home/.bin/kube-disable-webhook Executable file
View File

@@ -0,0 +1,61 @@
#!/usr/bin/env bash
source .utils
set -e
WEBHOOK_TYPE="mutating"
print_usage() {
blue "kube-disable-webhook - Disabled a webhook by modifying the namespace selector"
echo " "
underline "Usage:"
echo "kube-disable-webhook [options] NAME"
echo " "
underline "Options:"
echo "-h, --help show this help text"
echo "-t, --type the type of webhook [mutating (default), validating]"
}
while test $# -gt 0; do
case "$1" in
-t|--type)
shift
WEBHOOK_TYPE=$1
shift
;;
-h|--help)
print_usage
exit 0
;;
*)
break
;;
esac
done
NAME=${1}
FAKE_SELECTOR='"namespaceSelector":{"matchExpressions":[{"key":"disabled","operator":"In","values":["webhook"]}]}'
if [[ "${WEBHOOK_TYPE}" == "mutating" ]]; then
printf "🚫 Disabling mutating webhook ${NAME}..."
kubectl annotate mutatingwebhookconfigurations.admissionregistration.k8s.io ${NAME} previous-state='kubectl get mutatingwebhookconfigurations.admissionregistration.k8s.io ${NAME} -o json'
HOOKS=$(kubectl get mutatingwebhookconfigurations.admissionregistration.k8s.io ${NAME} -o go-template='{{range .webhooks}}{{.name}}{{"\n"}}{{end}}')
for HOOK in ${HOOKS}
do
kubectl patch mutatingwebhookconfigurations.admissionregistration.k8s.io ${NAME} -p '{"webhooks": [{"name": "'${HOOK}'", '${FAKE_SELECTOR}'}]}' 1>/dev/null
done
printf " ✅ Done"
elif [[ "${WEBHOOK_TYPE}" == "validating" ]]; then
printf "🚫 Disabling validating webhook ${NAME}..."
kubectl annotate validatingwebhookconfigurations.admissionregistration.k8s.io ${NAME} previous-state='kubectl get validatingwebhookconfigurations.admissionregistration.k8s.io ${NAME} -o json'
HOOKS=$(kubectl get validatingwebhookconfigurations.admissionregistration.k8s.io ${NAME} -o go-template='{{range .webhooks}}{{.name}}{{"\n"}}{{end}}')
for HOOK in ${HOOKS}
do
kubectl patch validatingwebhookconfigurations.admissionregistration.k8s.io ${NAME} -p '{"webhooks": [{"name": "'${HOOK}'", '${FAKE_SELECTOR}'}]}' 1>/dev/null
done
printf " ✅ Done"
else
echo "Unknown webhook type"
exit 1
fi

View File

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

View File

@@ -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)"
}

View File

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

View File

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

51
home/.bin/kube-reenable-webhook Executable file
View File

@@ -0,0 +1,51 @@
#!/usr/bin/env bash
source .utils
set -e
WEBHOOK_TYPE="mutating"
print_usage() {
blue "kube-reenable-webhook - Re-enable a previously disabled webhook"
echo " "
underline "Usage:"
echo "kube-reenable-webhook [options] NAME"
echo " "
underline "Options:"
echo "-h, --help show this help text"
echo "-t, --type the type of webhook [mutating (default), validating]"
}
while test $# -gt 0; do
case "$1" in
-t|--type)
shift
WEBHOOK_TYPE=$1
shift
;;
-h|--help)
print_usage
exit 0
;;
*)
break
;;
esac
done
NAME=${1}
FAKE_SELECTOR='"namespaceSelector":{"matchExpressions":[{"key":"disabled","operator":"In","values":["webhook"]}]}'
if [[ "${WEBHOOK_TYPE}" == "mutating" ]]; then
printf "🔌 Re-enabling mutating webhook ${NAME}..."
kubectl get mutatingwebhookconfigurations.admissionregistration.k8s.io ${NAME} -o custom-columns="prev:.metadata.annotations.previous-state" --no-headers | kubectl apply -f -
printf " ✅ Done"
elif [[ "${WEBHOOK_TYPE}" == "validating" ]]; then
printf "🔌 Re-enabling validating webhook ${NAME}..."
kubectl get validatingwebhookconfigurations.admissionregistration.k8s.io ${NAME} -o custom-columns="prev:.metadata.annotations.previous-state" --no-headers | kubectl apply -f -
printf " ✅ Done"
else
echo "Unknown webhook type"
exit 1
fi

View File

@@ -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)"
}

View File

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

View File

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

View File

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

View File

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