Skip to content

Instantly share code, notes, and snippets.

View martinkennelly's full-sized avatar

Martin Kennelly martinkennelly

View GitHub Profile
@martinkennelly
martinkennelly / remove-snat-gw.sh
Created April 23, 2025 11:11
OCP 4.14-4.17: remove EgressIP SNAT from gateway router
#!/bin/bash
# Version 1.0 (23 Apr 2025)
# Martin Kennelly (OCP Networking)
# Designed to assist with https://issues.redhat.com/browse/OCPBUGS-42303
# Requires ovn-northd+ovn-controller to sync at least once for SNAT removal changes to propagate to data plane
# Must be executed before ovnkube-controller is started
DATE=$(date +"%Y-%m-%d-%H-%M")
echo "$DATE"
for NAT_UUID in $(ovn-nbctl --bare --column _uuid find nat external-ids:\"name\"!=\"\") ; do \
@martinkennelly
martinkennelly / check_all_nodes.sh
Last active February 24, 2025 17:32
Check OCP Nodes with SDN CNI for stale IPs
#!/bin/bash
# Iterate over all Nodes and checked for stale IP allocations. Retry problamatic Nodes until success.
# Ctrl + C to cancel
set -eu pipefail
CNI_NETWORK_DIR="/host/var/lib/cni/networks/openshift-sdn"
function is_number {
if [ -n "$1" ] && [ "$1" -eq "$1" ] 2>/dev/null; then
return 0
@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