8b7d695d43
In Kuryr CNI container's entrypoint we were talking to K8s API to get the current container's CONTAINERID. This worked fine in most cases, but in more busy environments the value may be not saved into the K8s API yet and we end up with "null" as CONTAINERID. This obviously breaks kuryr-cni script that's being injected onto the host. Instead of implementing retries on "null" this commit uses another approach and fetches CONTAINERID from Docker API. Closes-Bug: 1777133 Change-Id: If0bbd55c4dc03077132b140a9a12cf6bd0f0cd03
51 lines
1.4 KiB
Bash
Executable File
51 lines
1.4 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
|
|
|
|
containers=json.load(sys.stdin)
|
|
for container in containers:
|
|
if ('Labels' in container and
|
|
container['Labels'].get('io.kubernetes.pod.name') == '${KURYR_CNI_POD_NAME}' and
|
|
container['Labels'].get('io.kubernetes.pod.namespace') == '${POD_NAMESPACE}' and
|
|
container['Labels'].get('io.kubernetes.docker.type') == 'container'):
|
|
print(container['Id'])
|
|
break
|
|
"
|
|
|
|
# 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}"\`
|
|
|
|
envs=(\$(env | grep ^CNI_))
|
|
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
|
|
kuryr-daemon --config-file /etc/kuryr/kuryr.conf
|
|
else
|
|
sleep infinity
|
|
fi
|