kuryr-kubernetes/cni_ds_init
Michał Dulko 3e3ed9dbb3 Remove way of running without kuryr-daemon
Deploying without kuryr-daemon is deprecated since Rocky and we
announced that it will be removed in the Rocky release notes. This
commit removes all the code that allows that, updates the documentation,
DevStack plugin and gates definitions.

Implements: blueprint remove-non-daemon

Change-Id: I65598d4a6ecb5c3dfde04dc5fefd7b02fc72a0cb
2019-02-04 12:53:00 +01:00

65 lines
1.9 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') == 'kuryr-cni'):
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 /etc/kuryr-cni/* /etc/cni/net.d
}
cleanup
deploy
exec kuryr-daemon --config-file /etc/kuryr/kuryr.conf