Skip to content

Instantly share code, notes, and snippets.

View jenrik's full-sized avatar
🐧

Jener Rasmussen jenrik

🐧
View GitHub Profile
@jenrik
jenrik / kubectl-badpdb
Last active February 6, 2025 09:31
Find PDBs guarding single pods
#!/bin/sh
set -e
if ! type jq 2>/dev/null 1>/dev/null; then
echo "jq command is required, please install it" >&2
exit 1
fi
kubectl get pdb -A -o json | \
jq -r '.items[] | {name: .metadata.name, namespace: .metadata.namespace, selector: ((.spec.selector.matchLabels // {} | to_entries | .[] |= "\(.key)=\(.value)") + (.spec.selector.matchExpressions // [] | .[] |= .key + " " + (.operator | ascii_downcase) + " (" + (.values[] | @json) + ")")) | join(",") }' -c | \
@jenrik
jenrik / kubectl-getall
Last active February 1, 2025 12:03
List all resources, including custom resources, in a Kubernetes namespace
#!/bin/sh
set -e
NAMESPACE="$1"
if [ "${NAMESPACE}x" = "x" ]; then
echo "usage: $(basename "$0") <namespace>" >&2
exit 1
fi
kubectl api-resources --namespaced -o name | while read -r resource; do
@jenrik
jenrik / spaghetti-detector.yaml
Last active January 21, 2025 23:41
AI Spaghetti detection for Bambu Lab P1 and A1 series printers using Home Assistant and Obico
blueprint:
name: 3D printer spaghetti detector
domain: automation
input:
printer_status:
name: Printer current stage entity
selector:
entity:
filter:
- domain: sensor
#!/bin/sh
set -e
# Convert Kubernetes storage and CPU units to plain decimals
grep -E "^[0-9]+(\.[0-9]+)?(e[0-9]+)?((E|P|T|G|M|K)i?|m)?$" \
| sed \
-e 's/Ki$/ * \(1024 \^ 1\)/' \
-e 's/K$/ * \(1000 \^ 1\)/' \
-e 's/Mi$/ * \(1024 \^ 2\)/' \
@jenrik
jenrik / resources.yaml
Created August 19, 2024 07:15
Kubernetes iperf test
---
apiVersion: batch/v1
kind: Job
metadata:
labels:
app: iperf-test
component: client
name: iperf-test-client
spec:
template:
sep()
{
(
if type "cowsay" > /dev/null < /dev/null; then
cowsay "separator"
cowsay "separator"
cowsay "separator"
else
echo "*-----------*"
echo "| separator |"
@jenrik
jenrik / utime.sh
Last active March 7, 2023 19:08
Multifunction timestamp tool
function utime()
{
if [ $# = 1 ] && ([ "${1:0:1}" = "+" ] || [ "${1:0:1}" = "-" ]) && [ "$1" != "--help" ]
then
# Do date math
date -d "$1" "+%s"
elif [ $# = 1 ] && (echo "$1" | grep -P "^[[:digit:]]+$" > /dev/null)
then
# Convert timestamp to human-readable date
date -d "@$1" || help
@jenrik
jenrik / cloud-init.yaml
Last active November 21, 2021 22:08
Rancher Ubuntu 20.04 cloud-init
#cloud-config
groups:
- docker
users:
- default
- name: ubuntu
ssh-authorized-keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCvu0XjgnnODcPW2/g2A63Q9L8nKO1LHx5xAdGEa+YH6SPJYncGYGoW2CfckwnQYPYy1vdWli1ZDnvtn0WIpUIRbyp06aQzX7+Iq/hoae0iRcSYXwRlBgAnYzATmXk7Vby/C5oX8yqoTlmSSjkbynRePLm4xvUoPjDir9Lct6xKeeb0hhJgmc4fByEwgP8LD6MjnViuLHjezScqbgfmKnl4bBVfJIJaOm3IGY4/ps2nH3zPVq1rtFkwqKKSjN374GQ6c8DW1+uBib4SfX8UplLCHt66bsrEZLlTfbYoOAdanbgar9OuzjveENa8wTnj3vON8OW5GhmrOhwPt8CfsOoXTbjM87zPnXkFkg1OS+QuEkwtM3y2KcFKE0ME/tHdBZekkII7NqpUn9WvWoDk+HexeIgfm9ZAgkywdcrObLlCqHreQKTuz5f7gDnUgq7fpYueMc6u03x5gsdVVpszuQwH7YjajD+8YATMsCjP8c85EKL0Nzhs2nSOzL/hMxUm9g6kw4uUXAP3wql7Qf4i24NVWmtd8QXABjXMSYzXw3Xf7619Q3/YadLCiDmmi5ArQjNtIwuL19OHNMjLobvOVIXnksGqABfpkOd9EXKRxCI9sWKb+tmvzAAX+T50l2TSfgdL/dwQIUXkasd8ZpIjXQqOmTh/hegVYtr1Bv0x+vMORQ==
sudo: ALL=(ALL) NOPASSWD:ALL
groups: sudo, docker
@jenrik
jenrik / index.php
Last active June 20, 2019 18:00
Cron script for updating ssh key from Github periodically, and logging which servers fetches keys
<?php
$github = "jenrik";
$dbhost = "";
$dbname = "";
$dbuser = "";
$dbpass = "";
header("Cache-control: private, max-age=0, no-cache");
@jenrik
jenrik / cores.py
Last active July 1, 2019 10:03
Enable/Disable a number of cores on a Linux system
#!/usr/bin/env python3
import sys
MAX_CORES = 12
if len(sys.argv) >= 2:
n = int(sys.argv[1])
if n > MAX_CORES or n < 1:
sys.exit(1)