Skip to content

Instantly share code, notes, and snippets.

View moio's full-sized avatar

Silvio Moioli moio

View GitHub Profile
@moio
moio / sqlite_query_from_rancher.md
Created August 6, 2025 09:05
Running timed SQLite queries directly from a Rancher pod

Running timed SQLite queries directly from a Rancher pod

NOTE THIS IS NOT SECURE FOR A PRODUCTION ENVIRONMENT, use for development/test only.

kubectl exec into the Rancher pod, then:

curl -k -o sqlite-tools.zip https://www.sqlite.org/2025/sqlite-tools-linux-x64-3500400.zip
unzip sqlite-tools.zip
@moio
moio / download-vai-db.sh
Created August 1, 2025 15:09
Downloads the Vai SQLite DB from a Rancher instance pointed by KUBECONFIG
#!/bin/bash
# This script automates copies the Vai DBs from Rancher to local machine.
# NOTE THIS IS NOT SECURE FOR A PRODUCTION ENVIRONMENT, use for development/test only
# Exit immediately if a command exits with a non-zero status.
set -e
# --- Configuration ---
@moio
moio / tester_cluster_k6.md
Created July 31, 2025 14:04
Run k6 from a pod interactively

Running k6 interactively from a pod in the tester cluster

Set local paths:

export KUBECONFIG=/path/to/tester.cluster.kubeconfig
export K6_TESTS_DIR=./k6/tests

Create a volume and pod

@moio
moio / main.go
Created July 28, 2025 09:51
GORM example: use SQL generation without the rest of the ORM
package main
import (
"fmt"
"log"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
@moio
moio / fix_date_format.py
Created January 17, 2025 10:41
Script to convert the date format in a CSV from an arbitrary format to ISO 8601
import sys
import csv
from datetime import datetime
# Replaces a CSV column reformatting the date according to ISO 8601 standard with millis
# Usage: python fix_date_format.py < input.csv > output.csv
COLUMN_TO_REFORMAT_INDEX = 0
INPUT_FORMAT = '%d.%m.%Y, %H:%M:%S.%f'
@moio
moio / run_test.sh
Created September 17, 2024 15:42
Benchmark Steve list API while resources are being changed
#!/bin/bash
set -euo pipefail
# Global variables
KUBECONFIG="../tofu/main/k3d/config/upstream.yaml"
CONTEXT="k3d-st-upstream"
KUBERNETES_BASE_URL="https://localhost:6445"
STEVE_BASE_URL="https://localhost:8444"
USERNAME="admin"
@moio
moio / continuous_profiling.sh
Last active December 21, 2023 09:30
Script to continuously collect Rancher profiles and upload them to Azure
#!/bin/bash
# Azure storage container SAS URL and token for uploading. Only creation permission is necessary
BLOB_URL=''
BLOB_TOKEN=''
cleanup() {
echo "Cleaning up..."
echo "Setting rancher logs back to error"
kubectl -n cattle-system get pods -l app=rancher --no-headers -o custom-columns=name:.metadata.name | while read rancherpod; do kubectl -n cattle-system exec $rancherpod -c rancher -- loglevel --set error; done
@moio
moio / steve_api_microbenchmark.js
Created September 1, 2023 10:29
k6 script to test Rancher's Steve API listing performance
import { check, fail } from 'k6';
import http from 'k6/http';
// Parameters
const vus = __ENV.VUS || 1
const perVuIterations = __ENV.PER_VU_ITERATIONS || 30
const baseUrl = __ENV.BASE_URL
const user = __ENV.USER
const password = __ENV.PASSWORD
const cluster = __ENV.CLUSTER || "local"
@moio
moio / rancher_pprof.md
Created June 16, 2023 10:18
Explore a Rancher pprof CPU profile

Explore a Rancher pprof CPU profile

Grab a kubeconfig file pointing to the Rancher upstream cluster, then copypaste:

export KUBECONFIG=/path/to/the/upstream_cluster.yaml

for pod in $(kubectl get pods -n cattle-system --no-headers -l app=rancher | cut -d ' ' -f1); do
  echo Collecting 30s worth of profile data for $pod...
 kubectl exec -n cattle-system $pod -- curl -s http://localhost:6060/debug/pprof/profile -o profile
@moio
moio / audit-to-csv-rancher.rb
Created June 6, 2023 15:52
Rancher audit log to CSV converter for Excel analysis
#!/usr/bin/env ruby
# encoding: UTF-8
# EXAMPLE
#
# {
# "kind": "Event",
# "apiVersion": "audit.k8s.io/v1",
# "level": "Metadata",
# "auditID": "f6618a15-8e4f-4f82-95b3-7592ed544eb9",