Skip to content

Instantly share code, notes, and snippets.

@alces
alces / find_pods_by_image_id.sh
Created September 10, 2024 12:59
Find all k8s pods running an image with a given imageID
#!/bin/bash -e
# Find all the pods using a given imageID
kubectl get pods --all-namespaces \
-o 'custom-columns=NS:.metadata.namespace,NAME:.metadata.name,IMAGE:.status.containerStatuses[*].imageID' |
awk '{if ($3 ~ "bitnami/external-dns@sha256:b615d1c97d93e5a4d83da00de8d1854f0274814b4ef57708d0ed9341205753e9") {print $1 "/" $2}}'
@alces
alces / k8s_patch_sidecar_version.sh
Created September 5, 2024 08:51
Upgrade a version of sidecar container image in all namespaces where it's used
for ns in $(kubectl get sts --all-namespaces | awk '{if ($2 == "zookeeper") {print $1}}'); do
if [ $(kubectl get sts zookeeper -n $ns -o json | jq '.spec.template.spec.containers[1].image') != null ]; then
kubectl patch sts zookeeper -n $ns \
-p '{"spec":{"template":{"spec": {"containers":[{"name": "jmx-exporter", "image":"bitnami/jmx-exporter:1.0.1"}]}}}}'
fi
done
@alces
alces / k8s_nifi_grep.sh
Created June 30, 2023 14:01
Looking for a pattern inside NiFi flowfiles on multiple clusters deployed atop of k8s
#!/bin/bash
PATTERN='for-example-a-kafka-topic-name-to-look-for'
for ns in $(kubectl get ns | awk '{if ($1 !~ /^NAME|kube-/) {print $1}}')
do
echo "Looking into $ns"
kubectl exec -n "$ns" -c nifi nifi-0 -- zgrep "$PATTERN" permanent_configs/flow.xml.gz 2>/dev/null
done
@alces
alces / fieldalignment_fix.sh
Created December 30, 2022 14:12
Fixing fieldalignment issues reported by govet
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment
fieldalignment -fix a_problematic_file.go
@alces
alces / install_terraform_provider.sh
Created December 7, 2022 13:21
Install a Terraform provider to a cache (tested on alpine Docker image)
#!/bin/sh -e
# Install a Terraform provider
OS=linux
ARCH=amd64
OPTS=`getopt -l dont-unzip,full-url:,group:,provider:,site:,url:,version: -- df:g:p:u:s:v: "$@"` || exit 1
eval set -- "$OPTS"
@alces
alces / signalflow_metrics.go
Created November 16, 2022 11:32
Getting metrics from SignalFX
package main
import (
"fmt"
"log"
. "github.com/signalfx/signalfx-go/signalflow"
)
const (
@alces
alces / gcloud_function_call.sh
Created March 26, 2021 12:20
Call Google Cloud function from command line
gcloud --project my-project-id \
functions call hello-world \
--data '{}' \
--region us-east1
@alces
alces / ec2_instance_creation_time.py
Created November 27, 2020 13:45
Print out "creation time" for EC2 instances (in reality, it's the first network interface attachement time)
import boto3
import datetime
# iterator over EC2 instances for region
def ec2_instances(region):
client = boto3.client('ec2', region_name = region)
for reservation in client.describe_instances().get('Reservations', []):
for instance in reservation.get('Instances', []):
yield instance
@alces
alces / ansible_pass_list.sh
Created October 1, 2020 09:18
Passing a list as a value of an external Ansible variable
ansible-playbook our_playbook.yml -e '{"our_var": ["one", "two", "three",]}'
@alces
alces / lenses-cli-groups.sh
Created July 6, 2020 12:45
Manipulating groups with lenses-cli
# Nice doc is here: https://docs.lenses.io/dev/lenses-cli/index.html
LENSES_CLI_CMD="lenses-cli --host https://10.0.17.20:9991/ --user admin --pass admin --insecure groups"
# Get the list
$LENSES_CLI_CMD get --output JSON
# Group config file
cat > config.yaml << EOF
name: windows_admins
description: "Admins from AD"