Skip to content

Instantly share code, notes, and snippets.

View duboisf's full-sized avatar

Fred Dubois duboisf

View GitHub Profile
@duboisf
duboisf / kube_search_api_resources.zsh
Created July 24, 2025 15:20
zsh function to search for kubernetes resources across clusters
emulate -RL zsh
setopt err_return warn_create_global
local API_RESOURCE="$1"
local ctx
local kind
if [[ -z "$API_RESOURCE" ]]; then
print "Usage: kubectl_search_api_resources <API_RESOURCE>" >&2
print "Will search for the api resources that match the regex API_RESOURCE in all clusters and all namespaces" >&2
@duboisf
duboisf / used-images-in-kubernetes-cluster.nu
Last active July 22, 2025 14:51
Find all images used in the current kubernetes cluster with image sizes
kubectl get no -o json
| from json
| get items
| select status.images status.nodeInfo.architecture
| rename images arch
| flatten
| update images.names { |in|
if ($in | length) > 1 {
$in | filter { $in !~ @sha }
} else {
@duboisf
duboisf / gh-changelog.md
Created June 11, 2025 17:15
Generate a changelog on the fly for a github repo based on releases with nu and the gh cli

In nushell, you can generate a changelog on the fly with the following:

gh release list --json name
| from json
| get name
| par-each --keep-order { |name|
    gh release view $name --json name,body,author
    | from json
 | $"# ($in.name) by ($in.author.login)\n\n($in.body)"

Troubleshooting Redis StatefulSet: Clearing Data from a PVC When Pods Are Crashlooping

The Problem

I encountered an issue with a Redis StatefulSet in our staging environment where the pods were stuck in a crashloop. The root cause was a full Persistent Volume Claim (PVC) that had run out of space. Since this was cache data in a staging environment, I needed to clear the /data folder to resolve the issue.

The challenge was that I couldn't exec into the pod directly because the Redis container was continuously crashlooping, making standard troubleshooting approaches impossible.

The Solution

@duboisf
duboisf / enable-scan-on-push.nu
Created May 27, 2025 19:58
Enable scan on push for all AWS ECR repositories that don't have it enabled, in nushell
aws ecr describe-repositories | from json | get repositories.repositoryName
| sort
| each { |repo|
let scanOnPush = (aws ecr batch-get-repository-scanning-configuration --repository-names $repo
| from json
| get scanningConfigurations
| first
| get scanOnPush
)
print $"Repository: ($repo), Scanning on push: ($scanOnPush)"
@duboisf
duboisf / coroutines.lua
Last active April 1, 2025 16:29
Example of running nvim coroutines sequentially and in parallel
-- Example of using coroutines with slow IO operations in Neovim.
-- It shows how to run coroutines sequentially and in "parallel".
-- The word "parallel" is in quotes because Lua coroutines are not actually
-- running in parallel, but the IO operations that they start are.
-- The coroutines are paused and resumed as the IO operations complete.
-- To run this example, put this file somewhere and do `:luafile path/to/coroutines.lua` in nvim.
local co = coroutine
vim.cmd "new"
@duboisf
duboisf / nu-get-all-s3-bucket-policies.md
Created February 3, 2025 17:15
Get all s3 bucket policies in an aws account using nushell

Get all s3 bucket policies in an aws account using nushell

In parallel! Saves output to a file so you can simply do open /tmp/bucket-policies.nuon after:

^aws s3api list-buckets
| from json
| get Buckets.Name
| par-each { |bucket|
 let policy = try {
@duboisf
duboisf / CreateGitopsFleetUser.md
Created January 21, 2025 15:48
Create a fleetmd api user with random password
fleetctl user create --name 'Gitops User' \
  --password "$(cat /dev/urandom | tr -cd '[:graph:]' | head -c 32)" \
  --email [email protected] \
  --api-only \
  --global-role admin
@duboisf
duboisf / docker-multi-arch-linux.md
Created October 5, 2024 13:27
HOWTO configure docker buildx to be able to build multi-archi images in Linux

Multi-architecture docker builds on Linux

Install binfmt if ls /proc/sys/fs/binfmt_misc/qemu* returns nothing:

docker run --privileged --rm tonistiigi/binfmt --install all

Verify that it worked, you should see stuff by running ls /proc/sys/fs/binfmt_misc/qemu*

@duboisf
duboisf / diff-container-images.sh
Last active September 27, 2024 19:03
Bash script to diff 2 container images
#!/bin/bash
# This script diffs the content of two container images
# USAGE: ./diff-container-images.sh <registry>/<repo> <tag1> <tag2>
# strict mode
set -euo pipefail
registry_repo=$1
tag1=$2