Skip to content

Instantly share code, notes, and snippets.

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

Ryan Jones rjchicago

💭
🐳 🚢 🏗️
View GitHub Profile
@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
@rjchicago
rjchicago / metallb-health.yaml
Created February 2, 2023 21:30
Demo Nginx service health endpoint for MetlalLB in K8s.
apiVersion: v1
kind: Namespace
metadata:
name: metallb-health
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
@rjchicago
rjchicago / configmap_from_file.sh
Created February 2, 2023 19:04
Function to read and format K8s ConfigMap data from file
# Function to read and format ConfigMap data from file
configmap_from_file() {
local FILE=${1:?FILE is required}
local INDENT=${2:-4}
local SPACES=$(printf ' %.0s' {1..$INDENT})
echo "|" && cat $FILE | sed "s/^/$SPACES/"
}
##################################################
# usage
@rjchicago
rjchicago / swarm-host-ip.sh
Created October 26, 2022 14:29
Docker Swarm Host IPs
# get hosts (mgr node)
HOSTS=$(docker node ls --format "{{.Hostname}}")
# print host/ip
for HOST in $HOSTS; do host $HOST; done | awk '{print $1, $4}' | sort
( 0.1 + 0.2 === 0.3 ) ? console.log('LGTM') : console.log('WTF');
@rjchicago
rjchicago / import_table.sql
Created May 9, 2022 15:05
Postgres Import Table Function
CREATE OR REPLACE FUNCTION "my_schema"."import_table" (fdw_server text, tablename text, where_filter text) RETURNS bigint
VOLATILE
AS $body$
DECLARE
v_fdw_schema TEXT;
v_fdw_tablename TEXT;
v_col_def TEXT;
v_query TEXT;
v_schema_name TEXT;
v_table_name TEXT;