Skip to content

Instantly share code, notes, and snippets.

@dctrwatson
Created April 25, 2020 05:36
Show Gist options
  • Save dctrwatson/6f2f86747eec29c802afd9afed6ef54e to your computer and use it in GitHub Desktop.
Save dctrwatson/6f2f86747eec29c802afd9afed6ef54e to your computer and use it in GitHub Desktop.
Clean up cilium bpf programs
#!/usr/bin/env bash
if [[ "${EUID}" -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
while read -r cgroup_json; do
cgroup="$(jq -r .cgroup <<<"${cgroup_json}")"
# Don't want to detach systemd programs. Cilium attaches its program at the root and under docker.
if [[ "${cgroup}" != "/sys/fs/cgroup/unified" ]] && [[ "${cgroup}" != "/sys/fs/cgroup/unified/docker/"* ]]; then
continue
fi
while read -r id attach_type; do
bpftool cgroup detach "${cgroup}" "${attach_type}" id "${id}"
done < <(jq -r '.programs[] | [.id,.attach_type] | @tsv' <<<"${cgroup_json}")
done < <(bpftool cgroup tree /sys/fs/cgroup/unified --json | jq -c '.[]')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment