mirror of https://github.com/k3s-io/k3s
kubelet: Remove GetRecentDockerContainersWithNameAndUUID().
Always call GetPodStatus().pull/6/head
parent
6103b144e0
commit
ddf323ee00
|
@ -1030,9 +1030,8 @@ func (kl *Kubelet) shouldContainerBeRestarted(container *api.Container, pod *api
|
|||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return true
|
||||
}
|
||||
|
||||
// Finds an infra container for a pod given by podFullName and UID in dockerContainers. If there is an infra container
|
||||
|
@ -1112,13 +1111,6 @@ func (kl *Kubelet) computePodContainerChanges(pod *api.Pod, runningPod kubeconta
|
|||
containersToStart := make(map[int]empty)
|
||||
containersToKeep := make(map[dockertools.DockerID]int)
|
||||
createPodInfraContainer := false
|
||||
var podStatus api.PodStatus
|
||||
|
||||
podStatus, err := kl.GetPodStatus(podFullName)
|
||||
if err != nil {
|
||||
glog.Errorf("Unable to get pod with name %q and uid %q info with error(%v)", podFullName, uid, err)
|
||||
return podContainerChangesSpec{}, nil
|
||||
}
|
||||
|
||||
var podInfraContainerID dockertools.DockerID
|
||||
podInfraContainer := runningPod.FindContainerByName(dockertools.PodInfraContainerName)
|
||||
|
@ -1132,6 +1124,12 @@ func (kl *Kubelet) computePodContainerChanges(pod *api.Pod, runningPod kubeconta
|
|||
createPodInfraContainer = true
|
||||
}
|
||||
|
||||
podStatus, err := kl.GetPodStatus(podFullName)
|
||||
if err != nil {
|
||||
glog.Errorf("Unable to get pod with name %q and uid %q info with error(%v)", podFullName, uid, err)
|
||||
return podContainerChangesSpec{}, err
|
||||
}
|
||||
|
||||
for index, container := range pod.Spec.Containers {
|
||||
expectedHash := dockertools.HashContainer(&container)
|
||||
|
||||
|
|
|
@ -512,7 +512,7 @@ func TestSyncPodsWithTerminationLog(t *testing.T) {
|
|||
}
|
||||
waitGroup.Wait()
|
||||
verifyCalls(t, fakeDocker, []string{
|
||||
"list", "list", "create", "start", "inspect_container", "create", "start", "list", "inspect_container", "inspect_container"})
|
||||
"list", "list", "list", "create", "start", "inspect_container", "create", "start", "list", "inspect_container", "inspect_container"})
|
||||
|
||||
fakeDocker.Lock()
|
||||
parts := strings.Split(fakeDocker.Container.HostConfig.Binds[0], ":")
|
||||
|
@ -564,7 +564,7 @@ func TestSyncPodsCreatesNetAndContainer(t *testing.T) {
|
|||
waitGroup.Wait()
|
||||
|
||||
verifyCalls(t, fakeDocker, []string{
|
||||
"list", "list", "create", "start", "inspect_container", "create", "start", "list", "inspect_container", "inspect_container"})
|
||||
"list", "list", "list", "create", "start", "inspect_container", "create", "start", "list", "inspect_container", "inspect_container"})
|
||||
|
||||
fakeDocker.Lock()
|
||||
|
||||
|
@ -619,7 +619,7 @@ func TestSyncPodsCreatesNetAndContainerPullsImage(t *testing.T) {
|
|||
waitGroup.Wait()
|
||||
|
||||
verifyCalls(t, fakeDocker, []string{
|
||||
"list", "list", "create", "start", "inspect_container", "create", "start", "list", "inspect_container", "inspect_container"})
|
||||
"list", "list", "list", "create", "start", "inspect_container", "create", "start", "list", "inspect_container", "inspect_container"})
|
||||
|
||||
fakeDocker.Lock()
|
||||
|
||||
|
@ -801,7 +801,13 @@ func TestSyncPodsDeletesWithNoPodInfraContainer(t *testing.T) {
|
|||
waitGroup.Wait()
|
||||
|
||||
verifyUnorderedCalls(t, fakeDocker, []string{
|
||||
"list", "list", "list", "list", "inspect_container", "inspect_container", "list", "inspect_container", "inspect_container", "stop", "create", "start", "inspect_container", "create", "start", "list", "inspect_container", "inspect_container"})
|
||||
"list",
|
||||
// foo1
|
||||
"list", "list", "inspect_container", "stop", "create", "start", "inspect_container", "create", "start", "list", "inspect_container", "inspect_container",
|
||||
|
||||
// foo2
|
||||
"list", "list", "inspect_container", "inspect_container", "list", "inspect_container", "inspect_container",
|
||||
})
|
||||
|
||||
// A map iteration is used to delete containers, so must not depend on
|
||||
// order here.
|
||||
|
@ -1649,8 +1655,8 @@ func TestSyncPodsWithPullPolicy(t *testing.T) {
|
|||
puller.HasImages = []string{"existing_one", "want:latest"}
|
||||
kubelet.podInfraContainerImage = "custom_image_name"
|
||||
fakeDocker.ContainerList = []docker.APIContainers{}
|
||||
waitGroup.Add(1)
|
||||
err := kubelet.SyncPods([]api.Pod{
|
||||
|
||||
pods := []api.Pod{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
UID: "12345678",
|
||||
|
@ -1667,7 +1673,10 @@ func TestSyncPodsWithPullPolicy(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}, emptyPodUIDs, map[string]api.Pod{}, time.Now())
|
||||
}
|
||||
kubelet.podManager.SetPods(pods)
|
||||
waitGroup.Add(1)
|
||||
err := kubelet.SyncPods(pods, emptyPodUIDs, map[string]api.Pod{}, time.Now())
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
@ -3442,6 +3451,7 @@ func TestHostNetworkAllowed(t *testing.T) {
|
|||
HostNetwork: true,
|
||||
},
|
||||
}
|
||||
kubelet.podManager.SetPods([]api.Pod{*pod})
|
||||
err := kubelet.syncPod(pod, nil, container.Pod{})
|
||||
if err != nil {
|
||||
t.Errorf("expected pod infra creation to succeed: %v", err)
|
||||
|
|
|
@ -74,6 +74,9 @@ func (d *testDocker) InspectContainer(id string) (*docker.Container, error) {
|
|||
func TestRunOnce(t *testing.T) {
|
||||
cadvisor := &cadvisor.Mock{}
|
||||
cadvisor.On("MachineInfo").Return(&cadvisorApi.MachineInfo{}, nil)
|
||||
|
||||
podManager, _ := newFakePodManager()
|
||||
|
||||
kb := &Kubelet{
|
||||
rootDirectory: "/tmp/kubelet",
|
||||
recorder: &record.FakeRecorder{},
|
||||
|
@ -82,6 +85,7 @@ func TestRunOnce(t *testing.T) {
|
|||
statusManager: newStatusManager(nil),
|
||||
containerRefManager: kubecontainer.NewRefManager(),
|
||||
readinessManager: kubecontainer.NewReadinessManager(),
|
||||
podManager: podManager,
|
||||
}
|
||||
|
||||
kb.networkPlugin, _ = network.InitNetworkPlugin([]network.NetworkPlugin{}, "", network.NewFakeHost(nil))
|
||||
|
@ -142,7 +146,8 @@ func TestRunOnce(t *testing.T) {
|
|||
}
|
||||
kb.dockerPuller = &dockertools.FakeDockerPuller{}
|
||||
kb.containerManager = dockertools.NewDockerManager(kb.dockerClient, kb.recorder)
|
||||
results, err := kb.runOnce([]api.Pod{
|
||||
|
||||
pods := []api.Pod{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
UID: "12345678",
|
||||
|
@ -155,7 +160,9 @@ func TestRunOnce(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}, time.Millisecond)
|
||||
}
|
||||
podManager.SetPods(pods)
|
||||
results, err := kb.runOnce(pods, time.Millisecond)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue