func (m *kubeGenericRuntimeManager) SyncPod(pod *v1.Pod, _ v1.PodStatus, podStatus *kubecontainer.PodStatus, pullSecrets []v1.Secret, backOff *flowcontrol.Backoff) (result kubecontainer.PodSyncResult) {
// 1. 計算pod actions,見上文
podContainerChanges := m.computePodActions(pod, podStatus)
.....
// 2. 需要情況下執行kill pod
if podContainerChanges.KillPod {
....
killResult := m.killPodWithSyncResult(pod, kubecontainer.ConvertPodStatusToRunningPod(m.runtimeName, podStatus), nil)
....
} else {
// 3. 不需要kill pod,但需要kill工作container
for containerID, containerInfo := range podContainerChanges.ContainersToKill {
....
if err := m.killContainer(pod, containerID, containerInfo.name, containerInfo.message, nil); err != nil {
...
return
}
}
}
.....
// 4. 按需創建sandbox
podSandboxID := podContainerChanges.SandboxID
if podContainerChanges.CreateSandbox {
.....
podSandboxID, msg, err = m.createPodSandbox(pod, podContainerChanges.Attempt)
....
}
....
// 5. 運行next init container
if container := podContainerChanges.NextInitContainerToStart; container != nil {
....
if msg, err := m.startContainer(podSandboxID, podSandboxConfig, container, pod, podStatus, pullSecrets, podIP); err != nil {
startContainerResult.Fail(err, msg)
utilruntime.HandleError(fmt.Errorf( "init container start failed: %v: %s" , err, msg))
return
}
....
}
// 6. 運行工作containers。注意,根據computePodActions,若NextInitContainerToStart不為空,則不存在ContainersToStart ,即這個循環在當前這個SyncPod中不會被執行
for _, idx := range podContainerChanges.ContainersToStart {
....
if msg, err := m.startContainer(podSandboxID, podSandboxConfig, container, pod, podStatus, pullSecrets, podIP); err != nil {
startContainerResult.Fail(err, msg)
// known errors that are logged in other places are logged at higher levels here to avoid
// repetitive log spam
switch {
case err == images.ErrImagePullBackOff:
glog.V( 3 ).Infof( "container start failed: %v: %s" , err, msg)
default :
utilruntime.HandleError(fmt.Errorf( "container start failed: %v: %s" , err, msg))
}
continue
}
}
return
}
|