Skip to content

Instantly share code, notes, and snippets.

@efossas
efossas / kubectl_save_all_contexts.sh
Created August 16, 2022 02:36
Kubectl Save All Contexts
contexts="$(cat "$KUBECONFIG" | yq e ".contexts[].name" -)";
for current_context in $contexts; do
kubeconfig_path="$(printf "%s" "$current_context" | rev | cut -d'/' -f1 | rev)";
kubectl config view --minify --flatten --context="$current_context" > "$kubeconfig_path";
if [[ "$?" != "0" ]]; then
rm -f "$kubeconfig_path";
echo "bad context: $current_context";
fi;
done;
@efossas
efossas / kubectl_print_all_contexts.sh
Created August 16, 2022 02:34
Kubectl Print All Contexts
contexts="$(cat "$KUBECONFIG" | yq e ".contexts[].name" -)";
for current_context in $contexts; do
kubectl config view --minify --flatten --context="$current_context" || echo "bad context: $current_context";
echo "---";
done;
@efossas
efossas / kubectl_print_context.sh
Last active September 18, 2022 09:47
Kubectl Print Context
# kubectl_print_context CONTEXT_NAME
kubectl_print_context() {
kubectl config view --minify --flatten --context="$1";
}
@efossas
efossas / kubectl_current_context.sh
Created August 16, 2022 02:30
Kubectl Get Current-Context
kubectl config view --minify --flatten --context="$(kubectl config current-context)";
@efossas
efossas / capacity.sh
Created July 11, 2022 04:37
View Node Capacity
# capacity
capacity() {
echo "node cpu.capacity cpu.allocatable memory.capacity memory.allocatable" | awk '{printf "%-50s %-20s %-20s %-20s %-20s \n", $1, $2, $3, $4, $5}';
kubectl get nodes -o json | jq -r '.items[] | "\(.metadata.name) \(.status.capacity.cpu) \(.status.allocatable.cpu) \(.status.capacity.memory) \(.status.allocatable.memory)"' | awk '{printf "%-50s %-20s %-20s %-20s %-20s \n", $1, $2, $3, $4, $5}';
}
@efossas
efossas / system.sh
Created July 5, 2022 04:04
Sort Kubernetes Pod CPU & Memory Usage
# system [cpu|mem]
system() {
if [[ "$1" == "cpu" ]]; then
kubectl top pod --all-namespaces | tail -n +2 | sort --reverse --key 3 --numeric;
elif [[ "$1" == "mem" ]]; then
kubectl top pod --all-namespaces | tail -n +2 | sort --reverse --key 4 --numeric;
else
echo "unknown resource type";
fi;
}
@efossas
efossas / .github-env-share.yml
Created July 4, 2022 06:23
Github Actions Share Environment Variable
jobs:
setup-env:
runs-on: ubuntu-latest
steps:
- id: setup-env
# pass secret in as input
with:
MY_SECRET: ${{ secrets.MY_SECRET }}
# or pass in secret as environment variable
env:
@efossas
efossas / .github-job-outputs.yml
Created July 4, 2022 06:18
Github Job Outputs
# so many steps to share a value 🙁
# set-output command -> internal key name -> output key name -> needs on next job -> handlebars (not portable)
jobs:
setup:
runs-on: ubuntu-latest
outputs:
key-name-alt: ${{ steps.set-value.outputs.key-name }}
steps:
- id: set-value
run: echo "::set-output name=key-name::value-goes-here"
@efossas
efossas / .github-workflow-call.yml
Created June 30, 2022 15:08
Github Empty Variables
on:
workflow_call:
inputs:
BUILD_NO_CACHE:
description: 'Add any value to disable build caching'
default: ''
required: false
type: string
@efossas
efossas / .gitlab-ci.yml
Last active September 18, 2022 09:47
Gitlab Empty Variables
variables:
BUILD_NO_CACHE:
value: ""
description: "Add any value to build your Dockerfiles without using the cache"