Guest User

Untitled

a guest
Dec 16th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. exist_container=()
  5.  
  6. containsElement () {
  7. local e match="$1"
  8. shift
  9. for e; do [[ "$e" == "$match" ]] && return 0; done
  10. return 1
  11. }
  12.  
  13. for sandbox in $(docker ps -q --no-trunc --filter label=io.kubernetes.docker.type=podsandbox); do
  14. if docker inspect $sandbox | grep -q SandboxKey; then
  15. sandboxKey=$(docker inspect $sandbox | grep SandboxKey | awk '{print $NF}' | cut -d '"' -f 2)
  16. if [ -z sandboxKey ] || [ "/var/run/docker/netns/default" == "$sandboxKey" ]; then
  17. continue;
  18. fi
  19. exist_container+=($sandbox)
  20. fi
  21. done
  22.  
  23. for ipfile in `ls /var/lib/cni/networks`; do
  24. if echo $ipfile | grep -q -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'; then
  25. if ! containsElement `cat /var/lib/cni/networks/$ipfile` "${exist_container[@]}"; then
  26. echo "file need to cleanup:" /var/lib/cni/networks/$ipfile
  27. echo "container id:" `cat /var/lib/cni/networks/$ipfile`
  28. if [ "1" == "$AUTO_CLEAN" ]; then
  29. echo "removing: $/var/lib/cni/networks/$ipfile"
  30. rm -f /var/lib/cni/networks/$ipfile
  31. fi
  32. fi
  33. fi
  34. done
Add Comment
Please, Sign In to add comment