mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
SetUp/TearDown II: remove code from kuberuntime
This commit is contained in:
parent
706207904e
commit
7c2aeecdd2
@ -641,41 +641,16 @@ func (m *kubeGenericRuntimeManager) SyncPod(pod *api.Pod, _ api.PodStatus, podSt
|
||||
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)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to get pod sandbox status: %v; Skipping pod %q", err, format.Pod(pod))
|
||||
result.Fail(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Overwrite the podIP passed in the pod status, since we just started the infra container.
|
||||
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))
|
||||
podSandboxStatus, err := m.runtimeService.PodSandboxStatus(podSandboxID)
|
||||
if err != nil {
|
||||
glog.Errorf("Failed to get pod sandbox status: %v; Skipping pod %q", err, format.Pod(pod))
|
||||
result.Fail(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Overwrite the podIP passed in the pod status, since we just started the pod sandbox.
|
||||
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))
|
||||
}
|
||||
|
||||
// Get podSandboxConfig for containers to start.
|
||||
@ -815,33 +790,6 @@ func (m *kubeGenericRuntimeManager) killPodWithSyncResult(pod *api.Pod, runningP
|
||||
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
|
||||
killSandboxResult := kubecontainer.NewSyncResult(kubecontainer.KillPodSandbox, runningPod.ID)
|
||||
result.AddSyncResult(killSandboxResult)
|
||||
|
@ -18,13 +18,13 @@ package kuberuntime
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"sort"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
runtimeApi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||
"k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"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.
|
||||
// TODO: remove determinePodSandboxIP after networking is delegated to the container runtime.
|
||||
func (m *kubeGenericRuntimeManager) determinePodSandboxIP(podNamespace, podName string, podSandbox *runtimeApi.PodSandboxStatus) string {
|
||||
ip := ""
|
||||
|
||||
if podSandbox.Network != nil {
|
||||
ip = podSandbox.Network.GetIp()
|
||||
if podSandbox.Network == nil {
|
||||
glog.Warningf("Pod Sandbox status doesn't have network information, cannot report IP")
|
||||
return ""
|
||||
}
|
||||
|
||||
if m.networkPlugin.Name() != network.DefaultPluginName {
|
||||
// TODO: podInfraContainerID in GetPodNetworkStatus() interface should be renamed to sandboxID
|
||||
netStatus, err := m.networkPlugin.GetPodNetworkStatus(podNamespace, podName, kubecontainer.ContainerID{
|
||||
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()
|
||||
}
|
||||
ip := podSandbox.Network.GetIp()
|
||||
if net.ParseIP(ip) == nil {
|
||||
glog.Warningf("Pod Sandbox reported an unparseable IP %v", ip)
|
||||
return ""
|
||||
}
|
||||
|
||||
return ip
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user