forked from barak/tarpoon
Add glide.yaml and vendor deps
This commit is contained in:
parent
db918f12ad
commit
5b3d5e81bd
18880 changed files with 5166045 additions and 1 deletions
43
vendor/k8s.io/kubernetes/pkg/kubelet/network/exec/BUILD
generated
vendored
Normal file
43
vendor/k8s.io/kubernetes/pkg/kubelet/network/exec/BUILD
generated
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_binary",
|
||||
"go_library",
|
||||
"go_test",
|
||||
"cgo_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"exec.go",
|
||||
"exec_unix.go",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/apis/componentconfig:go_default_library",
|
||||
"//pkg/apis/meta/v1:go_default_library",
|
||||
"//pkg/kubelet/container:go_default_library",
|
||||
"//pkg/kubelet/network:go_default_library",
|
||||
"//pkg/util/exec:go_default_library",
|
||||
"//vendor:github.com/golang/glog",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["exec_test.go"],
|
||||
library = "go_default_library",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/apis/componentconfig:go_default_library",
|
||||
"//pkg/kubelet/container:go_default_library",
|
||||
"//pkg/kubelet/network:go_default_library",
|
||||
"//pkg/kubelet/network/testing:go_default_library",
|
||||
"//pkg/util/sets:go_default_library",
|
||||
"//pkg/util/testing:go_default_library",
|
||||
],
|
||||
)
|
||||
203
vendor/k8s.io/kubernetes/pkg/kubelet/network/exec/exec.go
generated
vendored
Normal file
203
vendor/k8s.io/kubernetes/pkg/kubelet/network/exec/exec.go
generated
vendored
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
Copyright 2014 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package exec scans and loads networking plugins that are installed
|
||||
// under /usr/libexec/kubernetes/kubelet-plugins/net/exec/
|
||||
// The layout convention for a plugin is:
|
||||
// plugin-name/ (plugins have to be directories first)
|
||||
// plugin-name/plugin-name (executable that will be called out, see Vendoring Note for more nuances)
|
||||
// plugin-name/<other-files>
|
||||
// where, 'executable' has the following requirements:
|
||||
// - should have exec permissions
|
||||
// - should give non-zero exit code on failure, and zero on success
|
||||
// - the arguments will be <action> <pod_namespace> <pod_name> <docker_id_of_infra_container>
|
||||
// whereupon, <action> will be one of:
|
||||
// - init, called when the kubelet loads the plugin
|
||||
// - setup, called after the infra container of a pod is
|
||||
// created, but before other containers of the pod are created
|
||||
// - teardown, called before the pod infra container is killed
|
||||
// - status, called at regular intervals and is supposed to return a json
|
||||
// formatted output indicating the pod's IPAddress(v4/v6). An empty string value or an erroneous output
|
||||
// will mean the container runtime (docker) will be asked for the PodIP
|
||||
// e.g. {
|
||||
// "apiVersion" : "v1beta1",
|
||||
// "kind" : "PodNetworkStatus",
|
||||
// "ip" : "10.20.30.40"
|
||||
// }
|
||||
// The fields "apiVersion" and "kind" are optional in version v1beta1
|
||||
// As the executables are called, the file-descriptors stdin, stdout, stderr
|
||||
// remain open. The combined output of stdout/stderr is captured and logged.
|
||||
//
|
||||
// Note: If the pod infra container self-terminates (e.g. crashes or is killed),
|
||||
// the entire pod lifecycle will be restarted, but teardown will not be called.
|
||||
//
|
||||
// Vendoring Note:
|
||||
// Plugin Names can be vendored also. Use '~' as the escaped name for plugin directories.
|
||||
// And expect command line argument to call vendored plugins as 'vendor/pluginName'
|
||||
// e.g. pluginName = mysdn
|
||||
// vendorname = mycompany
|
||||
// then, plugin layout should be
|
||||
// mycompany~mysdn/
|
||||
// mycompany~mysdn/mysdn (this becomes the executable)
|
||||
// mycompany~mysdn/<other-files>
|
||||
// and, call the kubelet with '--network-plugin=mycompany/mysdn'
|
||||
package exec
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kubernetes/pkg/apis/componentconfig"
|
||||
metav1 "k8s.io/kubernetes/pkg/apis/meta/v1"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||
utilexec "k8s.io/kubernetes/pkg/util/exec"
|
||||
)
|
||||
|
||||
type execNetworkPlugin struct {
|
||||
network.NoopNetworkPlugin
|
||||
|
||||
execName string
|
||||
execPath string
|
||||
host network.Host
|
||||
}
|
||||
|
||||
const (
|
||||
initCmd = "init"
|
||||
setUpCmd = "setup"
|
||||
tearDownCmd = "teardown"
|
||||
statusCmd = "status"
|
||||
defaultDir = "/usr/libexec/kubernetes/kubelet-plugins/net/exec/"
|
||||
)
|
||||
|
||||
func ProbeNetworkPlugins(pluginDir string) []network.NetworkPlugin {
|
||||
execPlugins := []network.NetworkPlugin{}
|
||||
|
||||
if pluginDir == "" {
|
||||
pluginDir = defaultDir
|
||||
}
|
||||
|
||||
files, _ := ioutil.ReadDir(pluginDir)
|
||||
for _, f := range files {
|
||||
// only directories are counted as plugins
|
||||
// and pluginDir/dirname/dirname should be an executable
|
||||
// unless dirname contains '~' for escaping namespace
|
||||
// e.g. dirname = vendor~ipvlan
|
||||
// then, executable will be pluginDir/dirname/ipvlan
|
||||
if f.IsDir() {
|
||||
execPath := path.Join(pluginDir, f.Name())
|
||||
execPlugins = append(execPlugins, &execNetworkPlugin{execName: network.UnescapePluginName(f.Name()), execPath: execPath})
|
||||
}
|
||||
}
|
||||
return execPlugins
|
||||
}
|
||||
|
||||
func (plugin *execNetworkPlugin) Init(host network.Host, hairpinMode componentconfig.HairpinMode, nonMasqueradeCIDR string, mtu int) error {
|
||||
err := plugin.validate()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
plugin.host = host
|
||||
// call the init script
|
||||
out, err := utilexec.New().Command(plugin.getExecutable(), initCmd).CombinedOutput()
|
||||
if err != nil {
|
||||
glog.V(5).Infof("Init 'exec' network plugin output: %s, %v", string(out), err)
|
||||
} else {
|
||||
glog.V(5).Infof("Init 'exec' network plugin output: %s", string(out))
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (plugin *execNetworkPlugin) getExecutable() string {
|
||||
parts := strings.Split(plugin.execName, "/")
|
||||
execName := parts[len(parts)-1]
|
||||
return path.Join(plugin.execPath, execName)
|
||||
}
|
||||
|
||||
func (plugin *execNetworkPlugin) Name() string {
|
||||
return plugin.execName
|
||||
}
|
||||
|
||||
func (plugin *execNetworkPlugin) validate() error {
|
||||
if !isExecutable(plugin.getExecutable()) {
|
||||
errStr := fmt.Sprintf("Invalid exec plugin. Executable '%s' does not have correct permissions.", plugin.execName)
|
||||
return errors.New(errStr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (plugin *execNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.ContainerID) error {
|
||||
out, err := utilexec.New().Command(plugin.getExecutable(), setUpCmd, namespace, name, id.ID).CombinedOutput()
|
||||
if err != nil {
|
||||
glog.V(5).Infof("SetUpPod 'exec' network plugin output: %s, %v", string(out), err)
|
||||
} else {
|
||||
glog.V(5).Infof("SetUpPod 'exec' network plugin output: %s", string(out))
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (plugin *execNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.ContainerID) error {
|
||||
out, err := utilexec.New().Command(plugin.getExecutable(), tearDownCmd, namespace, name, id.ID).CombinedOutput()
|
||||
if err != nil {
|
||||
glog.V(5).Infof("TearDownPod 'exec' network plugin output: %s, %v", string(out), err)
|
||||
} else {
|
||||
glog.V(5).Infof("TearDownPod 'exec' network plugin output: %s", string(out))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (plugin *execNetworkPlugin) GetPodNetworkStatus(namespace string, name string, id kubecontainer.ContainerID) (*network.PodNetworkStatus, error) {
|
||||
out, err := utilexec.New().Command(plugin.getExecutable(), statusCmd, namespace, name, id.ID).CombinedOutput()
|
||||
if err != nil {
|
||||
glog.V(5).Infof("Status 'exec' network plugin output: %s, %v", string(out), err)
|
||||
return nil, err
|
||||
} else {
|
||||
glog.V(5).Infof("Status 'exec' network plugin output: %s", string(out))
|
||||
}
|
||||
if string(out) == "" {
|
||||
return nil, nil
|
||||
}
|
||||
findVersion := struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
}{}
|
||||
err = json.Unmarshal(out, &findVersion)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// check kind and version
|
||||
if findVersion.Kind != "" && findVersion.Kind != "PodNetworkStatus" {
|
||||
errStr := fmt.Sprintf("Invalid 'kind' returned in network status for pod '%s'. Valid value is 'PodNetworkStatus', got '%s'.", name, findVersion.Kind)
|
||||
return nil, errors.New(errStr)
|
||||
}
|
||||
switch findVersion.APIVersion {
|
||||
case "":
|
||||
fallthrough
|
||||
case "v1beta1":
|
||||
networkStatus := &network.PodNetworkStatus{}
|
||||
err = json.Unmarshal(out, networkStatus)
|
||||
return networkStatus, err
|
||||
}
|
||||
errStr := fmt.Sprintf("Unknown version '%s' in network status for pod '%s'.", findVersion.APIVersion, name)
|
||||
return nil, errors.New(errStr)
|
||||
}
|
||||
341
vendor/k8s.io/kubernetes/pkg/kubelet/network/exec/exec_test.go
generated
vendored
Normal file
341
vendor/k8s.io/kubernetes/pkg/kubelet/network/exec/exec_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,341 @@
|
|||
// +build linux
|
||||
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package exec
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path"
|
||||
"sync"
|
||||
"testing"
|
||||
"text/template"
|
||||
|
||||
"k8s.io/kubernetes/pkg/apis/componentconfig"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||
nettest "k8s.io/kubernetes/pkg/kubelet/network/testing"
|
||||
"k8s.io/kubernetes/pkg/util/sets"
|
||||
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||
)
|
||||
|
||||
func tmpDirOrDie() string {
|
||||
dir, err := utiltesting.MkTmpdir("exec-test")
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("error creating tmp dir: %v", err))
|
||||
}
|
||||
return path.Join(dir, "fake", "plugins", "net")
|
||||
}
|
||||
|
||||
var lock sync.Mutex
|
||||
var namesInUse = sets.NewString()
|
||||
|
||||
func selectName() string {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
for {
|
||||
pluginName := fmt.Sprintf("test%d", rand.Intn(1000))
|
||||
if !namesInUse.Has(pluginName) {
|
||||
namesInUse.Insert(pluginName)
|
||||
return pluginName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func releaseName(name string) {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
namesInUse.Delete(name)
|
||||
}
|
||||
|
||||
func installPluginUnderTest(t *testing.T, vendorName, testPluginPath, plugName string, execTemplateData *map[string]interface{}) {
|
||||
vendoredName := plugName
|
||||
if vendorName != "" {
|
||||
vendoredName = fmt.Sprintf("%s~%s", vendorName, plugName)
|
||||
}
|
||||
pluginDir := path.Join(testPluginPath, vendoredName)
|
||||
err := os.MkdirAll(pluginDir, 0777)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to create plugin dir %q: %v", pluginDir, err)
|
||||
}
|
||||
pluginExec := path.Join(pluginDir, plugName)
|
||||
f, err := os.Create(pluginExec)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to install plugin %q: %v", pluginExec, err)
|
||||
}
|
||||
defer f.Close()
|
||||
err = f.Chmod(0777)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to set exec perms on plugin %q: %v", pluginExec, err)
|
||||
}
|
||||
const execScriptTempl = `#!/bin/bash
|
||||
|
||||
# If status hook is called print the expected json to stdout
|
||||
if [ "$1" == "status" ]; then
|
||||
echo -n '{
|
||||
"ip" : "{{.IPAddress}}"
|
||||
}'
|
||||
fi
|
||||
|
||||
# Direct the arguments to a file to be tested against later
|
||||
echo -n "$@" &> {{.OutputFile}}
|
||||
`
|
||||
if execTemplateData == nil {
|
||||
execTemplateData = &map[string]interface{}{
|
||||
"IPAddress": "10.20.30.40",
|
||||
"OutputFile": path.Join(pluginDir, plugName+".out"),
|
||||
}
|
||||
}
|
||||
|
||||
tObj := template.Must(template.New("test").Parse(execScriptTempl))
|
||||
buf := &bytes.Buffer{}
|
||||
if err := tObj.Execute(buf, *execTemplateData); err != nil {
|
||||
t.Errorf("Error in executing script template: %v", err)
|
||||
}
|
||||
execScript := buf.String()
|
||||
_, err = f.WriteString(execScript)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to write plugin %q: %v", pluginExec, err)
|
||||
}
|
||||
}
|
||||
|
||||
func tearDownPlugin(testPluginPath string) {
|
||||
err := os.RemoveAll(testPluginPath)
|
||||
if err != nil {
|
||||
fmt.Printf("Error in cleaning up test: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectPlugin(t *testing.T) {
|
||||
// The temp dir where test plugins will be stored.
|
||||
testPluginPath := tmpDirOrDie()
|
||||
|
||||
// install some random plugin under testPluginPath
|
||||
pluginName := selectName()
|
||||
defer tearDownPlugin(testPluginPath)
|
||||
defer releaseName(pluginName)
|
||||
|
||||
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
||||
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to select the desired plugin: %v", err)
|
||||
}
|
||||
if plug.Name() != pluginName {
|
||||
t.Errorf("Wrong plugin selected, chose %s, got %s\n", pluginName, plug.Name())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectVendoredPlugin(t *testing.T) {
|
||||
// The temp dir where test plugins will be stored.
|
||||
testPluginPath := tmpDirOrDie()
|
||||
|
||||
// install some random plugin under testPluginPath
|
||||
pluginName := selectName()
|
||||
defer tearDownPlugin(testPluginPath)
|
||||
defer releaseName(pluginName)
|
||||
|
||||
vendor := "mycompany"
|
||||
installPluginUnderTest(t, vendor, testPluginPath, pluginName, nil)
|
||||
|
||||
vendoredPluginName := fmt.Sprintf("%s/%s", vendor, pluginName)
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), vendoredPluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to select the desired plugin: %v", err)
|
||||
}
|
||||
if plug.Name() != vendoredPluginName {
|
||||
t.Errorf("Wrong plugin selected, chose %s, got %s\n", vendoredPluginName, plug.Name())
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectWrongPlugin(t *testing.T) {
|
||||
// The temp dir where test plugins will be stored.
|
||||
testPluginPath := tmpDirOrDie()
|
||||
|
||||
// install some random plugin under testPluginPath
|
||||
pluginName := selectName()
|
||||
defer tearDownPlugin(testPluginPath)
|
||||
defer releaseName(pluginName)
|
||||
|
||||
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
||||
|
||||
wrongPlugin := "abcd"
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), wrongPlugin, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||
if plug != nil || err == nil {
|
||||
t.Errorf("Expected to see an error. Wrong plugin selected.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPluginValidation(t *testing.T) {
|
||||
// The temp dir where test plugins will be stored.
|
||||
testPluginPath := tmpDirOrDie()
|
||||
|
||||
// install some random plugin under testPluginPath
|
||||
pluginName := selectName()
|
||||
defer tearDownPlugin(testPluginPath)
|
||||
defer releaseName(pluginName)
|
||||
|
||||
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
||||
|
||||
// modify the perms of the pluginExecutable
|
||||
f, err := os.Open(path.Join(testPluginPath, pluginName, pluginName))
|
||||
if err != nil {
|
||||
t.Errorf("Nil value expected.")
|
||||
}
|
||||
err = f.Chmod(0444)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to set perms on plugin exec")
|
||||
}
|
||||
f.Close()
|
||||
|
||||
_, err = network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||
if err == nil {
|
||||
// we expected an error here because validation would have failed
|
||||
t.Errorf("Expected non-nil value.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPluginSetupHook(t *testing.T) {
|
||||
// The temp dir where test plugins will be stored.
|
||||
testPluginPath := tmpDirOrDie()
|
||||
|
||||
// install some random plugin under testPluginPath
|
||||
pluginName := selectName()
|
||||
defer tearDownPlugin(testPluginPath)
|
||||
defer releaseName(pluginName)
|
||||
|
||||
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
||||
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||
|
||||
err = plug.SetUpPod("podNamespace", "podName", kubecontainer.ContainerID{Type: "docker", ID: "dockerid2345"})
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil: %v", err)
|
||||
}
|
||||
// check output of setup hook
|
||||
output, err := ioutil.ReadFile(path.Join(testPluginPath, pluginName, pluginName+".out"))
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil")
|
||||
}
|
||||
expectedOutput := "setup podNamespace podName dockerid2345"
|
||||
if string(output) != expectedOutput {
|
||||
t.Errorf("Mismatch in expected output for setup hook. Expected '%s', got '%s'", expectedOutput, string(output))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPluginTearDownHook(t *testing.T) {
|
||||
// The temp dir where test plugins will be stored.
|
||||
testPluginPath := tmpDirOrDie()
|
||||
|
||||
// install some random plugin under testPluginPath
|
||||
pluginName := selectName()
|
||||
defer tearDownPlugin(testPluginPath)
|
||||
defer releaseName(pluginName)
|
||||
|
||||
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
||||
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||
|
||||
err = plug.TearDownPod("podNamespace", "podName", kubecontainer.ContainerID{Type: "docker", ID: "dockerid2345"})
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil")
|
||||
}
|
||||
// check output of setup hook
|
||||
output, err := ioutil.ReadFile(path.Join(testPluginPath, pluginName, pluginName+".out"))
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil")
|
||||
}
|
||||
expectedOutput := "teardown podNamespace podName dockerid2345"
|
||||
if string(output) != expectedOutput {
|
||||
t.Errorf("Mismatch in expected output for teardown hook. Expected '%s', got '%s'", expectedOutput, string(output))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPluginStatusHook(t *testing.T) {
|
||||
// The temp dir where test plugins will be stored.
|
||||
testPluginPath := tmpDirOrDie()
|
||||
|
||||
// install some random plugin under testPluginPath
|
||||
pluginName := selectName()
|
||||
defer tearDownPlugin(testPluginPath)
|
||||
defer releaseName(pluginName)
|
||||
|
||||
installPluginUnderTest(t, "", testPluginPath, pluginName, nil)
|
||||
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||
|
||||
ip, err := plug.GetPodNetworkStatus("namespace", "name", kubecontainer.ContainerID{Type: "docker", ID: "dockerid2345"})
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil got %v", err)
|
||||
}
|
||||
// check output of status hook
|
||||
output, err := ioutil.ReadFile(path.Join(testPluginPath, pluginName, pluginName+".out"))
|
||||
if err != nil {
|
||||
t.Errorf("Expected nil")
|
||||
}
|
||||
expectedOutput := "status namespace name dockerid2345"
|
||||
if string(output) != expectedOutput {
|
||||
t.Errorf("Mismatch in expected output for status hook. Expected '%s', got '%s'", expectedOutput, string(output))
|
||||
}
|
||||
if ip.IP.String() != "10.20.30.40" {
|
||||
t.Errorf("Mismatch in expected output for status hook. Expected '10.20.30.40', got '%s'", ip.IP.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestPluginStatusHookIPv6(t *testing.T) {
|
||||
// The temp dir where test plugins will be stored.
|
||||
testPluginPath := tmpDirOrDie()
|
||||
|
||||
// install some random plugin under testPluginPath
|
||||
pluginName := selectName()
|
||||
defer tearDownPlugin(testPluginPath)
|
||||
defer releaseName(pluginName)
|
||||
|
||||
pluginDir := path.Join(testPluginPath, pluginName)
|
||||
execTemplate := &map[string]interface{}{
|
||||
"IPAddress": "fe80::e2cb:4eff:fef9:6710",
|
||||
"OutputFile": path.Join(pluginDir, pluginName+".out"),
|
||||
}
|
||||
installPluginUnderTest(t, "", testPluginPath, pluginName, execTemplate)
|
||||
|
||||
plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil), componentconfig.HairpinNone, "10.0.0.0/8", network.UseDefaultMTU)
|
||||
if err != nil {
|
||||
t.Errorf("InitNetworkPlugin() failed: %v", err)
|
||||
}
|
||||
|
||||
ip, err := plug.GetPodNetworkStatus("namespace", "name", kubecontainer.ContainerID{Type: "docker", ID: "dockerid2345"})
|
||||
if err != nil {
|
||||
t.Errorf("Status() failed: %v", err)
|
||||
}
|
||||
// check output of status hook
|
||||
outPath := path.Join(testPluginPath, pluginName, pluginName+".out")
|
||||
output, err := ioutil.ReadFile(outPath)
|
||||
if err != nil {
|
||||
t.Errorf("ReadFile(%q) failed: %v", outPath, err)
|
||||
}
|
||||
expectedOutput := "status namespace name dockerid2345"
|
||||
if string(output) != expectedOutput {
|
||||
t.Errorf("Mismatch in expected output for status hook. Expected %q, got %q", expectedOutput, string(output))
|
||||
}
|
||||
if ip.IP.String() != "fe80::e2cb:4eff:fef9:6710" {
|
||||
t.Errorf("Mismatch in expected output for status hook. Expected 'fe80::e2cb:4eff:fef9:6710', got '%s'", ip.IP.String())
|
||||
}
|
||||
}
|
||||
27
vendor/k8s.io/kubernetes/pkg/kubelet/network/exec/exec_unix.go
generated
vendored
Normal file
27
vendor/k8s.io/kubernetes/pkg/kubelet/network/exec/exec_unix.go
generated
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// +build !windows
|
||||
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package exec
|
||||
|
||||
import "syscall"
|
||||
|
||||
const X_OK = 0x1
|
||||
|
||||
func isExecutable(path string) bool {
|
||||
return syscall.Access(path, X_OK) == nil
|
||||
}
|
||||
23
vendor/k8s.io/kubernetes/pkg/kubelet/network/exec/exec_unsupported.go
generated
vendored
Normal file
23
vendor/k8s.io/kubernetes/pkg/kubelet/network/exec/exec_unsupported.go
generated
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// +build windows
|
||||
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package exec
|
||||
|
||||
func isExecutable(path string) bool {
|
||||
return false
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue