Skip to content

Instantly share code, notes, and snippets.

View martinkennelly's full-sized avatar

Martin Kennelly martinkennelly

View GitHub Profile
@martinkennelly
martinkennelly / echo.py
Created January 31, 2024 09:09
echo server python
#!/usr/bin/python3
# usage python3 echoTcpServer.py [bind IP] [bind PORT]
import socket
import sys
import string
import random
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@martinkennelly
martinkennelly / gist:ad37bc7e022b737676ff47f0f655c142
Last active October 18, 2023 12:24
Easily tracing a packet with ofproto/trace and ovs-tcpundump
# Get packet info thatll later be used for the trace. This info describes the flow.
1. tcpdump -XX -c1 -nn -i <dev> <some filter thatll just capture the flow you want> | ovs-tcpundump
# Lookup the port ID on which the packet is coming in
2. ovs-ofctl show <ovs bridge>
# Perform trace
ovs-appctl ofproto/trace <ovs bridge> in_port=${port id in step 2} ${pkt data from step 1}
@martinkennelly
martinkennelly / gist:6e05502b68bec40bd8970b02eb5278de
Created October 14, 2023 11:13
setup non-root user with passwordless root
# Setup user group and user and ensure passwordless root
groupadd mk && useradd --gid mk --groups mk,users,adm --shell /bin/bash -c "mk home" --create-home mk
cat <<EOT >> /etc/sudoers.d/99-mk
mk ALL=(ALL) NOPASSWD:ALL
EOT
# Create new .ssh dir in mk home dir and add a public key to authorized_key file and set perms
chmod 400 authorized_key
chown -R mk:mk ~mk/.ssh
@martinkennelly
martinkennelly / gist:c7192831e6a27de86873abd6bcc12788
Created September 12, 2023 09:42
Building RH container images
# GetOAUTH token
https://oauth-openshift.apps.ci.l2s4.p1.openshiftapps.com/oauth/token/request
# Login with provided link
oc login..
# Login to registry (for podman)
oc registry login --to ~/.config/containers/auth.json
# Login to registry (for docker)
oc registry login --to ~/.docker/config.json
@martinkennelly
martinkennelly / cycle-cno.sh
Last active November 22, 2023 17:28
Build Openshift cluster network operator image
#!/bin/bash
set -eou pipefail
tag="$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13 ; echo '')"
echo "Tag is $tag"
docker build -f Dockerfile -t quay.io/mkennell/cluster-network-operator:$tag .
docker push quay.io/mkennell/cluster-network-operator:$tag
oc patch clusterversion version --type json -p '[{"op":"add","path":"/spec/overrides","value":[{"kind":"Deployment","group":"apps","name":"network-operator","namespace":"openshift-network-operator","unmanaged":true},{"kind":"Deployment","group":"apps","name":"openshift-controller-manager-operator","namespace":"openshift-controller-manager-operator","unmanaged":true}]}]'
oc -n openshift-network-operator set image deployment/network-operator network-operator=quay.io/mkennell/cluster-network-operator:$tag
@martinkennelly
martinkennelly / gist:dbf8a2eb043bdde06bebdbd3e00a449a
Created August 8, 2023 09:30
Getting ovn-nbctl: unix:/var/run/ovn/ovnnb_db.sock: database connection failed () ?
You can possibly resolve it in two ways:
1. If OVN is in HA, exec onto the pod who is the current leader and execute `ovn-nbctl --no-leader-only show`
2. Find all the instances IPs and execute `ovn-nbctl --no-leader-only --db=...`
echo -e "[logging]\nlevel=TRACE\n" > /etc/NetworkManager/conf.d/99-trace-logging.conf
for f in $(oc get nodes --no-headers -o custom-columns=N:.metadata.name ) ; do oc debug node/$f -- chroot /host bash -c "echo $USER-ocp-qe-$(date -I) | passwd --stdin core" & done
@martinkennelly
martinkennelly / gist:a4e9dfe5657bcf6479d2c9b5194ffc3f
Created January 30, 2023 13:27
Get OVN-Kubernetes master container leader
for f in $(oc -n openshift-ovn-kubernetes get pods -l app=ovnkube-master -o jsonpath={.items[*].metadata.name}) ; do echo -e "\n${f}\n" ; oc -n openshift-ovn-kubernetes exec "${f}" -c northd -- ovs-appctl -t /var/run/ovn/ovnnb_db.ctl cluster/status OVN_Northbound |grep Role ; done
# When this exits, exit all background processes:
trap 'kill $(jobs -p) &> /dev/null && sleep 0.2 && echo ' EXIT
# Create one tcpdump output per interface and add an identifier to the beginning of each line:
if [[ $@ =~ -i[[:space:]]?[^[:space:]]+ ]]; then
tcpdump -l $@ | sed 's/^/[Interface:'"${BASH_REMATCH[0]:2}"'] /' &
else
for interface in $(ifconfig | grep '^[a-z0-9]' | awk '{print $1}'i | sed "/:[0-9]/d")
do
tcpdump -l -i $interface -nn $@ | sed 's/^/[Interface:'"$interface"'] /' 2>/dev/null &