Skip to content

Instantly share code, notes, and snippets.

View WalBeh's full-sized avatar

Walter Behmann WalBeh

  • 09:08 (UTC +02:00)
View GitHub Profile
@WalBeh
WalBeh / trivy-helper.sh
Last active October 18, 2023 17:49
planned workaround
sanitize() {
local s="${1?need a string}" # receive input in first argument
s="${s//[^[:alnum:]]/-}" # replace all non-alnum characters to -
s="${s//+(-)/-}" # convert multiple - to single -
s="${s/#-}" # remove - from start
s="${s/%-}" # remove - from end
echo "${s,,}" # convert to lowercase
}
@WalBeh
WalBeh / image_updater.py
Last active December 6, 2023 10:30
k8s python client that updates an image tag
#!/usr/bin/env python3
# https://pip.wtf
def pip_wtf(command):
import os, os.path, sys
t = os.path.join(os.path.dirname(os.path.abspath(__file__)), ".pip_wtf." + os.path.basename(__file__))
sys.path = [p for p in sys.path if "-packages" not in p] + [t]
os.environ["PATH"] += os.pathsep + t + os.path.sep + "bin"
os.environ["PYTHONPATH"] = os.pathsep.join(sys.path)
if os.path.exists(t): return
@WalBeh
WalBeh / gc_image_updater.py
Created December 6, 2023 14:46
Update cratedb over all namespace (label selector)
#!/usr/bin/env python3
# https://pip.wtf
def pip_wtf(command):
import os, os.path, sys
t = os.path.join(os.path.dirname(os.path.abspath(__file__)), ".pip_wtf." + os.path.basename(__file__))
sys.path = [p for p in sys.path if "-packages" not in p] + [t]
os.environ["PATH"] += os.pathsep + t + os.path.sep + "bin"
os.environ["PYTHONPATH"] = os.pathsep.join(sys.path)
if os.path.exists(t): return
@WalBeh
WalBeh / py
Created May 22, 2024 09:26
k8s update deployment and cronjob
#!/usr/bin/env python3
""" Update the backup image in the cratedDB namespaces.
The script iterates over all cratedbs in a k8s context and updates tag on the deployment and cronjob
using the backup image.
The script can be run standlone/locally, or on-demand in the cluster via CI/CD. Runtime
behaviour and configuration is controlled via environment variables.
#!/usr/bin/env python3
"""
This script is used to update the JMX exporter version in the CrateDB StatefulSet.
JMX exporter is referenced in
- the initContainer,
- the CRATE_JAVA_OPTS environment variable, and
- the volumeMounts and
- sql_exporter image.
package main
import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
@WalBeh
WalBeh / trivy_db_updater.go
Created November 9, 2024 17:34
trivy db updater for cache-dir
package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"io"
"os"
"os/exec"
@WalBeh
WalBeh / aws_usage_quota_exporter.py
Last active November 13, 2024 15:58
Exports Quota and Usage on selected VPC, EC, ELB resources
import boto3
from botocore.exceptions import ClientError
import logging
import time
import os
from prometheus_client import start_http_server, Gauge
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
@WalBeh
WalBeh / jfr.py
Last active December 2, 2024 15:03
automate jfr+heapdump handling
#!/usr/bin/env python3
import argparse
import time
import sys
from kubernetes import client, config
from kubernetes.config.config_exception import ConfigException
import logging
import logging.handlers
import subprocess
import boto3
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "argparse",
# "kubernetes<=31.0",
# "loguru",
# ]
# ///
import re