-
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 the binary and config after ipamd is ready #576
Merged
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
package main | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"github.com/aws/amazon-vpc-cni-k8s/pkg/utils/logger" | ||
|
@@ -57,27 +58,78 @@ func _main() int { | |
go eniConfigController.Start() | ||
} | ||
|
||
awsK8sAgent, err := ipamd.New(discoverController, eniConfigController) | ||
ipamContext, err := ipamd.New(discoverController, eniConfigController) | ||
|
||
if err != nil { | ||
log.Error("Initialization failure ", err) | ||
log.Errorf("Initialization failure: %v", err) | ||
return 1 | ||
} | ||
|
||
// Pool manager | ||
go awsK8sAgent.StartNodeIPPoolManager() | ||
go ipamContext.StartNodeIPPoolManager() | ||
|
||
// Prometheus metrics | ||
go awsK8sAgent.ServeMetrics() | ||
go ipamContext.ServeMetrics() | ||
|
||
// CNI introspection endpoints | ||
go awsK8sAgent.ServeIntrospection() | ||
go ipamContext.ServeIntrospection() | ||
|
||
err = awsK8sAgent.RunRPCHandler() | ||
// Copy the CNI plugin and config. This will mark the node as Ready. | ||
log.Info("Copying /app/aws-cni to /host/opt/cni/bin/aws-cni") | ||
err = copyFileContents("/app/aws-cni", "/host/opt/cni/bin/aws-cni") | ||
if err != nil { | ||
log.Error("Failed to set up gRPC handler ", err) | ||
log.Errorf("Failed to copy aws-cni: %v", err) | ||
return 1 | ||
} | ||
|
||
log.Info("Copying /app/10-aws.conflist to /host/etc/cni/net.d/10-aws.conflist") | ||
err = copyFileContents("/app/10-aws.conflist", "/host/etc/cni/net.d/10-aws.conflist") | ||
if err != nil { | ||
log.Errorf("Failed to copy 10-aws.conflist: %v", err) | ||
return 1 | ||
} | ||
|
||
// Start the RPC listener | ||
err = ipamContext.RunRPCHandler() | ||
if err != nil { | ||
log.Errorf("Failed to set up gRPC handler: %v", err) | ||
return 1 | ||
} | ||
return 0 | ||
} | ||
|
||
// copyFileContents copies a file | ||
func copyFileContents(src, dst string) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have a test for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding in a separate PR. |
||
in, err := os.Open(src) | ||
if err != nil { | ||
return err | ||
} | ||
defer in.Close() | ||
out, err := os.Create(dst) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { | ||
e := out.Close() | ||
if err == nil { | ||
err = e | ||
} | ||
}() | ||
if _, err = io.Copy(out, in); err != nil { | ||
return err | ||
} | ||
err = out.Sync() | ||
if err != nil { | ||
return err | ||
} | ||
si, err := os.Stat(src) | ||
if err != nil { | ||
return err | ||
} | ||
err = os.Chmod(dst, si.Mode()) | ||
if err != nil { | ||
return err | ||
} | ||
log.Debugf("Copied file from %q to %q", src, dst) | ||
return err | ||
} |
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 |
---|---|---|
@@ -1,14 +1,12 @@ | ||
#!/usr/bin/env bash | ||
echo "===== Starting installing AWS-CNI =========" | ||
echo "====== Installing AWS-CNI ======" | ||
sed -i s/__VETHPREFIX__/${AWS_VPC_K8S_CNI_VETHPREFIX:-"eni"}/g /app/10-aws.conflist | ||
cp /app/aws-cni /host/opt/cni/bin/ | ||
cp /app/portmap /host/opt/cni/bin/ | ||
cp /app/aws-cni-support.sh /host/opt/cni/bin/ | ||
cp /app/10-aws.conflist /host/etc/cni/net.d/ | ||
|
||
if [[ -f /host/etc/cni/net.d/aws.conf ]]; then | ||
rm /host/etc/cni/net.d/aws.conf | ||
fi | ||
|
||
echo "===== Starting amazon-k8s-agent ===========" | ||
echo "====== Starting amazon-k8s-agent ======" | ||
/app/aws-k8s-agent |
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.
I think this is fine for now, but do we want to parameterize this filename? I'm take it or leave it