Created
April 25, 2020 05:36
-
-
Save dctrwatson/6f2f86747eec29c802afd9afed6ef54e to your computer and use it in GitHub Desktop.
Clean up cilium bpf programs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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