-
Notifications
You must be signed in to change notification settings - Fork 750
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
copy CNI plugin and config in entrypoint not agent
Replaces the hard-coded copying of the CNI plugin binary and configuration file from the main.go of the aws-k8s-agent (the IPAMd daemon) into a new entrypoint.sh script that backgrounds the IPAM daemon, waits for it to listen on port 50051 and then proceeds to copy the CNI plugin binaries and configuration files into the well-known directory for Kubelet to see them as ready.
- Loading branch information
Showing
5 changed files
with
79 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env bash | ||
|
||
# NOTE(jaypipes): Normally, we would prefer *not* to have an entrypoint script | ||
# and instead just start the agent daemon as the container's CMD. However, the | ||
# design of CNI is such that Kubelet looks for the presence of binaries and CNI | ||
# configuration files in specific directories, and the presence of those files | ||
# is the trigger to Kubelet that that particular CNI plugin is "ready". | ||
# | ||
# In the case of the AWS VPC CNI plugin, we have two components to the plugin. | ||
# The first component is the actual CNI binary that is execve'd from Kubelet | ||
# when a container is started or destroyed. The second component is the | ||
# aws-k8s-agent daemon which houses the IPAM controller. | ||
# | ||
# As mentioned above, Kubelet considers a CNI plugin "ready" when it sees the | ||
# binary and configuration file for the plugin in a well-known directory. For | ||
# the AWS VPC CNI plugin binary, we only want to copy the CNI plugin binary | ||
# into that well-known directory AFTER we have succeessfully started the IPAM | ||
# daemon and know that it can connect to Kubernetes and the local EC2 metadata | ||
# service. This is why this entrypoint script exists; we start the IPAM daemon | ||
# and wait until we know it is up and running successfully before copying the | ||
# CNI plugin binary and its configuration file to the well-known directory that | ||
# Kubelet looks in. | ||
|
||
# turn on bash's job control | ||
set -m | ||
|
||
# Checks for IPAM connectivity on localhost port 50051, retrying connectivity | ||
# check with a timeout of 36 seconds | ||
wait_for_ipam() { | ||
local __sleep_time=0 | ||
|
||
until [ $__sleep_time -eq 8 ]; do | ||
sleep $(( __sleep_time++ )) | ||
if /app/grpc_health_probe -addr 127.0.0.1:50051 </dev/null; then | ||
return 0 | ||
fi | ||
done | ||
return 1 | ||
} | ||
|
||
echo -n "starting IPAM daemon in background ... " | ||
./app/aws-k8s-agent & | ||
echo "ok." | ||
|
||
echo -n "checking for IPAM connectivity ... " | ||
|
||
if ! wait_for_ipam; then | ||
echo " failed." | ||
echo "timed out waiting for IPAM daemon to start." | ||
exit 1 | ||
fi | ||
|
||
echo "ok." | ||
|
||
echo -n "copying CNI plugin binaries and config files ... " | ||
|
||
sed -i s/__VETHPREFIX__/"${AWS_VPC_K8S_CNI_VETHPREFIX:-"eni"}"/g /app/10-aws.conflist | ||
sed -i s/__MTU__/"${AWS_VPC_ENI_MTU:-"9001"}"/g /app/10-aws.conflist | ||
mv /app/10-aws.conflist /host/etc/cni/net.d/ | ||
mv /app/portmap /host/opt/cni/bin/ | ||
mv /app/aws-cni /host/opt/cni/bin/ | ||
mv /app/aws-cni-support.sh /host/opt/cni/bin/ | ||
|
||
echo " ok." | ||
|
||
if [[ -f /host/etc/cni/net.d/aws.conf ]]; then | ||
rm /host/etc/cni/net.d/aws.conf | ||
fi | ||
|
||
# bring the aws-k8s-agent process back into the foreground | ||
echo -n "foregrounding IPAM daemon ... " | ||
fg %1 | ||
echo "ok." |