Skip to content

Instantly share code, notes, and snippets.

View clementnuss's full-sized avatar
🐄

Clément Nussbaumer clementnuss

🐄
View GitHub Profile
# given $netns the the network namespace id. e.g. netns=46165437
# 1st: we create a virtual interface
ip link add name toto_if type ipip local 10.20.30.46 remote 10.30.30.1
# 2nd, we put this interface in the network namespace of our pod
ip link set dev toto_if netns $netns
# 3rd, we can for example change the ip address or routing parameters:
nsenter -t $netns --network ip addr add 1.2.3.4/30 dev toto_if
@clementnuss
clementnuss / cni_interceptor.sh
Last active March 29, 2021 12:00
Bash script permitting to intercept CNI calls and log env, stdin, stdout, stderr
#!/bin/bash
# Auther Clément Nussbaumer <clement@astutus.org>, Aug 2020
#
# CNI interception script: permits to do live debugging of CNI calls.
# Usage: rename the real cni binary file with by prepending the orginal binary name with real_
# E.g. for multus, real_multus. Now put this script in place the binary:
# Concretely, name it `multus` if you want to intercept multus calls.
cni=$(echo $0 | awk '{split($0,r,"/"); print r[length(r)]}')
echo 'intercepted '$cni' cni with command: ' $CNI_COMMAND ' and caller: ' $(ps -o comm= $PPID) | logger -t cni
CNI_PATH=/opt/cni/bin:/opt/cni/bin
CNI_ARGS=IgnoreUnknown=true;K8S_POD_NAMESPACE=default;K8S_POD_NAME=nginx-f89759699-dv4hf;K8S_POD_INFRA_CONTAINER_ID=96638ef97eaf430ea57999413e5bc36caf25240bff2d24c49679fc7854850af0
CNI_CONTAINERID=96638ef97eaf430ea57999413e5bc36caf25240bff2d24c49679fc7854850af0
CNI_IFNAME=eth0
CNI_COMMAND=ADD
CNI_NETNS=/proc/280526/ns/net

the following ffmpeg permits to save images in highest quality to generate a timelapse:

export RTSP_STREAM='rtsps://abcdeffhijklmnop:1234/asdlfkjasdlf'
ffmpeg -loglevel error -rtsp_transport tcp \
  -i $RTSP_STREAM \
  -vf fps=1/120 \
  -q:v 1 -strftime 1 \
  "%Y-%m-%d_%H-%M-%S.jpg"
@clementnuss
clementnuss / yqblank.sh
Last active June 2, 2023 23:09
fish/bash function to prevent changing blank lines while using yq
#fish
function yqblank;
yq eval "$argv[1]" "$argv[2]" | diff -B "$argv[2]" - | patch "$argv[2]" -o -
end
#bash
yqblank() {
yq "$1" "$2" | diff -B "$2" - | patch "$2" -
}
@clementnuss
clementnuss / xclip
Last active May 23, 2022 13:31
`xclip` script to permit replacing xclip with lemonade easily
#!/bin/bash
stdin="$([[ -p /dev/stdin ]] && cat -)"
lemonade copy $stdin
@clementnuss
clementnuss / rollout-restart.go
Last active September 28, 2022 13:57
script to rollout restart all deployments on a kubernetes cluster by packs of 20, waiting 1min between packs
package main
import (
"fmt"
"os"
"strings"
"time"
"github.com/bitfield/script"
)
@clementnuss
clementnuss / s3-batch-deletion.md
Created January 7, 2023 09:21
Batch deletion of S3 objects #blog

Batch deletion of S3 objects

If you ever tried to delete more than a few hundred files on S3, you might have noticed how slow it was.

To speed-up the deletion, we can use a few bash commands to parallelize the deletion, and we can also use some json description of the objets we want to delete.

Concretely, it permits us to delete e.g. 1000 files with a single s3 API request.

How ?

@clementnuss
clementnuss / etcdctl-leader-transfer.md
Created July 7, 2023 05:49
etcd - move leader away

etcd - moving the leader away

When patching some Kubernetes control-plane nodes on which etcd also happens to be running, you might want to gracefully transfer the leadership of the etcd cluster away before patching and eventually patching the node.

This can be achieved with the following script, provided you specify the adequate environment variables in /etc/profile.d/etcd-all:

set -o pipefail && \
source /etc/profile.d/etcd-all && \
AM_LEADER=$(etcdctl endpoint status | grep $(hostname) | cut -d ',' -f 5 | tr -d ' ') && \
@clementnuss
clementnuss / eBPF-execve-argv-envp-print.md
Created November 28, 2023 13:36
eBPF - using bpftrace to debug argv and env of an executable

Using eBPF to print argv and envp when running a specific file

With bpftrace on Linux, it's quite simple to monitor when a specific binary is run, and to print it's args and the environment variables passed to it.

This can be done with the following bpftrace "program":

tracepoint:syscalls:sys_enter_execve
/str(args->filename) == "/etc/network/if-up.d/resolved" /
{