-
Notifications
You must be signed in to change notification settings - Fork 748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
copy CNI plugin and config in entrypoint not agent #735
Merged
+100
−102
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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,91 @@ | ||
#!/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 | ||
|
||
# Check for all the required binaries before we go forward | ||
if [ ! -x $(command -v aws-k8s-agent) ]; then | ||
echo "Required aws-k8s-agent executable not found." | ||
exit 1 | ||
fi | ||
if [ ! -x $(command -v grp_health_probe) ]; then | ||
echo "Required grp_health_probe executable not found." | ||
exit 1 | ||
fi | ||
|
||
AGENT_LOG_PATH=${AGENT_LOG_PATH:-aws-k8s-agent.log} | ||
HOST_CNI_BIN_PATH=${HOST_CNI_BIN_PATH:-/host/opt/cni/bin} | ||
HOST_CNI_CONFDIR_PATH=${HOST_CNI_CONFDIR_PATH:-/host/opt/cni/net.d} | ||
|
||
# Checks for IPAM connectivity on localhost port 50051, retrying connectivity | ||
# check with a timeout of 36 seconds | ||
mogren marked this conversation as resolved.
Show resolved
Hide resolved
|
||
wait_for_ipam() { | ||
local __sleep_time=0 | ||
|
||
until [ $__sleep_time -eq 8 ]; do | ||
sleep $(( __sleep_time++ )) | ||
if $(./grpc_health_probe -addr 127.0.0.1:50051 >/dev/null 2>&1); then | ||
return 0 | ||
fi | ||
done | ||
return 1 | ||
} | ||
|
||
echo -n "starting IPAM daemon in background ... " | ||
./aws-k8s-agent > $AGENT_LOG_PATH 2>&1 & | ||
echo "ok." | ||
jaypipes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 ... " | ||
|
||
cp portmap $HOST_CNI_BIN_PATH | ||
cp aws-cni $HOST_CNI_BIN_PATH$ | ||
cp aws-cni-support.sh $HOST_CNI_BIN_PATH | ||
|
||
sed -i s/__VETHPREFIX__/"${AWS_VPC_K8S_CNI_VETHPREFIX:-"eni"}"/g 10-aws.conflist | ||
sed -i s/__MTU__/"${AWS_VPC_ENI_MTU:-"9001"}"/g 10-aws.conflist | ||
cp 10-aws.conflist $HOST_CNI_CONFDIR_PATH | ||
|
||
echo " ok." | ||
|
||
if [[ -f "$HOST_CNI_CONFDIR_PATH/aws.conf" ]]; then | ||
rm "$HOST_CNI_CONFDIR_PATH/aws.conf" | ||
fi | ||
|
||
# bring the aws-k8s-agent process back into the foreground | ||
echo "foregrounding IPAM daemon ... " | ||
fg %1 >/dev/null 2>&1 || $(echo "failed (process terminated)" && cat $AGENT_LOG_PATH && exit 1) | ||
|
||
# Best practice states we should send the container's CMD output to stdout, so | ||
# let's tee back up the log file into stdout | ||
cat $AGENT_LOG_PATH |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, I would like to move these variables into a configMap so that they persisted upon upgrades. May be a separate PR and add //To do here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack. good idea.