// makeAndSetFakePod is a helper function to create and set one fake sandbox for a pod and
// one fake container for each of its container.
func makeAndSetFakePod(t *testing.T, m *kubeGenericRuntimeManager, fakeRuntime *apitest.FakeRuntimeService,
	pod *v1.Pod) (*apitest.FakePodSandbox, []*apitest.FakeContainer) {
	sandbox := makeFakePodSandbox(t, m, sandboxTemplate{
		pod:       pod,
		createdAt: fakeCreatedAt,
		state:     runtimeApi.PodSandboxState_SANDBOX_READY,
	})

	var containers []*apitest.FakeContainer
	newTemplate := func(c *v1.Container) containerTemplate {
		return containerTemplate{
			pod:       pod,
			container: c,
			createdAt: fakeCreatedAt,
			state:     runtimeApi.ContainerState_CONTAINER_RUNNING,
		}
	}
	for i := range pod.Spec.Containers {
		containers = append(containers, makeFakeContainer(t, m, newTemplate(&pod.Spec.Containers[i])))
	}
	for i := range pod.Spec.InitContainers {
		containers = append(containers, makeFakeContainer(t, m, newTemplate(&pod.Spec.InitContainers[i])))
	}

	fakeRuntime.SetFakeSandboxes([]*apitest.FakePodSandbox{sandbox})
	fakeRuntime.SetFakeContainers(containers)
	return sandbox, containers
}
Пример #2
0
func makeAndSetFakeEvictablePod(m *kubeGenericRuntimeManager, fakeRuntime *apitest.FakeRuntimeService, pods []*apiPodWithCreatedAt) error {
	sandboxes := make([]*apitest.FakePodSandbox, 0)
	containers := make([]*apitest.FakeContainer, 0)
	for _, pod := range pods {
		fakePodSandbox, err := makeFakePodSandbox(m, pod.apiPod, pod.createdAt)
		if err != nil {
			return err
		}

		fakeContainers, err := makeFakeContainers(m, pod.apiPod, pod.apiPod.Spec.Containers, pod.createdAt, runtimeApi.ContainerState_EXITED)
		if err != nil {
			return err
		}

		// Set sandbox to not ready state
		sandboxNotReady := runtimeApi.PodSandBoxState_NOTREADY
		fakePodSandbox.State = &sandboxNotReady
		sandboxes = append(sandboxes, fakePodSandbox)

		// Set containers to exited state
		containerExited := runtimeApi.ContainerState_EXITED
		for _, c := range fakeContainers {
			c.State = &containerExited
			containers = append(containers, c)
		}

	}

	fakeRuntime.SetFakeSandboxes(sandboxes)
	fakeRuntime.SetFakeContainers(containers)
	return nil
}
func makeAndSetFakePod(m *kubeGenericRuntimeManager, fakeRuntime *apitest.FakeRuntimeService, pod *api.Pod) (*apitest.FakePodSandbox, []*apitest.FakeContainer, error) {
	fakePodSandbox, err := makeFakePodSandbox(m, pod)
	if err != nil {
		return nil, nil, err
	}

	fakeContainers, err := makeFakeContainers(m, pod, pod.Spec.Containers)
	if err != nil {
		return nil, nil, err
	}

	fakeRuntime.SetFakeSandboxes([]*apitest.FakePodSandbox{fakePodSandbox})
	fakeRuntime.SetFakeContainers(fakeContainers)
	return fakePodSandbox, fakeContainers, nil
}
Пример #4
0
func makeAndSetFakePod(m *kubeGenericRuntimeManager, fakeRuntime *apitest.FakeRuntimeService, pod *api.Pod) (*apitest.FakePodSandbox, []*apitest.FakeContainer, error) {
	fakePodSandbox, err := makeFakePodSandbox(m, pod, fakeCreatedAt)
	if err != nil {
		return nil, nil, err
	}

	fakeContainers, err := makeFakeContainers(m, pod, pod.Spec.Containers, fakeCreatedAt, runtimeApi.ContainerState_RUNNING)
	if err != nil {
		return nil, nil, err
	}

	fakeInitContainers, err := makeFakeContainers(m, pod, pod.Spec.InitContainers, fakeCreatedAt, runtimeApi.ContainerState_EXITED)
	if err != nil {
		return nil, nil, err
	}

	fakeContainers = append(fakeContainers, fakeInitContainers...)
	fakeRuntime.SetFakeSandboxes([]*apitest.FakePodSandbox{fakePodSandbox})
	fakeRuntime.SetFakeContainers(fakeContainers)
	return fakePodSandbox, fakeContainers, nil
}