Skip to content

Instantly share code, notes, and snippets.

@jewzaam
jewzaam / deployment.yaml
Last active July 28, 2023 16:00
CMO scrape metrics
apiVersion: apps/v1
kind: Deployment
metadata:
name: metrics-load-test
namespace: metrics-load-test
spec:
replicas: 5
selector:
matchLabels:
name: metrics-load-test
@jewzaam
jewzaam / kubectl-debug.sh
Created April 16, 2021 15:50
kubectl debug poc
#!/bin/bash
NAMESPACE=default
NODE_NAME=nmalik-dev-ts2v9-worker-eastus21-lnktj
TOKEN_SECRET_NAME=$(oc -n $NAMESPACE get sa default -o json | jq -r '.secrets[] | select(.name | contains("token")) | .name')
DOCKERCFG_SECRET_NAME=$(oc -n $NAMESPACE get sa default -o json | jq -r '.secrets[] | select(.name | contains("dockercfg")) | .name')
IMAGE=quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:3f968cb0ca3116a7869cb41b4bfcb5ac537ff9d0ea21b3c4b69d8248881a1408
cat << EOF | kubectl create -f -
apiVersion: v1
@jewzaam
jewzaam / bluetooth-connect.sh
Created February 23, 2021 14:01
Force my headphones to connect if they're on
#!/bin/bash
# assumes bluetooth is turned on
# assumes name of device
# sudo dnf install python3-bluez
# pip3 install bluetooth_battery --user
BOSE_CONNECT=$(bt-device -l | egrep -e "Bose QC 35" -e "PLT BBFIT3150" | sort | sed 's/.*[(]\(.*\)[)].*/connect \1 \n/g')
@jewzaam
jewzaam / dump-node-logs
Created January 20, 2021 20:04
Dump node-logs into current directory
#!/bin/bash
# simple script to dump node-logs to the current directory
echo "Downloading audit log files.."
NODES=$(oc get nodes | grep master | awk '{print $1}')
# create dirs for each node
# collect all the logs, do in parallel
for LOG_PATH in openshift-apiserver kube-apiserver;
@jewzaam
jewzaam / grafana
Created August 12, 2020 21:02
Fire up local grafana for remote prometheus using oc to get bearer token etc.
#!/bin/bash
DEFAULT_PORT=3000
PORT=${1:-$DEFAULT_PORT}
CONTAINER_ENGINE=${CONTAINER_ENGINE:-docker}
SA_NAME=prometheus-k8s
SA_NAMESPACE=openshift-monitoring
SA_TOKEN=$(oc -n $SA_NAMESPACE sa get-token $SA_NAME)
@jewzaam
jewzaam / nmalik-prometheus.yaml
Last active July 23, 2020 16:59
install prometheus from operatorhub.io catalog source
---
apiVersion: project.openshift.io/v1
kind: Project
metadata:
name: nmalik-prometheus
---
apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
name: operatorhubio-catalog
@jewzaam
jewzaam / alertmanager.yaml
Created June 5, 2020 17:16
example alertmanager configuration
global:
resolve_timeout: 5m
pagerduty_url: https://events.pagerduty.com/v2/enqueue
route:
receiver: "null"
group_by:
- job
routes:
- receiver: "null"
group_by:
@jewzaam
jewzaam / yaml2json
Created March 27, 2020 13:23
convert yaml to json
python -c 'import json, sys, yaml ; y=yaml.safe_load(sys.stdin.read()) ; print(json.dumps(y))'
@jewzaam
jewzaam / python-crd-rbac.py
Created March 17, 2020 21:24
Script to grant RBAC to dedicated-admins for CRDs
import re
from kubernetes import client, config
from kubernetes.client import ApiClient
# based on initial 4.3.0 installation using 3 tiers of crd name possible:
# oc get crds -o json | jq -r '.items[].metadata.name' | sed 's/.*\(\.[^.]*\.[^.]*\.[^.]*\)$/\1/g' | sed 's/^[^.]*\(\.[^.]*\.[^.]*\)/\1/g' | sort -u
RE_DENYLIST = [
r".*\.authorization\.openshift\.io",
@jewzaam
jewzaam / script
Last active August 25, 2020 12:29
info from grpc catalogsource
# Useful link for how to discover API's: https://github.com/operator-framework/operator-registry/issues/33#issuecomment-473671805
# get tools
go get github.com/fullstorydev/grpcurl/...
go install github.com/fullstorydev/grpcurl/cmd/grpcurl
# constants for what we're investigating
NAMESPACE=openshift-marketplace
LOCAL_PORT=50051
REMOTE_PORT=50051