Skip to content

Instantly share code, notes, and snippets.

View karlkfi's full-sized avatar

Karl Isenberg karlkfi

View GitHub Profile
@karlkfi
karlkfi / assign-kube-system-node-selector.yaml
Created August 15, 2024 22:55
Use Gatekeeper mutating webhooks to auto-assign Pods from a namespace to a specific node pool
apiVersion: mutations.gatekeeper.sh/v1
kind: Assign
metadata:
name: kube-system-node-selector
spec:
applyTo:
- groups: [""]
kinds: ["Pod"]
versions: ["v1"]
match:
@karlkfi
karlkfi / json-encode.py
Created August 6, 2021 12:29
json encode in starlark
# In a Starlark context that doesn't support json or recursion,
# you might become desperate enough to do something crazy like this...
def quoteIfString(obj):
if type(obj) == "string":
return '"' + obj + '"'
else:
return obj
def jsonEncode(obj):
@karlkfi
karlkfi / kpt-pkg-status.sh
Created June 11, 2021 21:25
kpt-pkg-status.sh - Get the status of all resources in a directory.
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
PKG_PATH="${1:-.}"
if ! hash jq 2>/dev/null; then
echo >&2 "Error: jq not found. Please install jq: https://stedolan.github.io/jq/download/"
fi
@karlkfi
karlkfi / bash2asciicast.sh
Created February 2, 2021 07:16
bash2asciicast.sh - Convert a bash script into an asciinema recording
#!/usr/bin/env bash
# Convert a bash script into an asciinema recording
set -o errexit -o nounset -o pipefail
INPUT_FILE=${1:-}
if [[ -z "${INPUT_FILE}" ]]; then
echo "Syntax: $0 <path/to/bash-scipt.sh> <path/to/out.cast>"
exit 1
@karlkfi
karlkfi / bash2asciicast.sh
Last active February 2, 2021 07:36
bash2asciicast.sh - Convert a bash script into an asciicast recording
#!/usr/bin/env bash
# Convert a bash script into an asciicast recording
set -o errexit -o nounset -o pipefail
USER=karl
WORKDIR="~/workspace"
PROMPT="\u001b]0;Cloud Shell\u0007${USER}@cloudshell:\u001b[1;34m${WORKDIR}\u001b[00m$ \u001bkcloudshell\u001b\\\\"
---
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
networking:
# expose to private network
apiServerAddress: "0.0.0.0"
# fixed port so Vault auth backend can find the API
apiServerPort: 32769
kubeadmConfigPatchesJSON6902:
- group: kubeadm.k8s.io
@karlkfi
karlkfi / dcos-install-prereqs.sh
Last active November 1, 2017 23:31
Install DC/OS node prerequisites on CentOS/RHEL 7.2+
#!/usr/bin/env bash
# Exit on error, unset variable, or error in pipe chain
set -o errexit -o nounset -o pipefail
# For setenforce & xfs_info
PATH=$PATH:/usr/sbin:/sbin
echo "Validating distro..."
distro="$(source /etc/os-release && echo "${ID}")"
@karlkfi
karlkfi / semver-compare.sh
Created May 16, 2017 21:33
Compare two semantic versions in bash
# return 0 if version A >= version B using semanatic versioning
function semver_gte() {
VERISON_A="${1}"
VERISON_B="${2}"
SEMVER_PATTERN="[^0-9]*\([0-9][0-9]*\)[.]\([0-9][0-9]*\)[.]\([0-9][0-9]*\).*"
SEG1_A="$(echo "${VERISON_A}" | sed -e "s#${SEMVER_PATTERN}#\1#")"
SEG1_B="$(echo "${VERISON_B}" | sed -e "s#${SEMVER_PATTERN}#\1#")"
[[ ${SEG1_A} < ${SEG1_B} ]] && return 1
[[ ${SEG1_A} > ${SEG1_B} ]] && return 0
SEG2_A="$(echo "${VERISON_A}" | sed -e "s#${SEMVER_PATTERN}#\2#")"
@karlkfi
karlkfi / changes.sh
Created October 18, 2016 01:48
Generate markdown change log from merged PR titles
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
# org/repo (e.g. karlkfi/probe)
REPO=$1
# range (e.g. 1.8.4..1.8.5)
RANGE=$2
@karlkfi
karlkfi / resize.sh
Created August 23, 2016 02:57
Resizing a vagrant centos disk... the hard way
#!/usr/bin/env bash
# Resizing a vagrant centos disk... the hard way
set -o errexit
set -o nounset
set -o pipefail
set -o xtrace
vagrant up