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

switch to use ContainerID instead of DockerID in network plugin interface #23940

Merged
merged 1 commit into from
Apr 17, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/kubelet/dockertools/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func (dm *DockerManager) determineContainerIP(podNamespace, podName string, cont
}

if dm.networkPlugin.Name() != network.DefaultPluginName {
netStatus, err := dm.networkPlugin.Status(podNamespace, podName, kubecontainer.DockerID(container.ID))
netStatus, err := dm.networkPlugin.Status(podNamespace, podName, kubecontainer.DockerID(container.ID).ContainerID())
if err != nil {
glog.Errorf("NetworkPlugin %s failed on the status hook for pod '%s' - %v", dm.networkPlugin.Name(), podName, err)
} else if netStatus != nil {
Expand Down Expand Up @@ -1254,7 +1254,7 @@ func (dm *DockerManager) killPodWithSyncResult(pod *api.Pod, runningPod kubecont
if getDockerNetworkMode(ins) != namespaceModeHost {
teardownNetworkResult := kubecontainer.NewSyncResult(kubecontainer.TeardownNetwork, kubecontainer.BuildPodFullName(runningPod.Name, runningPod.Namespace))
result.AddSyncResult(teardownNetworkResult)
if err := dm.networkPlugin.TearDownPod(runningPod.Namespace, runningPod.Name, kubecontainer.DockerID(networkContainer.ID.ID)); err != nil {
if err := dm.networkPlugin.TearDownPod(runningPod.Namespace, runningPod.Name, networkContainer.ID); err != nil {
message := fmt.Sprintf("Failed to teardown network for pod %q using network plugins %q: %v", runningPod.ID, dm.networkPlugin.Name(), err)
teardownNetworkResult.Fail(kubecontainer.ErrTeardownNetwork, message)
glog.Error(message)
Expand Down Expand Up @@ -1822,7 +1822,7 @@ func (dm *DockerManager) SyncPod(pod *api.Pod, _ api.PodStatus, podStatus *kubec
result.AddSyncResult(setupNetworkResult)
if !usesHostNetwork(pod) {
// Call the networking plugin
err = dm.networkPlugin.SetUpPod(pod.Namespace, pod.Name, podInfraContainerID)
err = dm.networkPlugin.SetUpPod(pod.Namespace, pod.Name, podInfraContainerID.ContainerID())
if err != nil {
// TODO: (random-liu) There shouldn't be "Skipping pod" in sync result message
message := fmt.Sprintf("Failed to setup network for pod %q using network plugins %q: %v; Skipping pod", format.Pod(pod), dm.networkPlugin.Name(), err)
Expand Down
16 changes: 8 additions & 8 deletions pkg/kubelet/network/cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ func (plugin *cniNetworkPlugin) Name() string {
return CNIPluginName
}

func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error {
func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.ContainerID) error {
runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
if !ok {
return fmt.Errorf("CNI execution called on non-docker runtime")
}
netns, err := runtime.GetNetNS(id.ContainerID())
netns, err := runtime.GetNetNS(id)
if err != nil {
return err
}

_, err = plugin.defaultNetwork.addToNetwork(name, namespace, id.ContainerID(), netns)
_, err = plugin.defaultNetwork.addToNetwork(name, namespace, id, netns)
if err != nil {
glog.Errorf("Error while adding to cni network: %s", err)
return err
Expand All @@ -121,27 +121,27 @@ func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubec
return err
}

func (plugin *cniNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.DockerID) error {
func (plugin *cniNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.ContainerID) error {
runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
if !ok {
return fmt.Errorf("CNI execution called on non-docker runtime")
}
netns, err := runtime.GetNetNS(id.ContainerID())
netns, err := runtime.GetNetNS(id)
if err != nil {
return err
}

return plugin.defaultNetwork.deleteFromNetwork(name, namespace, id.ContainerID(), netns)
return plugin.defaultNetwork.deleteFromNetwork(name, namespace, id, netns)
}

// TODO: Use the addToNetwork function to obtain the IP of the Pod. That will assume idempotent ADD call to the plugin.
// Also fix the runtime's call to Status function to be done only in the case that the IP is lost, no need to do periodic calls
func (plugin *cniNetworkPlugin) Status(namespace string, name string, id kubecontainer.DockerID) (*network.PodNetworkStatus, error) {
func (plugin *cniNetworkPlugin) Status(namespace string, name string, id kubecontainer.ContainerID) (*network.PodNetworkStatus, error) {
runtime, ok := plugin.host.GetRuntime().(*dockertools.DockerManager)
if !ok {
return nil, fmt.Errorf("CNI execution called on non-docker runtime")
}
ipStr, err := runtime.GetContainerIP(string(id), network.DefaultInterfaceName)
ipStr, err := runtime.GetContainerIP(id.ID, network.DefaultInterfaceName)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/network/cni/cni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func TestCNIPlugin(t *testing.T) {
t.Fatalf("Failed to select the desired plugin: %v", err)
}

err = plug.SetUpPod("podNamespace", "podName", "test_infra_container")
err = plug.SetUpPod("podNamespace", "podName", kubecontainer.ContainerID{"docker", "test_infra_container"})
if err != nil {
t.Errorf("Expected nil: %v", err)
}
Expand All @@ -195,7 +195,7 @@ func TestCNIPlugin(t *testing.T) {
if string(output) != expectedOutput {
t.Errorf("Mismatch in expected output for setup hook. Expected '%s', got '%s'", expectedOutput, string(output))
}
err = plug.TearDownPod("podNamespace", "podName", "test_infra_container")
err = plug.TearDownPod("podNamespace", "podName", kubecontainer.ContainerID{"docker", "test_infra_container"})
if err != nil {
t.Errorf("Expected nil: %v", err)
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/kubelet/network/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,20 @@ func (plugin *execNetworkPlugin) validate() error {
return nil
}

func (plugin *execNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error {
out, err := utilexec.New().Command(plugin.getExecutable(), setUpCmd, namespace, name, string(id)).CombinedOutput()
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()
glog.V(5).Infof("SetUpPod 'exec' network plugin output: %s, %v", string(out), err)
return err
}

func (plugin *execNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.DockerID) error {
out, err := utilexec.New().Command(plugin.getExecutable(), tearDownCmd, namespace, name, string(id)).CombinedOutput()
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()
glog.V(5).Infof("TearDownPod 'exec' network plugin output: %s, %v", string(out), err)
return err
}

func (plugin *execNetworkPlugin) Status(namespace string, name string, id kubecontainer.DockerID) (*network.PodNetworkStatus, error) {
out, err := utilexec.New().Command(plugin.getExecutable(), statusCmd, namespace, name, string(id)).CombinedOutput()
func (plugin *execNetworkPlugin) Status(namespace string, name string, id kubecontainer.ContainerID) (*network.PodNetworkStatus, error) {
out, err := utilexec.New().Command(plugin.getExecutable(), statusCmd, namespace, name, id.ID).CombinedOutput()
glog.V(5).Infof("Status 'exec' network plugin output: %s, %v", string(out), err)
if err != nil {
return nil, err
Expand Down
9 changes: 5 additions & 4 deletions pkg/kubelet/network/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"testing"
"text/template"

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"
Expand Down Expand Up @@ -224,7 +225,7 @@ func TestPluginSetupHook(t *testing.T) {

plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil))

err = plug.SetUpPod("podNamespace", "podName", "dockerid2345")
err = plug.SetUpPod("podNamespace", "podName", kubecontainer.ContainerID{"docker", "dockerid2345"})
if err != nil {
t.Errorf("Expected nil: %v", err)
}
Expand Down Expand Up @@ -252,7 +253,7 @@ func TestPluginTearDownHook(t *testing.T) {

plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil))

err = plug.TearDownPod("podNamespace", "podName", "dockerid2345")
err = plug.TearDownPod("podNamespace", "podName", kubecontainer.ContainerID{"docker", "dockerid2345"})
if err != nil {
t.Errorf("Expected nil")
}
Expand Down Expand Up @@ -280,7 +281,7 @@ func TestPluginStatusHook(t *testing.T) {

plug, err := network.InitNetworkPlugin(ProbeNetworkPlugins(testPluginPath), pluginName, nettest.NewFakeHost(nil))

ip, err := plug.Status("namespace", "name", "dockerid2345")
ip, err := plug.Status("namespace", "name", kubecontainer.ContainerID{"docker", "dockerid2345"})
if err != nil {
t.Errorf("Expected nil got %v", err)
}
Expand Down Expand Up @@ -319,7 +320,7 @@ func TestPluginStatusHookIPv6(t *testing.T) {
t.Errorf("InitNetworkPlugin() failed: %v", err)
}

ip, err := plug.Status("namespace", "name", "dockerid2345")
ip, err := plug.Status("namespace", "name", kubecontainer.ContainerID{"docker", "dockerid2345"})
if err != nil {
t.Errorf("Status() failed: %v", err)
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/kubelet/network/kubenet/kubenet_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ type kubenetNetworkPlugin struct {
cniConfig *libcni.CNIConfig
shaper bandwidth.BandwidthShaper

podCIDRs map[kubecontainer.DockerID]string
podCIDRs map[kubecontainer.ContainerID]string
MTU int
}

func NewPlugin() network.NetworkPlugin {
return &kubenetNetworkPlugin{
podCIDRs: make(map[kubecontainer.DockerID]string),
podCIDRs: make(map[kubecontainer.ContainerID]string),
MTU: 1460,
}
}
Expand Down Expand Up @@ -179,7 +179,7 @@ func (plugin *kubenetNetworkPlugin) Name() string {
return KubenetPluginName
}

func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error {
func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.ContainerID) error {
// Can't set up pods if we don't have a PodCIDR yet
if plugin.netConfig == nil {
return fmt.Errorf("Kubenet needs a PodCIDR to set up pods")
Expand All @@ -189,12 +189,12 @@ func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id k
if !ok {
return fmt.Errorf("Kubenet execution called on non-docker runtime")
}
netnsPath, err := runtime.GetNetNS(id.ContainerID())
netnsPath, err := runtime.GetNetNS(id)
if err != nil {
return err
}

rt := buildCNIRuntimeConf(name, namespace, id.ContainerID(), netnsPath)
rt := buildCNIRuntimeConf(name, namespace, id, netnsPath)
if err != nil {
return fmt.Errorf("Error building CNI config: %v", err)
}
Expand Down Expand Up @@ -223,7 +223,7 @@ func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id k
return nil
}

func (plugin *kubenetNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.DockerID) error {
func (plugin *kubenetNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.ContainerID) error {
if plugin.netConfig == nil {
return fmt.Errorf("Kubenet needs a PodCIDR to tear down pods")
}
Expand All @@ -232,12 +232,12 @@ func (plugin *kubenetNetworkPlugin) TearDownPod(namespace string, name string, i
if !ok {
return fmt.Errorf("Kubenet execution called on non-docker runtime")
}
netnsPath, err := runtime.GetNetNS(id.ContainerID())
netnsPath, err := runtime.GetNetNS(id)
if err != nil {
return err
}

rt := buildCNIRuntimeConf(name, namespace, id.ContainerID(), netnsPath)
rt := buildCNIRuntimeConf(name, namespace, id, netnsPath)
if err != nil {
return fmt.Errorf("Error building CNI config: %v", err)
}
Expand All @@ -263,7 +263,7 @@ func (plugin *kubenetNetworkPlugin) TearDownPod(namespace string, name string, i

// TODO: Use the addToNetwork function to obtain the IP of the Pod. That will assume idempotent ADD call to the plugin.
// Also fix the runtime's call to Status function to be done only in the case that the IP is lost, no need to do periodic calls
func (plugin *kubenetNetworkPlugin) Status(namespace string, name string, id kubecontainer.DockerID) (*network.PodNetworkStatus, error) {
func (plugin *kubenetNetworkPlugin) Status(namespace string, name string, id kubecontainer.ContainerID) (*network.PodNetworkStatus, error) {
cidr, ok := plugin.podCIDRs[id]
if !ok {
return nil, fmt.Errorf("No IP address found for pod %v", id)
Expand Down
6 changes: 3 additions & 3 deletions pkg/kubelet/network/kubenet/kubenet_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func (plugin *kubenetNetworkPlugin) Name() string {
return "kubenet"
}

func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error {
func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.ContainerID) error {
return fmt.Errorf("Kubenet is not supported in this build")
}

func (plugin *kubenetNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.DockerID) error {
func (plugin *kubenetNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.ContainerID) error {
return fmt.Errorf("Kubenet is not supported in this build")
}

func (plugin *kubenetNetworkPlugin) Status(namespace string, name string, id kubecontainer.DockerID) (*network.PodNetworkStatus, error) {
func (plugin *kubenetNetworkPlugin) Status(namespace string, name string, id kubecontainer.ContainerID) (*network.PodNetworkStatus, error) {
return nil, fmt.Errorf("Kubenet is not supported in this build")
}
12 changes: 6 additions & 6 deletions pkg/kubelet/network/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ type NetworkPlugin interface {
// SetUpPod is the method called after the infra container of
// the pod has been created but before the other containers of the
// pod are launched.
SetUpPod(namespace string, name string, podInfraContainerID kubecontainer.DockerID) error
SetUpPod(namespace string, name string, podInfraContainerID kubecontainer.ContainerID) error

// TearDownPod is the method called before a pod's infra container will be deleted
TearDownPod(namespace string, name string, podInfraContainerID kubecontainer.DockerID) error
TearDownPod(namespace string, name string, podInfraContainerID kubecontainer.ContainerID) error

// Status is the method called to obtain the ipv4 or ipv6 addresses of the container
Status(namespace string, name string, podInfraContainerID kubecontainer.DockerID) (*PodNetworkStatus, error)
Status(namespace string, name string, podInfraContainerID kubecontainer.ContainerID) (*PodNetworkStatus, error)
}

// PodNetworkStatus stores the network status of a pod (currently just the primary IP address)
Expand Down Expand Up @@ -180,14 +180,14 @@ func (plugin *NoopNetworkPlugin) Capabilities() utilsets.Int {
return utilsets.NewInt()
}

func (plugin *NoopNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.DockerID) error {
func (plugin *NoopNetworkPlugin) SetUpPod(namespace string, name string, id kubecontainer.ContainerID) error {
return nil
}

func (plugin *NoopNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.DockerID) error {
func (plugin *NoopNetworkPlugin) TearDownPod(namespace string, name string, id kubecontainer.ContainerID) error {
return nil
}

func (plugin *NoopNetworkPlugin) Status(namespace string, name string, id kubecontainer.DockerID) (*PodNetworkStatus, error) {
func (plugin *NoopNetworkPlugin) Status(namespace string, name string, id kubecontainer.ContainerID) (*PodNetworkStatus, error) {
return nil, nil
}