Kubernetes integration with OpenStack networking
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cni_ds_init 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash -ex
  2. function cleanup() {
  3. rm -f "/etc/cni/net.d/10-kuryr.conf"
  4. rm -f "/opt/cni/bin/kuryr-cni"
  5. }
  6. function deploy() {
  7. POD_NAMESPACE=$(</var/run/secrets/kubernetes.io/serviceaccount/namespace)
  8. # Write the script to a file.
  9. cat > /kuryr-cni << EOF
  10. #!/bin/bash -x
  11. finder="
  12. import json
  13. import sys
  14. mode = 'docker' if len(sys.argv) == 1 else sys.argv[1]
  15. if mode == 'docker':
  16. label_key = 'Labels'
  17. id_key = 'Id'
  18. else:
  19. label_key = 'annotations'
  20. id_key = 'id'
  21. containers=json.load(sys.stdin)
  22. # Looping over all the containers until we find the right one. We print it.
  23. for container in containers:
  24. if (label_key in container and
  25. container[label_key].get('io.kubernetes.pod.name') == '${KURYR_CNI_POD_NAME}' and
  26. container[label_key].get('io.kubernetes.pod.namespace') == '${POD_NAMESPACE}' and
  27. container[label_key].get('io.kubernetes.container.name') == 'kuryr-cni'):
  28. print(container[id_key])
  29. break
  30. "
  31. envs=(\$(env | grep ^CNI_))
  32. if command -v runc > /dev/null; then
  33. # We have runc binary, let's see if that works.
  34. CONTAINERID=\`runc list -f json 2> /dev/null | python -c "\${finder}" runc\`
  35. if [[ ! -z \${CONTAINERID} ]]; then
  36. exec runc exec \${envs[@]/#/--env } "\${CONTAINERID}" kuryr-cni --config-file /etc/kuryr/kuryr.conf
  37. fi
  38. fi
  39. # Fall back to using Docker binary.
  40. # TODO(dulek): We might want to fetch socket path from config.
  41. CONTAINERID=\`curl --unix-socket /var/run/docker.sock http://v1.24/containers/json 2> /dev/null | python -c "\${finder}" docker\`
  42. docker exec \${envs[@]/#/--env } -i "\${CONTAINERID}" kuryr-cni --config-file /etc/kuryr/kuryr.conf
  43. EOF
  44. # Copy the script into the designated location
  45. cp /kuryr-cni "/opt/cni/bin/kuryr-cni"
  46. chmod +x /opt/cni/bin/kuryr-cni
  47. cp /etc/kuryr-cni/* /etc/cni/net.d
  48. }
  49. cleanup
  50. deploy
  51. exec kuryr-daemon --config-file /etc/kuryr/kuryr.conf