diff --git a/pkg/pod/pod_test.go b/pkg/pod/pod_test.go index 7adcd221960..de292cde6b9 100644 --- a/pkg/pod/pod_test.go +++ b/pkg/pod/pod_test.go @@ -417,7 +417,7 @@ func TestMakePod(t *testing.T) { Requests: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("8"), corev1.ResourceMemory: resource.MustParse("100Gi"), - corev1.ResourceEphemeralStorage: resource.MustParse("0"), + corev1.ResourceEphemeralStorage: zeroQty, }, }, }}, diff --git a/pkg/reconciler/taskrun/taskrun_test.go b/pkg/reconciler/taskrun/taskrun_test.go index 6e75a846f38..b9eaa6cff2f 100644 --- a/pkg/reconciler/taskrun/taskrun_test.go +++ b/pkg/reconciler/taskrun/taskrun_test.go @@ -211,11 +211,6 @@ var ( tb.VolumeMount("workspace", workspaceDir), tb.VolumeMount("tekton-home", "/tekton/home"), tb.VolumeMount("tekton-home", "/builder/home"), - tb.Resources(tb.Requests( - tb.CPU("0"), - tb.Memory("0"), - tb.EphemeralStorage("0"), - )), } actualOps = append(actualOps, ops...) @@ -315,11 +310,6 @@ func TestReconcile_ExplicitDefaultSA(t *testing.T) { tb.VolumeMount("workspace", workspaceDir), tb.VolumeMount("tekton-home", "/tekton/home"), tb.VolumeMount("tekton-home", "/builder/home"), - tb.Resources(tb.Requests( - tb.CPU("0"), - tb.Memory("0"), - tb.EphemeralStorage("0"), - )), ), ), ), @@ -355,11 +345,6 @@ func TestReconcile_ExplicitDefaultSA(t *testing.T) { tb.VolumeMount("workspace", workspaceDir), tb.VolumeMount("tekton-home", "/tekton/home"), tb.VolumeMount("tekton-home", "/builder/home"), - tb.Resources(tb.Requests( - tb.CPU("0"), - tb.Memory("0"), - tb.EphemeralStorage("0"), - )), ), ), ), @@ -578,11 +563,6 @@ func TestReconcile(t *testing.T) { tb.VolumeMount("workspace", workspaceDir), tb.VolumeMount("tekton-home", "/tekton/home"), tb.VolumeMount("tekton-home", "/builder/home"), - tb.Resources(tb.Requests( - tb.CPU("0"), - tb.Memory("0"), - tb.EphemeralStorage("0"), - )), ), ), ), @@ -618,11 +598,6 @@ func TestReconcile(t *testing.T) { tb.VolumeMount("workspace", workspaceDir), tb.VolumeMount("tekton-home", "/tekton/home"), tb.VolumeMount("tekton-home", "/builder/home"), - tb.Resources(tb.Requests( - tb.CPU("0"), - tb.Memory("0"), - tb.EphemeralStorage("0"), - )), ), ), ), @@ -663,11 +638,6 @@ func TestReconcile(t *testing.T) { tb.VolumeMount("workspace", workspaceDir), tb.VolumeMount("tekton-home", "/tekton/home"), tb.VolumeMount("tekton-home", "/builder/home"), - tb.Resources(tb.Requests( - tb.CPU("0"), - tb.Memory("0"), - tb.EphemeralStorage("0"), - )), ), tb.PodContainer("step-mycontainer", "myimage", tb.Command(entrypointLocation), @@ -680,11 +650,6 @@ func TestReconcile(t *testing.T) { tb.VolumeMount("workspace", workspaceDir), tb.VolumeMount("tekton-home", "/tekton/home"), tb.VolumeMount("tekton-home", "/builder/home"), - tb.Resources(tb.Requests( - tb.CPU("0"), - tb.Memory("0"), - tb.EphemeralStorage("0"), - )), ), tb.PodContainer("step-myothercontainer", "myotherimage", tb.Command(entrypointLocation), @@ -696,11 +661,6 @@ func TestReconcile(t *testing.T) { tb.VolumeMount("workspace", workspaceDir), tb.VolumeMount("tekton-home", "/tekton/home"), tb.VolumeMount("tekton-home", "/builder/home"), - tb.Resources(tb.Requests( - tb.CPU("0"), - tb.Memory("0"), - tb.EphemeralStorage("0"), - )), ), tb.PodContainer("step-image-digest-exporter-9l9zj", "override-with-imagedigest-exporter-image:latest", tb.Command(entrypointLocation), @@ -712,11 +672,6 @@ func TestReconcile(t *testing.T) { tb.VolumeMount("workspace", workspaceDir), tb.VolumeMount("tekton-home", "/tekton/home"), tb.VolumeMount("tekton-home", "/builder/home"), - tb.Resources(tb.Requests( - tb.CPU("0"), - tb.Memory("0"), - tb.EphemeralStorage("0"), - )), tb.TerminationMessagePolicy(corev1.TerminationMessageFallbackToLogsOnError), ), ), @@ -758,11 +713,6 @@ func TestReconcile(t *testing.T) { tb.VolumeMount("workspace", workspaceDir), tb.VolumeMount("tekton-home", "/tekton/home"), tb.VolumeMount("tekton-home", "/builder/home"), - tb.Resources(tb.Requests( - tb.CPU("0"), - tb.Memory("0"), - tb.EphemeralStorage("0"), - )), ), tb.PodContainer("step-mycontainer", "myimage", tb.Command(entrypointLocation), @@ -774,11 +724,6 @@ func TestReconcile(t *testing.T) { tb.VolumeMount("workspace", workspaceDir), tb.VolumeMount("tekton-home", "/tekton/home"), tb.VolumeMount("tekton-home", "/builder/home"), - tb.Resources(tb.Requests( - tb.CPU("0"), - tb.Memory("0"), - tb.EphemeralStorage("0"), - )), ), ), ), @@ -813,11 +758,6 @@ func TestReconcile(t *testing.T) { tb.VolumeMount("workspace", workspaceDir), tb.VolumeMount("tekton-home", "/tekton/home"), tb.VolumeMount("tekton-home", "/builder/home"), - tb.Resources(tb.Requests( - tb.CPU("0"), - tb.Memory("0"), - tb.EphemeralStorage("0"), - )), ), ), ), @@ -857,11 +797,6 @@ func TestReconcile(t *testing.T) { tb.VolumeMount("workspace", workspaceDir), tb.VolumeMount("tekton-home", "/tekton/home"), tb.VolumeMount("tekton-home", "/builder/home"), - tb.Resources(tb.Requests( - tb.CPU("0"), - tb.Memory("0"), - tb.EphemeralStorage("0"), - )), ), tb.PodContainer("step-mystep", "ubuntu", tb.Command(entrypointLocation), @@ -872,11 +807,6 @@ func TestReconcile(t *testing.T) { tb.VolumeMount("workspace", workspaceDir), tb.VolumeMount("tekton-home", "/tekton/home"), tb.VolumeMount("tekton-home", "/builder/home"), - tb.Resources(tb.Requests( - tb.CPU("0"), - tb.Memory("0"), - tb.EphemeralStorage("0"), - )), ), ), ), @@ -910,11 +840,6 @@ func TestReconcile(t *testing.T) { tb.VolumeMount("workspace", workspaceDir), tb.VolumeMount("tekton-home", "/tekton/home"), tb.VolumeMount("tekton-home", "/builder/home"), - tb.Resources(tb.Requests( - tb.CPU("0"), - tb.Memory("0"), - tb.EphemeralStorage("0"), - )), ), ), ), diff --git a/test/builder/pod.go b/test/builder/pod.go index 431318ed301..7f73ec8c9c5 100644 --- a/test/builder/pod.go +++ b/test/builder/pod.go @@ -20,6 +20,7 @@ import ( "time" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -118,6 +119,15 @@ func PodContainer(name, image string, ops ...ContainerOp) PodSpecOp { c := &corev1.Container{ Name: name, Image: image, + // By default, containers request zero resources. Ops + // can override this. + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("0"), + corev1.ResourceMemory: resource.MustParse("0"), + corev1.ResourceEphemeralStorage: resource.MustParse("0"), + }, + }, } for _, op := range ops { op(c) diff --git a/test/builder/pod_test.go b/test/builder/pod_test.go index c6e44207088..6e9adfbc3ca 100644 --- a/test/builder/pod_test.go +++ b/test/builder/pod_test.go @@ -35,7 +35,7 @@ func TestPod(t *testing.T) { Name: "tools-volume", VolumeSource: corev1.VolumeSource{}, } - pod := tb.Pod("foo-pod-123456", "foo", + got := tb.Pod("foo-pod-123456", "foo", tb.PodAnnotation("annotation", "annotation-value"), tb.PodLabel("label", "label-value"), tb.PodOwnerReference("TaskRun", "taskrun-foo", @@ -62,7 +62,7 @@ func TestPod(t *testing.T) { tb.PodVolumes(volume), ), ) - expectedPod := &corev1.Pod{ + want := &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Namespace: "foo", Name: "foo-pod-123456", @@ -86,6 +86,13 @@ func TestPod(t *testing.T) { Containers: []corev1.Container{{ Name: "nop", Image: "nop:latest", + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceCPU: resource.MustParse("0"), + corev1.ResourceMemory: resource.MustParse("0"), + corev1.ResourceEphemeralStorage: resource.MustParse("0"), + }, + }, }}, InitContainers: []corev1.Container{{ Name: "basic", @@ -114,7 +121,7 @@ func TestPod(t *testing.T) { Volumes: []corev1.Volume{volume}, }, } - if d := cmp.Diff(expectedPod, pod, resourceQuantityCmp); d != "" { + if d := cmp.Diff(want, got, resourceQuantityCmp); d != "" { t.Fatalf("Pod diff -want, +got: %v", d) } }