SetUp/TearDown II: remove code from kuberuntime
This commit is contained in:
		@@ -641,30 +641,6 @@ func (m *kubeGenericRuntimeManager) SyncPod(pod *api.Pod, _ api.PodStatus, podSt
 | 
				
			|||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		setupNetworkResult := kubecontainer.NewSyncResult(kubecontainer.SetupNetwork, podSandboxID)
 | 
					 | 
				
			||||||
		result.AddSyncResult(setupNetworkResult)
 | 
					 | 
				
			||||||
		if !kubecontainer.IsHostNetworkPod(pod) {
 | 
					 | 
				
			||||||
			glog.V(3).Infof("Calling network plugin %s to setup pod for %s", m.networkPlugin.Name(), format.Pod(pod))
 | 
					 | 
				
			||||||
			// Setup pod network plugin with sandbox id
 | 
					 | 
				
			||||||
			// TODO: rename the last param to sandboxID
 | 
					 | 
				
			||||||
			err = m.networkPlugin.SetUpPod(pod.Namespace, pod.Name, kubecontainer.ContainerID{
 | 
					 | 
				
			||||||
				Type: m.runtimeName,
 | 
					 | 
				
			||||||
				ID:   podSandboxID,
 | 
					 | 
				
			||||||
			})
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				message := fmt.Sprintf("Failed to setup network for pod %q using network plugins %q: %v", format.Pod(pod), m.networkPlugin.Name(), err)
 | 
					 | 
				
			||||||
				setupNetworkResult.Fail(kubecontainer.ErrSetupNetwork, message)
 | 
					 | 
				
			||||||
				glog.Error(message)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				killPodSandboxResult := kubecontainer.NewSyncResult(kubecontainer.KillPodSandbox, format.Pod(pod))
 | 
					 | 
				
			||||||
				result.AddSyncResult(killPodSandboxResult)
 | 
					 | 
				
			||||||
				if err := m.runtimeService.StopPodSandbox(podSandboxID); err != nil {
 | 
					 | 
				
			||||||
					killPodSandboxResult.Fail(kubecontainer.ErrKillPodSandbox, err.Error())
 | 
					 | 
				
			||||||
					glog.Errorf("Kill sandbox %q failed for pod %q: %v", podSandboxID, format.Pod(pod), err)
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				return
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		podSandboxStatus, err := m.runtimeService.PodSandboxStatus(podSandboxID)
 | 
							podSandboxStatus, err := m.runtimeService.PodSandboxStatus(podSandboxID)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			glog.Errorf("Failed to get pod sandbox status: %v; Skipping pod %q", err, format.Pod(pod))
 | 
								glog.Errorf("Failed to get pod sandbox status: %v; Skipping pod %q", err, format.Pod(pod))
 | 
				
			||||||
@@ -672,11 +648,10 @@ func (m *kubeGenericRuntimeManager) SyncPod(pod *api.Pod, _ api.PodStatus, podSt
 | 
				
			|||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// Overwrite the podIP passed in the pod status, since we just started the infra container.
 | 
							// Overwrite the podIP passed in the pod status, since we just started the pod sandbox.
 | 
				
			||||||
		podIP = m.determinePodSandboxIP(pod.Namespace, pod.Name, podSandboxStatus)
 | 
							podIP = m.determinePodSandboxIP(pod.Namespace, pod.Name, podSandboxStatus)
 | 
				
			||||||
		glog.V(4).Infof("Determined the ip %q for pod %q after sandbox changed", podIP, format.Pod(pod))
 | 
							glog.V(4).Infof("Determined the ip %q for pod %q after sandbox changed", podIP, format.Pod(pod))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get podSandboxConfig for containers to start.
 | 
						// Get podSandboxConfig for containers to start.
 | 
				
			||||||
	configPodSandboxResult := kubecontainer.NewSyncResult(kubecontainer.ConfigPodSandbox, podSandboxID)
 | 
						configPodSandboxResult := kubecontainer.NewSyncResult(kubecontainer.ConfigPodSandbox, podSandboxID)
 | 
				
			||||||
@@ -815,33 +790,6 @@ func (m *kubeGenericRuntimeManager) killPodWithSyncResult(pod *api.Pod, runningP
 | 
				
			|||||||
		result.AddSyncResult(containerResult)
 | 
							result.AddSyncResult(containerResult)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Teardown network plugin
 | 
					 | 
				
			||||||
	if len(runningPod.Sandboxes) == 0 {
 | 
					 | 
				
			||||||
		glog.V(4).Infof("Can not find pod sandbox by UID %q, assuming already removed.", runningPod.ID)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	sandboxID := runningPod.Sandboxes[0].ID.ID
 | 
					 | 
				
			||||||
	isHostNetwork, err := m.isHostNetwork(sandboxID, pod)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		result.Fail(err)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if !isHostNetwork {
 | 
					 | 
				
			||||||
		teardownNetworkResult := kubecontainer.NewSyncResult(kubecontainer.TeardownNetwork, runningPod.ID)
 | 
					 | 
				
			||||||
		result.AddSyncResult(teardownNetworkResult)
 | 
					 | 
				
			||||||
		// Tear down network plugin with sandbox id
 | 
					 | 
				
			||||||
		if err := m.networkPlugin.TearDownPod(runningPod.Namespace, runningPod.Name, kubecontainer.ContainerID{
 | 
					 | 
				
			||||||
			Type: m.runtimeName,
 | 
					 | 
				
			||||||
			ID:   sandboxID,
 | 
					 | 
				
			||||||
		}); err != nil {
 | 
					 | 
				
			||||||
			message := fmt.Sprintf("Failed to teardown network for pod %s_%s(%s) using network plugins %q: %v",
 | 
					 | 
				
			||||||
				runningPod.Name, runningPod.Namespace, runningPod.ID, m.networkPlugin.Name(), err)
 | 
					 | 
				
			||||||
			teardownNetworkResult.Fail(kubecontainer.ErrTeardownNetwork, message)
 | 
					 | 
				
			||||||
			glog.Error(message)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// stop sandbox, the sandbox will be removed in GarbageCollect
 | 
						// stop sandbox, the sandbox will be removed in GarbageCollect
 | 
				
			||||||
	killSandboxResult := kubecontainer.NewSyncResult(kubecontainer.KillPodSandbox, runningPod.ID)
 | 
						killSandboxResult := kubecontainer.NewSyncResult(kubecontainer.KillPodSandbox, runningPod.ID)
 | 
				
			||||||
	result.AddSyncResult(killSandboxResult)
 | 
						result.AddSyncResult(killSandboxResult)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,13 +18,13 @@ package kuberuntime
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
 | 
						"net"
 | 
				
			||||||
	"sort"
 | 
						"sort"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/golang/glog"
 | 
						"github.com/golang/glog"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/api"
 | 
						"k8s.io/kubernetes/pkg/api"
 | 
				
			||||||
	runtimeApi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
 | 
						runtimeApi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
 | 
				
			||||||
	kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
 | 
						kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/kubelet/network"
 | 
					 | 
				
			||||||
	"k8s.io/kubernetes/pkg/kubelet/types"
 | 
						"k8s.io/kubernetes/pkg/kubelet/types"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/kubelet/util/format"
 | 
						"k8s.io/kubernetes/pkg/kubelet/util/format"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -180,27 +180,16 @@ func (m *kubeGenericRuntimeManager) getKubeletSandboxes(all bool) ([]*runtimeApi
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// determinePodSandboxIP determines the IP address of the given pod sandbox.
 | 
					// determinePodSandboxIP determines the IP address of the given pod sandbox.
 | 
				
			||||||
// TODO: remove determinePodSandboxIP after networking is delegated to the container runtime.
 | 
					 | 
				
			||||||
func (m *kubeGenericRuntimeManager) determinePodSandboxIP(podNamespace, podName string, podSandbox *runtimeApi.PodSandboxStatus) string {
 | 
					func (m *kubeGenericRuntimeManager) determinePodSandboxIP(podNamespace, podName string, podSandbox *runtimeApi.PodSandboxStatus) string {
 | 
				
			||||||
	ip := ""
 | 
						if podSandbox.Network == nil {
 | 
				
			||||||
 | 
							glog.Warningf("Pod Sandbox status doesn't have network information, cannot report IP")
 | 
				
			||||||
	if podSandbox.Network != nil {
 | 
							return ""
 | 
				
			||||||
		ip = podSandbox.Network.GetIp()
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						ip := podSandbox.Network.GetIp()
 | 
				
			||||||
	if m.networkPlugin.Name() != network.DefaultPluginName {
 | 
						if net.ParseIP(ip) == nil {
 | 
				
			||||||
		// TODO: podInfraContainerID in GetPodNetworkStatus() interface should be renamed to sandboxID
 | 
							glog.Warningf("Pod Sandbox reported an unparseable IP %v", ip)
 | 
				
			||||||
		netStatus, err := m.networkPlugin.GetPodNetworkStatus(podNamespace, podName, kubecontainer.ContainerID{
 | 
							return ""
 | 
				
			||||||
			Type: m.runtimeName,
 | 
					 | 
				
			||||||
			ID:   podSandbox.GetId(),
 | 
					 | 
				
			||||||
		})
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			glog.Errorf("NetworkPlugin %s failed on the status hook for pod '%s' - %v", m.networkPlugin.Name(), kubecontainer.BuildPodFullName(podName, podNamespace), err)
 | 
					 | 
				
			||||||
		} else if netStatus != nil {
 | 
					 | 
				
			||||||
			ip = netStatus.IP.String()
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return ip
 | 
						return ip
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user