Updates e2e_node test to allow both kubenet and cni to be specified for the network plugin.

This adds a simple CNI configuration which is added to the node during test setup.
This also modifies the default flags in services/kubelet.go to specify the "cni-bin-dir"
and the "cni-conf-dir" and removes the "network-plugin-dir" flag.  This leaves the default
network plugin to kubenet.
This commit is contained in:
Daniel Nardo
2017-04-11 16:23:54 -07:00
parent c3463d737e
commit 4e458ce001
4 changed files with 61 additions and 14 deletions

View File

@@ -27,13 +27,30 @@ import (
// utils.go contains functions used across test suites.
const (
cniRelease = "0799f5732f2a11b329d9e3d51b9c8f2e3759f2ff"
cniDirectory = "cni"
cniURL = "https://storage.googleapis.com/kubernetes-release/network-plugins/cni-" + cniRelease + ".tar.gz"
cniRelease = "0799f5732f2a11b329d9e3d51b9c8f2e3759f2ff"
cniDirectory = "cni" // The CNI tarball creates the "bin" directory under "cni".
cniConfDirectory = "cni/net.d"
cniURL = "https://storage.googleapis.com/kubernetes-release/network-plugins/cni-" + cniRelease + ".tar.gz"
)
// Install the cni plugin.
func installCNI(host, workspace string) error {
const cniConfig = `{
"name": "mynet",
"type": "bridge",
"bridge": "mynet0",
"isDefaultGateway": true,
"forceAddress": false,
"ipMasq": true,
"hairpinMode": true,
"ipam": {
"type": "host-local",
"subnet": "10.10.0.0/16"
}
}
`
// Install the cni plugin and add basic bridge configuration to the
// configuration directory.
func setupCNI(host, workspace string) error {
glog.V(2).Infof("Install CNI on %q", host)
cniPath := filepath.Join(workspace, cniDirectory)
cmd := getSSHCommand(" ; ",
@@ -43,6 +60,16 @@ func installCNI(host, workspace string) error {
if output, err := SSH(host, "sh", "-c", cmd); err != nil {
return fmt.Errorf("failed to install cni plugin on %q: %v output: %q", host, err, output)
}
glog.V(2).Infof("Adding CNI configuration on %q", host)
cniConfigPath := filepath.Join(workspace, cniConfDirectory)
cmd = getSSHCommand(" ; ",
fmt.Sprintf("mkdir -p %s", cniConfigPath),
fmt.Sprintf("echo %s > %s", quote(cniConfig), filepath.Join(cniConfigPath, "mynet.conf")),
)
if output, err := SSH(host, "sh", "-c", cmd); err != nil {
return fmt.Errorf("failed to write cni configuration on %q: %v output: %q", host, err, output)
}
return nil
}
@@ -95,3 +122,8 @@ func cleanupNodeProcesses(host string) {
// logs about failing to bind the required ports.
SSH(host, "sh", "-c", cmd)
}
// Quotes a shell literal so it can be nested within another shell scope.
func quote(s string) string {
return fmt.Sprintf("'\"'\"'%s'\"'\"'", s)
}