diff --git a/pkg/kubelet/dockertools/manager.go b/pkg/kubelet/dockertools/manager.go index cb555102fcb..076e6091f13 100644 --- a/pkg/kubelet/dockertools/manager.go +++ b/pkg/kubelet/dockertools/manager.go @@ -325,7 +325,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 { @@ -1292,7 +1292,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) @@ -1919,7 +1919,7 @@ func (dm *DockerManager) SyncPod(pod *api.Pod, _ api.PodStatus, podStatus *kubec result.AddSyncResult(setupNetworkResult) if !kubecontainer.IsHostNetworkPod(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) diff --git a/pkg/kubelet/network/cni/cni.go b/pkg/kubelet/network/cni/cni.go index 03edbbaf6eb..daa9c8bf8fe 100644 --- a/pkg/kubelet/network/cni/cni.go +++ b/pkg/kubelet/network/cni/cni.go @@ -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 @@ -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 } diff --git a/pkg/kubelet/network/cni/cni_test.go b/pkg/kubelet/network/cni/cni_test.go index dbf237d46ea..5e807916d8d 100644 --- a/pkg/kubelet/network/cni/cni_test.go +++ b/pkg/kubelet/network/cni/cni_test.go @@ -179,7 +179,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) } @@ -194,7 +194,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) } diff --git a/pkg/kubelet/network/exec/exec.go b/pkg/kubelet/network/exec/exec.go index 24e8478400a..776cfd99377 100644 --- a/pkg/kubelet/network/exec/exec.go +++ b/pkg/kubelet/network/exec/exec.go @@ -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 diff --git a/pkg/kubelet/network/exec/exec_test.go b/pkg/kubelet/network/exec/exec_test.go index d96f06bd807..314a6b9d683 100644 --- a/pkg/kubelet/network/exec/exec_test.go +++ b/pkg/kubelet/network/exec/exec_test.go @@ -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" @@ -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) } @@ -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") } @@ -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) } @@ -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) } diff --git a/pkg/kubelet/network/kubenet/kubenet_linux.go b/pkg/kubelet/network/kubenet/kubenet_linux.go index c73c543e7fc..da39e99109c 100644 --- a/pkg/kubelet/network/kubenet/kubenet_linux.go +++ b/pkg/kubelet/network/kubenet/kubenet_linux.go @@ -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, } } @@ -180,7 +180,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") @@ -190,12 +190,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) } @@ -225,7 +225,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") } @@ -234,12 +234,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) } @@ -266,7 +266,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) diff --git a/pkg/kubelet/network/kubenet/kubenet_unsupported.go b/pkg/kubelet/network/kubenet/kubenet_unsupported.go index 05ef445e076..04f534730a1 100644 --- a/pkg/kubelet/network/kubenet/kubenet_unsupported.go +++ b/pkg/kubelet/network/kubenet/kubenet_unsupported.go @@ -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") } diff --git a/pkg/kubelet/network/plugins.go b/pkg/kubelet/network/plugins.go index 64cfd03c1a3..6198098fd1e 100644 --- a/pkg/kubelet/network/plugins.go +++ b/pkg/kubelet/network/plugins.go @@ -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) @@ -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 }