From 445529fe5da5c4aa53f4b320fbb50b432543488b Mon Sep 17 00:00:00 2001 From: Austin Zhao Date: Thu, 12 May 2022 01:00:14 +0000 Subject: [PATCH] Support Task-level Resources Requirements on TaskRun: Part #1 Required fields and related webhook validations are added to support a user to configure compute resources for TaskRun which will significantly reduce the over-asked resources amount configured by the Step-level. --- docs/compute-resources.md | 212 +++++++++++++++++- docs/install.md | 1 + docs/taskruns.md | 33 +++ .../pipeline/v1beta1/openapi_generated.go | 16 +- .../pipeline/v1beta1/pipelinerun_types.go | 4 + .../v1beta1/pipelinerun_validation.go | 3 + .../v1beta1/pipelinerun_validation_test.go | 52 ++++- pkg/apis/pipeline/v1beta1/swagger.json | 8 + pkg/apis/pipeline/v1beta1/taskrun_types.go | 2 + .../pipeline/v1beta1/taskrun_validation.go | 15 ++ .../v1beta1/taskrun_validation_test.go | 62 ++++- .../pipeline/v1beta1/zz_generated.deepcopy.go | 10 + 12 files changed, 411 insertions(+), 7 deletions(-) diff --git a/docs/compute-resources.md b/docs/compute-resources.md index 87559ac930c..c88e5d59c05 100644 --- a/docs/compute-resources.md +++ b/docs/compute-resources.md @@ -42,7 +42,9 @@ request will be 6. Since the sidecar container has no CPU limit, this is treated as the highest CPU limit. Therefore, the pod will have no effective CPU limit. -## Task Resource Requirements +## Task-level Compute Resources Configuration + +**([alpha only](https://github.com/tektoncd/pipeline/blob/main/docs/install.md#alpha-features))** Tekton allows users to specify resource requirements of [`Steps`](./tasks.md#defining-steps), which run sequentially. However, the pod's effective resource requirements are still the @@ -52,6 +54,107 @@ requirements for `Step`containers, they must be treated as if they are running i Tekton adjusts `Step` resource requirements to comply with [LimitRanges](#limitrange-support). [ResourceQuotas](#resourcequota-support) are not currently supported. +Instead of specifying resource requirements on each `Step`, users can choose to specify resource requirements at the Task-level. If users specify a Task-level resource request, it will ensure that the kubelet reserves only that amount of resources to execute the `Task`'s `Steps`. +If users specify a Task-level resource limit, no `Step` may use more than that amount of resources. + +Each of these details is explained in more depth below. + +Some points to note: + +- Task-level resource requests and limits do not apply to sidecars which can be configured separately. +- Users may not configure the Task-level and Step-level resource requirements (requests/limits) simultaneously. + +### Configure Task-level Compute Resources + +Task-level resource requirements can be configured in `TaskRun.ComputeResources`, or `PipelineRun.TaskRunSpecs.ComputeResources`. + +e.g. + +```yaml +apiVersion: tekton.dev/v1beta1 +kind: TaskRun +metadata: + name: foo +spec: + computeResources: + requests: + cpu: 1 + limits: + cpu: 2 +``` + +### Specify Task-level Compute Resources in TaskRun/PipelineRun + +Users can specify compute resources either at the Step-level or the Task-level in `TaskRun`. + +To specify compute resources at the Step-level, use `TaskRun.StepOverrides.Resources`. +To specify compute resources at the Task-level, use `TaskRun.ComputeResources` or `PipelineRun.TaskRunSpecs.ComputeResources`. + +e.g. + +Using `TaskRun.Resources`: + +```yaml +kind: TaskRun +spec: + computeResources: + requests: + cpu: 2 +``` + +Rejected when configuring `TaskRun.StepOverrides.Resources` and `TaskRun.ComputeResources`: + +```yaml +kind: TaskRun +spec: + stepOverrides: + - name: foo + resources: + requests: + cpu: 1 + computeResources: + requests: + cpu: 2 +``` + +Rejected when configuring `PipelineRun.TaskRunSpecs.StepOverrides.Resources` and `PipelineRun.TaskRunSpecs.ComputeResources`: + +```yaml +kind: PipelineRun +spec: + taskRunSpecs: + - pipelineTaskName: foo + stepOverrides: + - name: foo + resources: + requests: + cpu: 1 + computeResources: + requests: + cpu: 2 +``` + +### Configure Resource Requirements with Sidecar + +Users can specify compute resources separately for a sidecar while configuring task-level resource requirements on TaskRun. + +e.g. + +```yaml +kind: TaskRun +spec: + sidecarOverrides: + - name: sidecar + resources: + requests: + cpu: 750m + limits: + cpu: 1 + computeResources: + requests: + cpu: 2 +``` + ## LimitRange Support Kubernetes allows users to configure [LimitRanges]((https://kubernetes.io/docs/concepts/policy/limit-range/)), @@ -217,6 +320,113 @@ spec: Here, the minimum of the "max" values is the output "max" value, and likewise for "default" and "defaultRequest". The maximum of the "min" values is the output "min" value. +### Configure Task-level Compute Resources on TaskRun with LimitRange + +**([alpha only](https://github.com/tektoncd/pipeline/blob/main/docs/install.md#alpha-features))** + +User can use `LimitRange` to configure min or max compute resources for a `Task` or `Step`. + +(Note: The Task-level compute resources configuration is an alpha feature at this moment.) + +Here are examples with a task-level resource requirements: + +e.g. + +Applying min: + +```yaml +kind: LimitRange +spec: + limits: + - min: + cpu: 200m +--- +kind: Task +spec: + steps: + - name: step1 # applied with min + - name: step2 # applied with min + - name: step3 # not applied +--- +kind: TaskRun +spec: + computeResources: + requests: + cpu: 1 +``` + +| Step name | CPU request | +| --------- | ----------- | +| step1 | 800m | +| step2 | 200m | +| step3 | N/A | + +Here the 800m on step1 comes from `200m + (1 - 200m * 2)`. + +Applying max: + +```yaml +kind: LimitRange +spec: + limits: + - max: + cpu: 800m +--- +kind: Task +spec: + steps: + - name: step1 # applied with max + - name: step2 # applied with max + - name: step3 # not applied +--- +kind: TaskRun +spec: + computeResources: + requests: + cpu: 1 +``` + +| Step name | CPU request | +| --------- | ----------- | +| step1 | 333m | +| step2 | 333m | +| step3 | 333m | + +Here the 333m comes from `1 / 3` with number rounding to leave decimals out. + +Applying min and max: + +```yaml +kind: LimitRange +spec: + limits: + - min: + cpu: 200m + - max: + cpu: 700m +--- +kind: Task +spec: + steps: + - name: step1 # applied with min and max + - name: step2 # applied with min and max + - name: step3 # not applied +--- +kind: TaskRun +spec: + computeResources: + requests: + cpu: 1 +``` + +| Step name | CPU request | +| --------- | ----------- | +| step1 | 400m | +| step2 | 400m | +| step3 | 200m |   + +Here the 400m comes from the min `200` + the spread out `(1 - 200m * 2) / 3`. + ## ResourceQuota Support Kubernetes allows users to define [ResourceQuotas](https://kubernetes.io/docs/concepts/policy/resource-quotas/), diff --git a/docs/install.md b/docs/install.md index 6acb55a5967..0d5ba2819e0 100644 --- a/docs/install.md +++ b/docs/install.md @@ -427,6 +427,7 @@ Features currently in "alpha" are: | [Step and Sidecar Overrides](./taskruns.md#overriding-task-steps-and-sidecars) | [TEP-0094](https://github.com/tektoncd/community/blob/main/teps/0094-specifying-resource-requirements-at-runtime.md) | | | | [Matrix](./matrix.md) | [TEP-0090](https://github.com/tektoncd/community/blob/main/teps/0090-matrix.md) | | | | [Embedded Statuse](pipelineruns.md#configuring-usage-of-taskrun-and-run-embedded-statuses) | [TEP-0100](https://github.com/tektoncd/community/blob/main/teps/0100-embedded-taskruns-and-runs-status-in-pipelineruns.md) | | | +| [Task-level Resource Requirements](compute-resources.md#task-level-compute-resources-configuration) | [TEP-0104](https://github.com/tektoncd/community/blob/main/teps/0104-tasklevel-resource-requirements.md) | ## Configuring High Availability diff --git a/docs/taskruns.md b/docs/taskruns.md index 5a8d7045327..971be33993a 100644 --- a/docs/taskruns.md +++ b/docs/taskruns.md @@ -324,6 +324,39 @@ Each Step in a Task can specify its resource requirements. See [Defining `Steps`](tasks.md#defining-steps). Resource requirements defined in Steps and Sidecars may be overridden by a TaskRun's StepOverrides and SidecarOverrides. +### Specifying Task-level `ComputeResources` + +**([alpha only](https://github.com/tektoncd/pipeline/blob/main/docs/install.md#alpha-features))** + +Task-level compute resources can be configured in `TaskRun.ComputeResources`, or `PipelineRun.TaskRunSpecs.ComputeResources`. + +e.g. + +```yaml +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: task +spec: + steps: + - name: foo +--- +apiVersion: tekton.dev/v1beta1 +kind: TaskRun +metadata: + name: taskrun +spec: + taskRef: + name: task + computeResources: + requests: + cpu: 1 + limits: + cpu: 2 +``` + +Further details and examples could be found in [Compute Resources in Tekton](https://github.com/tektoncd/pipeline/blob/main/docs/compute-resources.md). + ### Specifying a `Pod` template You can specify a [`Pod` template](podtemplates.md) configuration that will serve as the configuration starting diff --git a/pkg/apis/pipeline/v1beta1/openapi_generated.go b/pkg/apis/pipeline/v1beta1/openapi_generated.go index 294409a481e..48b40fe423c 100644 --- a/pkg/apis/pipeline/v1beta1/openapi_generated.go +++ b/pkg/apis/pipeline/v1beta1/openapi_generated.go @@ -2521,11 +2521,17 @@ func schema_pkg_apis_pipeline_v1beta1_PipelineTaskRunSpec(ref common.ReferenceCa Ref: ref("github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskMetadata"), }, }, + "computeResources": { + SchemaProps: spec.SchemaProps{ + Description: "Compute resources to use for this TaskRun", + Ref: ref("k8s.io/api/core/v1.ResourceRequirements"), + }, + }, }, }, }, Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod.Template", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskMetadata", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunSidecarOverride", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunStepOverride"}, + "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod.Template", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.PipelineTaskMetadata", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunSidecarOverride", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunStepOverride", "k8s.io/api/core/v1.ResourceRequirements"}, } } @@ -4497,11 +4503,17 @@ func schema_pkg_apis_pipeline_v1beta1_TaskRunSpec(ref common.ReferenceCallback) }, }, }, + "computeResources": { + SchemaProps: spec.SchemaProps{ + Description: "Compute resources to use for this TaskRun", + Ref: ref("k8s.io/api/core/v1.ResourceRequirements"), + }, + }, }, }, }, Dependencies: []string{ - "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod.Template", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRef", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunDebug", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunResources", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunSidecarOverride", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunStepOverride", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.WorkspaceBinding", "k8s.io/apimachinery/pkg/apis/meta/v1.Duration"}, + "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod.Template", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.Param", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRef", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunDebug", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunResources", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunSidecarOverride", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskRunStepOverride", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.TaskSpec", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1.WorkspaceBinding", "k8s.io/api/core/v1.ResourceRequirements", "k8s.io/apimachinery/pkg/apis/meta/v1.Duration"}, } } diff --git a/pkg/apis/pipeline/v1beta1/pipelinerun_types.go b/pkg/apis/pipeline/v1beta1/pipelinerun_types.go index 01686eb88bb..a8a7b51c0b4 100644 --- a/pkg/apis/pipeline/v1beta1/pipelinerun_types.go +++ b/pkg/apis/pipeline/v1beta1/pipelinerun_types.go @@ -20,6 +20,7 @@ import ( "context" "time" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" "github.com/tektoncd/pipeline/pkg/apis/config" @@ -563,6 +564,9 @@ type PipelineTaskRunSpec struct { // +optional Metadata *PipelineTaskMetadata `json:"metadata,omitempty"` + + // Compute resources to use for this TaskRun + ComputeResources *corev1.ResourceRequirements `json:"computeResources,omitempty"` } // GetTaskRunSpec returns the task specific spec for a given diff --git a/pkg/apis/pipeline/v1beta1/pipelinerun_validation.go b/pkg/apis/pipeline/v1beta1/pipelinerun_validation.go index 482cda177eb..babfebe94e3 100644 --- a/pkg/apis/pipeline/v1beta1/pipelinerun_validation.go +++ b/pkg/apis/pipeline/v1beta1/pipelinerun_validation.go @@ -195,6 +195,9 @@ func validateTaskRunSpec(ctx context.Context, trs PipelineTaskRunSpec) (errs *ap if trs.SidecarOverrides != nil { errs = errs.Also(validateSidecarOverrides(trs.SidecarOverrides).ViaField("sidecarOverrides")) } + if trs.ComputeResources != nil { + errs = errs.Also(validateTaskRunComputeResources(trs.ComputeResources, trs.StepOverrides)) + } } else { if trs.StepOverrides != nil { errs = errs.Also(apis.ErrDisallowedFields("stepOverrides")) diff --git a/pkg/apis/pipeline/v1beta1/pipelinerun_validation_test.go b/pkg/apis/pipeline/v1beta1/pipelinerun_validation_test.go index 6fc9f58c306..a0267ea6e3e 100644 --- a/pkg/apis/pipeline/v1beta1/pipelinerun_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/pipelinerun_validation_test.go @@ -610,7 +610,32 @@ func TestPipelineRunSpec_Invalidate(t *testing.T) { }, wantErr: apis.ErrMissingField("taskRunSpecs[0].sidecarOverrides[0].name"), withContext: enableAlphaAPIFields, + }, { + name: "invalid both step-level (stepOverrides.resources) and task-level (taskRunSpecs.resources) resource requirements configured", + spec: v1beta1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{Name: "pipeline"}, + TaskRunSpecs: []v1beta1.PipelineTaskRunSpec{ + { + PipelineTaskName: "pipelineTask", + StepOverrides: []v1beta1.TaskRunStepOverride{{ + Name: "stepOverride", + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{corev1.ResourceMemory: corev1resources.MustParse("1Gi")}, + }}, + }, + ComputeResources: &corev1.ResourceRequirements{ + Requests: corev1.ResourceList{corev1.ResourceMemory: corev1resources.MustParse("2Gi")}, + }, + }, + }, + }, + wantErr: apis.ErrMultipleOneOf( + "taskRunSpecs[0].stepOverrides.resources", + "taskRunSpecs[0].taskRunSpecs.computeResources", + ), + withContext: enableAlphaAPIFields, }} + for _, ps := range tests { t.Run(ps.name, func(t *testing.T) { ctx := context.Background() @@ -627,8 +652,9 @@ func TestPipelineRunSpec_Invalidate(t *testing.T) { func TestPipelineRunSpec_Validate(t *testing.T) { tests := []struct { - name string - spec v1beta1.PipelineRunSpec + name string + spec v1beta1.PipelineRunSpec + withContext func(context.Context) context.Context }{{ name: "PipelineRun without pipelineRef", spec: v1beta1.PipelineRunSpec{ @@ -641,10 +667,30 @@ func TestPipelineRunSpec_Validate(t *testing.T) { }}, }, }, + }, { + name: "valid task-level (taskRunSpecs.resources) resource requirements configured", + spec: v1beta1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{Name: "pipeline"}, + TaskRunSpecs: []v1beta1.PipelineTaskRunSpec{{ + PipelineTaskName: "pipelineTask", + StepOverrides: []v1beta1.TaskRunStepOverride{{ + Name: "stepOverride", + }}, + ComputeResources: &corev1.ResourceRequirements{ + Requests: corev1.ResourceList{corev1.ResourceMemory: corev1resources.MustParse("2Gi")}, + }, + }}, + }, + withContext: enableAlphaAPIFields, }} + for _, ps := range tests { t.Run(ps.name, func(t *testing.T) { - if err := ps.spec.Validate(context.Background()); err != nil { + ctx := context.Background() + if ps.withContext != nil { + ctx = ps.withContext(ctx) + } + if err := ps.spec.Validate(ctx); err != nil { t.Error(err) } }) diff --git a/pkg/apis/pipeline/v1beta1/swagger.json b/pkg/apis/pipeline/v1beta1/swagger.json index 7800d55c8d5..c888d3a5289 100644 --- a/pkg/apis/pipeline/v1beta1/swagger.json +++ b/pkg/apis/pipeline/v1beta1/swagger.json @@ -1415,6 +1415,10 @@ "description": "PipelineTaskRunSpec can be used to configure specific specs for a concrete Task", "type": "object", "properties": { + "computeResources": { + "description": "Compute resources to use for this TaskRun", + "$ref": "#/definitions/v1.ResourceRequirements" + }, "metadata": { "$ref": "#/definitions/v1beta1.PipelineTaskMetadata" }, @@ -2454,6 +2458,10 @@ "description": "TaskRunSpec defines the desired state of TaskRun", "type": "object", "properties": { + "computeResources": { + "description": "Compute resources to use for this TaskRun", + "$ref": "#/definitions/v1.ResourceRequirements" + }, "debug": { "$ref": "#/definitions/v1beta1.TaskRunDebug" }, diff --git a/pkg/apis/pipeline/v1beta1/taskrun_types.go b/pkg/apis/pipeline/v1beta1/taskrun_types.go index 03e98bec971..44a0f02b816 100644 --- a/pkg/apis/pipeline/v1beta1/taskrun_types.go +++ b/pkg/apis/pipeline/v1beta1/taskrun_types.go @@ -77,6 +77,8 @@ type TaskRunSpec struct { // +optional // +listType=atomic SidecarOverrides []TaskRunSidecarOverride `json:"sidecarOverrides,omitempty"` + // Compute resources to use for this TaskRun + ComputeResources *corev1.ResourceRequirements `json:"computeResources,omitempty"` } // TaskRunSpecStatus defines the taskrun spec status the user can provide diff --git a/pkg/apis/pipeline/v1beta1/taskrun_validation.go b/pkg/apis/pipeline/v1beta1/taskrun_validation.go index e4fa03228e7..5c7a18a9c24 100644 --- a/pkg/apis/pipeline/v1beta1/taskrun_validation.go +++ b/pkg/apis/pipeline/v1beta1/taskrun_validation.go @@ -23,6 +23,7 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/validate" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/sets" "knative.dev/pkg/apis" ) @@ -66,6 +67,7 @@ func (ts *TaskRunSpec) Validate(ctx context.Context) (errs *apis.FieldError) { if ts.StepOverrides != nil { errs = errs.Also(ValidateEnabledAPIFields(ctx, "stepOverrides", config.AlphaAPIFields).ViaField("stepOverrides")) errs = errs.Also(validateStepOverrides(ts.StepOverrides).ViaField("stepOverrides")) + errs = errs.Also(validateTaskRunComputeResources(ts.ComputeResources, ts.StepOverrides)) } if ts.SidecarOverrides != nil { errs = errs.Also(ValidateEnabledAPIFields(ctx, "sidecarOverrides", config.AlphaAPIFields).ViaField("sidecarOverrides")) @@ -138,6 +140,19 @@ func validateStepOverrides(overrides []TaskRunStepOverride) (errs *apis.FieldErr return errs } +// validateTaskRunComputeResources ensures that compute resources are not configured at both the step level and the task level +func validateTaskRunComputeResources(computeResources *corev1.ResourceRequirements, overrides []TaskRunStepOverride) (errs *apis.FieldError) { + for _, override := range overrides { + if override.Resources.Size() > 0 && computeResources != nil { + return apis.ErrMultipleOneOf( + "stepOverrides.resources", + "taskRunSpecs.computeResources", + ) + } + } + return nil +} + func validateSidecarOverrides(overrides []TaskRunSidecarOverride) (errs *apis.FieldError) { var names []string for i, o := range overrides { diff --git a/pkg/apis/pipeline/v1beta1/taskrun_validation_test.go b/pkg/apis/pipeline/v1beta1/taskrun_validation_test.go index 89bfffe91ed..4fb021e619b 100644 --- a/pkg/apis/pipeline/v1beta1/taskrun_validation_test.go +++ b/pkg/apis/pipeline/v1beta1/taskrun_validation_test.go @@ -515,7 +515,31 @@ func TestTaskRunSpec_Invalidate(t *testing.T) { }, wantErr: apis.ErrMissingField("sidecarOverrides[0].name"), wc: enableAlphaAPIFields, + }, { + name: "invalid both step-level (stepOverrides.resources) and task-level (spec.computeResources) resource requirements", + spec: v1beta1.TaskRunSpec{ + TaskRef: &v1beta1.TaskRef{Name: "task"}, + StepOverrides: []v1beta1.TaskRunStepOverride{{ + Name: "stepOverride", + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceMemory: corev1resources.MustParse("1Gi"), + }, + }, + }}, + ComputeResources: &corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceMemory: corev1resources.MustParse("2Gi"), + }, + }, + }, + wantErr: apis.ErrMultipleOneOf( + "stepOverrides.resources", + "taskRunSpecs.computeResources", + ), + wc: enableAlphaAPIFields, }} + for _, ts := range tests { t.Run(ts.name, func(t *testing.T) { ctx := context.Background() @@ -534,6 +558,7 @@ func TestTaskRunSpec_Validate(t *testing.T) { tests := []struct { name string spec v1beta1.TaskRunSpec + wc func(context.Context) context.Context }{{ name: "taskspec without a taskRef", spec: v1beta1.TaskRunSpec{ @@ -581,10 +606,45 @@ func TestTaskRunSpec_Validate(t *testing.T) { }}, }, }, + }, { + name: "valid task-level (spec.resources) resource requirements", + spec: v1beta1.TaskRunSpec{ + TaskRef: &v1beta1.TaskRef{Name: "task"}, + ComputeResources: &corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceMemory: corev1resources.MustParse("2Gi"), + }, + }, + }, + wc: enableAlphaAPIFields, + }, { + name: "valid sidecar and task-level (spec.resources) resource requirements", + spec: v1beta1.TaskRunSpec{ + TaskRef: &v1beta1.TaskRef{Name: "task"}, + ComputeResources: &corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceMemory: corev1resources.MustParse("2Gi"), + }, + }, + SidecarOverrides: []v1beta1.TaskRunSidecarOverride{{ + Name: "sidecar", + Resources: corev1.ResourceRequirements{ + Requests: corev1.ResourceList{ + corev1.ResourceMemory: corev1resources.MustParse("4Gi"), + }, + }, + }}, + }, + wc: enableAlphaAPIFields, }} + for _, ts := range tests { t.Run(ts.name, func(t *testing.T) { - if err := ts.spec.Validate(context.Background()); err != nil { + ctx := context.Background() + if ts.wc != nil { + ctx = ts.wc(ctx) + } + if err := ts.spec.Validate(ctx); err != nil { t.Error(err) } }) diff --git a/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go b/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go index 89846e1d64c..a47edecacaf 100644 --- a/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/pipeline/v1beta1/zz_generated.deepcopy.go @@ -1062,6 +1062,11 @@ func (in *PipelineTaskRunSpec) DeepCopyInto(out *PipelineTaskRunSpec) { *out = new(PipelineTaskMetadata) (*in).DeepCopyInto(*out) } + if in.ComputeResources != nil { + in, out := &in.ComputeResources, &out.ComputeResources + *out = new(v1.ResourceRequirements) + (*in).DeepCopyInto(*out) + } return } @@ -1899,6 +1904,11 @@ func (in *TaskRunSpec) DeepCopyInto(out *TaskRunSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.ComputeResources != nil { + in, out := &in.ComputeResources, &out.ComputeResources + *out = new(v1.ResourceRequirements) + (*in).DeepCopyInto(*out) + } return }