kuryr-kubernetes/cni_ds_init
Michał Dulko eecd44d335 cri-o support
This commit adds support for cri-o by changing the binary initially used
to run CNI plugin to runc and falling back to docker only in case it's
not available.

Also DevStack support for installing and configuring Kubernetes with
cri-o is added.

Implements: blueprint crio-support
Depends-On: Ib049d66058429e499f5d0932c4a749820bec73ff
Depends-On: Ic3c7d355a455298f43e37fb2aceddfd1e7eefaf2
Change-Id: I081edf0dbd4eb57826399c4820376381950080ed
2018-12-03 19:31:11 +01:00

70 lines
2.0 KiB
Bash
Executable File

#!/bin/bash -ex
function cleanup() {
rm -f "/etc/cni/net.d/10-kuryr.conf"
rm -f "/opt/cni/bin/kuryr-cni"
}
function deploy() {
POD_NAMESPACE=$(</var/run/secrets/kubernetes.io/serviceaccount/namespace)
# Write the script to a file.
cat > /kuryr-cni << EOF
#!/bin/bash -x
finder="
import json
import sys
mode = 'docker' if len(sys.argv) == 1 else sys.argv[1]
if mode == 'docker':
label_key = 'Labels'
id_key = 'Id'
else:
label_key = 'annotations'
id_key = 'id'
containers=json.load(sys.stdin)
# Looping over all the containers until we find the right one. We print it.
for container in containers:
if (label_key in container and
container[label_key].get('io.kubernetes.pod.name') == '${KURYR_CNI_POD_NAME}' and
container[label_key].get('io.kubernetes.pod.namespace') == '${POD_NAMESPACE}' and
container[label_key].get('io.kubernetes.container.name') != 'POD'):
print(container[id_key])
break
"
envs=(\$(env | grep ^CNI_))
if command -v runc > /dev/null; then
# We have runc binary, let's see if that works.
CONTAINERID=\`runc list -f json 2> /dev/null | python -c "\${finder}" runc\`
if [[ ! -z \${CONTAINERID} ]]; then
exec runc exec \${envs[@]/#/--env } "\${CONTAINERID}" kuryr-cni --config-file /etc/kuryr/kuryr.conf
fi
fi
# Fall back to using Docker binary.
# TODO(dulek): We might want to fetch socket path from config.
CONTAINERID=\`curl --unix-socket /var/run/docker.sock http://v1.24/containers/json 2> /dev/null | python -c "\${finder}" docker\`
docker exec \${envs[@]/#/--env } -i "\${CONTAINERID}" kuryr-cni --config-file /etc/kuryr/kuryr.conf
EOF
# Copy the script into the designated location
cp /kuryr-cni "/opt/cni/bin/kuryr-cni"
chmod +x /opt/cni/bin/kuryr-cni
cp /opt/kuryr-kubernetes/etc/cni/net.d/* /etc/cni/net.d
}
cleanup
deploy
# Start CNI daemon if required
if [ "$CNI_DAEMON" == "True" ]; then
exec kuryr-daemon --config-file /etc/kuryr/kuryr.conf
else
exec sleep infinity
fi