Skip to content

Instantly share code, notes, and snippets.

View rjchicago's full-sized avatar
💭
🐳 🚢 🏗️

Ryan Jones rjchicago

💭
🐳 🚢 🏗️
View GitHub Profile
@rjchicago
rjchicago / set_ci_variables.sh
Created November 13, 2024 21:52
Example script to generate CI variables for a build process
#!/bin/sh
set -Eeou pipefail
# args
MAIN_BRANCH=${MAIN_BRANCH:-main}
BUILD_NUMBER=${BUILD_NUMBER:-0}
docker_tag_parse_string() {
KEY=$(echo $1 | awk '{print tolower($0)}')
re='(.*)[^a-z0-9.-]+(.*)'
# Include all kube configs
export KUBECONFIG=~/.kube/config$(for YAML in $(find ${HOME}/.kube -name '*.y*ml') ; do echo -n ":${YAML}"; done)
# get pods per namespace
alias kpns="kubectl get pods -A | sed 1d | awk '{print \$1}' | sort | uniq -c | sort -k1 -n -r"
# get pods per node
alias kpn="kubectl get pods -A -o jsonpath='{range .items[?(@.spec.nodeName)]}{.spec.nodeName}{\"\n\"}{end}' | sort | uniq -c | sort -rn"
@rjchicago
rjchicago / pipefail.md
Created August 29, 2024 18:39
Bash: set -Eeou pipefail explained by Amazon Q

The code snippet you provided is:

set -Eeou pipefail

This is a Bash shell command that sets various options to control how the shell behaves and handles errors. Let's break down what each part of this command does:

set is a built-in Bash command used to set or unset shell options and positional parameters.

# K2D
# <https://docs.k2d.io/quick-start-guide>
SECRET=asdasd
docker run --rm -d \
--name k2d-k2d \
--network bridge \
--publish 6443:6443 \
@rjchicago
rjchicago / k8s_list_taints.sh
Created May 6, 2024 17:03
K8s: List nodes with taints
# list taints (all nodes)
kubectl get nodes -o json | jq -r '.items[] | .metadata.name + " " + .spec.taints[]?.key + "=" + .spec.taints[]?.key + ":" + .spec.taints[]?.effect'
# list taints (exclude control plane)
kubectl get nodes -o json -l '!node-role.kubernetes.io/control-plane' | jq -r '.items[] | .metadata.name + " " + .spec.taints[]?.key + "=" + .spec.taints[]?.key + ":" + .spec.taints[]?.effect'
# remove taint example (note: the hyphen after the taint to remove)
# kubectl taint nodes $NODE $TAINT-
@rjchicago
rjchicago / kubectl_get_images.sh
Created March 20, 2024 13:57
Use kubectl to get all running images in a Kubernetes cluster.
#! /bin/sh
set -Eeou pipefail
# kubectl_get_images.sh
#
# Use kubectl to get all running images in a Kubernetes cluster.
# Ref: https://kubernetes.io/docs/tasks/access-application-cluster/list-all-running-container-images/
# if context is provided, switch context
if [[ ! -z ${1:-} ]]; then
# add all yaml configs under ${HOME}/.kube to KUBECONFIG
export KUBECONFIG=~/.kube/config$(for YAML in $(find ${HOME}/.kube -name '*.y*ml') ; do echo -n ":${YAML}"; done)
@rjchicago
rjchicago / reset-argocd-application-finalizers.sh
Created April 11, 2023 18:08
Reset ArgoCD Application Finalizers
# In switching Git repositories, I found you must delete the ArgoCD ApplicationSets and
# Applications in order to allow ArgoCD to recreate. However, deleting the resources can
# hang due to finalizers. Run the below script to reset the ArgoCD Application finalizers:
# get argocd applications by name, one per row
APPS=$(kubectl get -n ${NAMESPACE:-argocd} applications.argoproj.io -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{"\n"}{end}')
# loop through and reset each application's finalizers
while read -r APP; do
kubectl patch -n ${NAMESPACE:-argocd} applications.argoproj.io/$APP -p '{"metadata":{"finalizers":[]}}' --type=merge
@rjchicago
rjchicago / test.sh
Created February 27, 2023 14:58
Test Endpoint
# create alias
test() {
local URL=${1:?URL is required as first argument}
local TIMEOUT=${TIMEOUT:-1}
local SLEEP=${SLEEP:-1}
while true; do curl -s -m $TIMEOUT $URL > /dev/null && echo -n ✅ || echo -n 💀; sleep $SLEEP; done
}
# usage
@rjchicago
rjchicago / verify-floating-ip.sh
Created February 3, 2023 16:47
Script to verify MetalLB floating IP assignment to a given service.
#!/bin/sh
set -Eeuo pipefail
echo
: ${NAMESPACE:?NAMESPACE is required}
: ${SERVICE:?SERVICE is required}
: ${FLOATING_IP:?FLOATING_IP is required}
echo "VERIFY FLOATING IP: $FLOATING_IP"
while true; do