ovs.sh.j2 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. TTY=""
  3. BIMG={{ insecure_registry | default('registry.cn-beijing.aliyuncs.com') }}/{{ registry | default('yunion') }}/openvswitch:2.12.4-20260212
  4. {% if k8s_or_k3s | default('k3s') == 'k3s' %}
  5. if [ -t 0 ]; then
  6. TTY="-t"
  7. fi
  8. IMG=$(k3s ctr images list -q | grep -m 1 -w "yunion/openvswitch")
  9. if [ -z "$IMG" ]; then
  10. IMG=$(k3s ctr images list -q | grep -m 1 -w "yunionio/openvswitch")
  11. if [ -z "$IMG" ]; then
  12. IMG=$BIMG
  13. k3s ctr images list name==$IMG -q | grep $IMG > /dev/null
  14. if [ $? -ne 0 ]; then
  15. k3s ctr images pull $IMG
  16. fi
  17. fi
  18. fi
  19. k3s ctr run --rm --net-host $TTY \
  20. --mount type=bind,src=/tmp,dst=/tmp,options=rbind \
  21. --mount type=bind,src=/etc/openvswitch,dst=/etc/openvswitch,options=rbind \
  22. --mount type=bind,src=/var/run/openvswitch,dst=/var/run/openvswitch,options=rbind \
  23. $IMG \
  24. openvswitch \
  25. /usr/bin/$(basename $0) $@
  26. {% else %}
  27. if [ -t 0 ]; then
  28. TTY="-it"
  29. fi
  30. IMG=$(docker image ls --filter 'reference=*/yunion/openvswitch' | grep -m 1 -w "yunion/openvswitch" | awk '{print $1 ":" $2}')
  31. if [ -z "$IMG" ]; then
  32. IMG=$(docker image ls --filter 'reference=*/yunionio/openvswitch' | grep -m 1 -w "yunionio/openvswitch" | awk '{print $1 ":" $2}')
  33. if [ -z "$IMG" ]; then
  34. IMG=$BIMG
  35. fi
  36. fi
  37. docker run --rm --network host $TTY \
  38. -v /tmp:/tmp \
  39. -v /etc/openvswitch:/etc/openvswitch \
  40. -v /var/run/openvswitch:/var/run/openvswitch \
  41. $IMG \
  42. /usr/bin/$(basename $0) $@
  43. {% endif %}