Skip to content

Commit

Permalink
Copy the binary and config after ipamd is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Claes Mogren authored and mogren committed Aug 7, 2019
1 parent ffaf737 commit f9acdeb
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 11 deletions.
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")
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 {
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

0 comments on commit f9acdeb

Please sign in to comment.