Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- exist_container=()
- containsElement () {
- local e match="$1"
- shift
- for e; do [[ "$e" == "$match" ]] && return 0; done
- return 1
- }
- for sandbox in $(docker ps -q --no-trunc --filter label=io.kubernetes.docker.type=podsandbox); do
- if docker inspect $sandbox | grep -q SandboxKey; then
- sandboxKey=$(docker inspect $sandbox | grep SandboxKey | awk '{print $NF}' | cut -d '"' -f 2)
- if [ -z sandboxKey ] || [ "/var/run/docker/netns/default" == "$sandboxKey" ]; then
- continue;
- fi
- exist_container+=($sandbox)
- fi
- done
- for ipfile in `ls /var/lib/cni/networks`; do
- if echo $ipfile | grep -q -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'; then
- if ! containsElement `cat /var/lib/cni/networks/$ipfile` "${exist_container[@]}"; then
- echo "file need to cleanup:" /var/lib/cni/networks/$ipfile
- echo "container id:" `cat /var/lib/cni/networks/$ipfile`
- if [ "1" == "$AUTO_CLEAN" ]; then
- echo "removing: $/var/lib/cni/networks/$ipfile"
- rm -f /var/lib/cni/networks/$ipfile
- fi
- fi
- fi
- done
Add Comment
Please, Sign In to add comment