Skip to content

Commit

Permalink
Set default resource requests in Pod test builder
Browse files Browse the repository at this point in the history
This avoids needless duplication and takes advantage of the test builder
paradigm
  • Loading branch information
imjasonh authored and tekton-robot committed Dec 3, 2019
1 parent 4f2bb9d commit c493a4c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 79 deletions.
2 changes: 1 addition & 1 deletion pkg/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}},
Expand Down
75 changes: 0 additions & 75 deletions pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down Expand Up @@ -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"),
)),
),
),
),
Expand Down Expand Up @@ -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"),
)),
),
),
),
Expand Down Expand Up @@ -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"),
)),
),
),
),
Expand Down Expand Up @@ -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"),
)),
),
),
),
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
),
),
Expand Down Expand Up @@ -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),
Expand All @@ -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"),
)),
),
),
),
Expand Down Expand Up @@ -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"),
)),
),
),
),
Expand Down Expand Up @@ -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),
Expand All @@ -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"),
)),
),
),
),
Expand Down Expand Up @@ -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"),
)),
),
),
),
Expand Down
10 changes: 10 additions & 0 deletions test/builder/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions test/builder/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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)
}
}

0 comments on commit c493a4c

Please sign in to comment.