Skip to content
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 1 commit into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 59 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package main

import (
"io"
"os"

"github.com/aws/amazon-vpc-cni-k8s/pkg/utils/logger"
Expand Down Expand Up @@ -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")
Copy link
Member

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

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
}
6 changes: 2 additions & 4 deletions scripts/install-aws.sh
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