Skip to content

Instantly share code, notes, and snippets.

View jplitza's full-sized avatar

Jan-Philipp Litza jplitza

View GitHub Profile
@jplitza
jplitza / nc.sh
Created February 23, 2024 14:10
Netcat in Bash
#!/bin/bash
set -eu
PROXY=false
usage() {
echo "Usage: $0 [-X connect -x <proxy:port>] <host> <port>"
}
#!/bin/sh
set -eu
REPO="$1"
ARCHIVE="$2"
FILE="$3"
# Fetch the latest version using GitHub API
VERSION="$(curl -s "https://api.github.com/repos/${REPO}/releases" | jq -r 'map(select(.prerelease | not)) | .[0].tag_name' | cut -c 2-)"
@jplitza
jplitza / resize-pvc.sh
Created December 4, 2024 11:16
Resize PersistentVolumeClaims according to owning StatefulSet spec
#!/bin/sh -eu
# Update the actual storage requets of existing PVCs to those specified in their owning StatefulSet.
# This assumes the StatefulSet was already "updated" (via `kubectl replace --force --cascade=orphan` or similar)
STS="$1"
kubectl get statefulset "$STS" -o jsonpath='{range .spec.volumeClaimTemplates[]}{.metadata.name} {.spec.resources.requests.storage}{"\n"}{end}' |
while read -r VOLNAME SIZE; do
for PVC in $(kubectl get pvc -o custom-columns=NAME:.metadata.name | grep -E "^$VOLNAME-$STS-[0-9]+\$"); do
@jplitza
jplitza / kyverno-junit.jq
Created January 10, 2025 13:37
Convert output from `kyverno apply -p` (converted to JSON) to JUnit XML format using `jq`
@html "<testsuite name=\"kyverno\" tests=\"\(.summary|add)\" failures=\"\(.summary.fail)\" skipped=\"\(.summary.skip)\" errors=\"\(.summary.error)\">",
(.results | group_by(.policy) | .[] | [
@html "<testsuite name=\"\(.[0].policy)\">",
(group_by(.rule) | .[] | [
"<testsuite name=\"\(.[0].policy).\(.[0].rule)\">",
(.[] | [
@html "<testcase name=\"\(.policy).\(.rule).\(.resources[0].namespace)/\(.resources[0].kind)/\(.resources[0].name)\">",
(if .result == "fail"
then @html "<failure message=\"\(.message)\" />"
else if .result == "skip"