Skip to content

Instantly share code, notes, and snippets.

View cwilkers's full-sized avatar

Chandler Wilkerson cwilkers

View GitHub Profile
@cwilkers
cwilkers / reservation-test.yaml
Created November 22, 2024 20:41
Ansible playbook to demonstrate figuring a reservation window using date commands
---
- name: Test date handling for machine reservation re-up
hosts: localhost
tasks:
- name: Get tomorrow's date
ansible.builtin.command: date -d "tomorrow" "+%Y-%m-%d"
register: tomorrow
changed_when: false
- name: Set start date
ansible.builtin.set_fact:
@cwilkers
cwilkers / zap-odf-pvs.sh
Created August 8, 2024 15:30
Clear old data on PVs for ODF after reinstalling
#!/bin/bash
for pod in $(oc -n openshift-storage get pod -l app=rook-ceph-osd-prepare -o name)
do
DISK=$(oc -n openshift-storage get $pod -oyaml | grep -A1 ROOK_DATA_DEVICES | awk -F'"' '/value/ {print $4}')
oc -n openshift-storage debug $pod -- bash -c "sgdisk --zap-all $DISK; dd if=/dev/zero of=$DISK bs=1M count=100 oflag=direct,dsync"
done
@cwilkers
cwilkers / clean-kubevirt.sh
Created January 21, 2022 03:43
Uninstall KubeVirt the hard way
#!/bin/bash
# Try to clean everything created by kubevirt
KC=kubectl
# Take out anything added by KubeVirt that lives in a namespace
NSRES=$($KC api-resources --namespaced=true | awk '/kubevirt.io/ {print $1}'| tr -s ' ' ',')
$KC delete $res --all-namespaces --all --now=true --wait=false
# Take out any cluster-wide KubeVirt resources
@cwilkers
cwilkers / ip2mac.py
Created January 8, 2022 02:08
Generate VM MAC addresses from last 3 of IP range
#!/usr/bin/env python
import sys
# turn IP address string into array of int
def parseip(ipstr):
array = ipstr.split('.')
return [int(x) for x in array]
# append last 3 of IP to static MAC vendor ID and return printable string
def ip2mac(ip):
@cwilkers
cwilkers / create17vms.sh
Created September 15, 2021 22:28
Create 17 (or more) RHEL8 VMs automatically
#!/bin/bash
COUNT=${1:-17}
NAME=rh8-
for num in $(seq 1 $COUNT)
do
oc process openshift//rhel8-desktop-small NAME=${NAME}${num} > /tmp/${NAME}${num}.yaml
done
@cwilkers
cwilkers / clean-trident.sh
Created July 28, 2021 19:33
Clear all trident luns from NetApp for a backend
#!/bin/bash
BACKEND=${1:-trident-backend.json}
source <(awk -F':' '$2~/./ { gsub(/[ \t,"]+/,""); print $1 "=\"" $2 "\""}' $BACKEND)
PREFIX=$(echo $storagePrefix |tr - _)
echo $PREFIX
for lun in $(showmount -e $dataLIF | awk -F '[/ ]' "/$PREFIX/ { print \$2 }")
do
SSHPASS=${password} sshpass -e ssh -l $username $managementLIF volume offline -f $lun
@cwilkers
cwilkers / grab-dev-tools.sh
Created May 13, 2021 15:41
script to download latest OpenShift development version CLI tools
#!/bin/bash
TARGETDIR=~/bin
VERSION=latest-4.8
URL="https://mirror.openshift.com/pub/openshift-v4/clients/ocp-dev-preview/${VERSION}"
pullsecret_file=~/openshift_pull.json
update_tool () {
TOOL=${1:-openshift-install}
curl -sLO ${URL}/${TOOL}-linux.tar.gz
tar xf ${TOOL}-linux.tar.gz
oc get nns -o jsonpath='{range .items[*]}{@.metadata.name}{"\t"}{@.status.currentState.interfaces[?(@.name=="eno4")].ipv4}{"\n"}'
---
apiVersion: hostpathprovisioner.kubevirt.io/v1beta1
kind: HostPathProvisioner
metadata:
name: hostpath-provisioner
namespace: openshift-cnv
spec:
imagePullPolicy: IfNotPresent
pathConfig:
path: "/var/hostpath"
---
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
name: 50-set-selinux-for-hostpath-provisioner
labels:
machineconfiguration.openshift.io/role: worker
spec:
config:
ignition: