diff --git a/config/config-defaults.yaml b/config/config-defaults.yaml index 0526a4a967b..a254c510cc2 100644 --- a/config/config-defaults.yaml +++ b/config/config-defaults.yaml @@ -86,3 +86,56 @@ data: # default-resolver-type contains the default resolver type to be used in the cluster, # no default-resolver-type is specified by default default-resolver-type: + + # default-container-resource-requirements allow users to update default resource requirements + # to a init-containers and containers of a pods create by the controller + # Onet: All the resource requirements are applied to init-containers and containers + # only if the existing resource requirements are empty. + # default-container-resource-requirements: | + # place-scripts: # updates resource requirements of a 'place-scripts' container + # requests: + # memory: "64Mi" + # cpu: "250m" + # limits: + # memory: "128Mi" + # cpu: "500m" + # + # prepare: # updates resource requirements of a 'prepare' container + # requests: + # memory: "64Mi" + # cpu: "250m" + # limits: + # memory: "256Mi" + # cpu: "500m" + # + # working-dir-initializer: # updates resource requirements of a 'working-dir-initializer' container + # requests: + # memory: "64Mi" + # cpu: "250m" + # limits: + # memory: "512Mi" + # cpu: "500m" + # + # prefix-scripts: # updates resource requirements of containers which starts with 'scripts-' + # requests: + # memory: "64Mi" + # cpu: "250m" + # limits: + # memory: "128Mi" + # cpu: "500m" + # + # prefix-sidecar-scripts: # updates resource requirements of containers which starts with 'sidecar-scripts-' + # requests: + # memory: "64Mi" + # cpu: "250m" + # limits: + # memory: "128Mi" + # cpu: "500m" + # + # default: # updates resource requirements of init-containers and containers which has empty resource resource requirements + # requests: + # memory: "64Mi" + # cpu: "250m" + # limits: + # memory: "256Mi" + # cpu: "500m" diff --git a/docs/additional-configs.md b/docs/additional-configs.md index b568a76d9e1..31768bde0ea 100644 --- a/docs/additional-configs.md +++ b/docs/additional-configs.md @@ -163,6 +163,69 @@ spec: _In the above example the environment variable `TEST_TEKTON` will not be overriden by value specified in podTemplate, because the `config-default` option `default-forbidden-env` is configured with value `TEST_TEKTON`._ +## Configuring default resources requirements + +Resource requirements of containers created by the controller can be assigned default values. This allows to fully control the resources requirement of `TaskRun`. + +```yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: config-defaults + namespace: tekton-pipelines +data: + default-container-resource-requirements: | + place-scripts: # updates resource requirements of a 'place-scripts' container + requests: + memory: "64Mi" + cpu: "250m" + limits: + memory: "128Mi" + cpu: "500m" + + prepare: # updates resource requirements of a 'prepare' container + requests: + memory: "64Mi" + cpu: "250m" + limits: + memory: "256Mi" + cpu: "500m" + + working-dir-initializer: # updates resource requirements of a 'working-dir-initializer' container + requests: + memory: "64Mi" + cpu: "250m" + limits: + memory: "512Mi" + cpu: "500m" + + prefix-scripts: # updates resource requirements of containers which starts with 'scripts-' + requests: + memory: "64Mi" + cpu: "250m" + limits: + memory: "128Mi" + cpu: "500m" + + prefix-sidecar-scripts: # updates resource requirements of containers which starts with 'sidecar-scripts-' + requests: + memory: "64Mi" + cpu: "250m" + limits: + memory: "128Mi" + cpu: "500m" + + default: # updates resource requirements of init-containers and containers which has empty resource resource requirements + requests: + memory: "64Mi" + cpu: "250m" + limits: + memory: "256Mi" + cpu: "500m" +``` + +Any resource requirements set at the `Task` and `TaskRun` levels will overidde the default one specified in the `config-defaults` configmap. + ## Customizing basic execution parameters You can specify your own values that replace the default service account (`ServiceAccount`), timeout (`Timeout`), resolver (`Resolver`), and Pod template (`PodTemplate`) values used by Tekton Pipelines in `TaskRun` and `PipelineRun` definitions. To do so, modify the ConfigMap `config-defaults` with your desired values. diff --git a/pkg/pod/pod.go b/pkg/pod/pod.go index 10967089c82..709696aff92 100644 --- a/pkg/pod/pod.go +++ b/pkg/pod/pod.go @@ -490,7 +490,7 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1.TaskRun, taskSpec v1.Ta return newPod, nil } -// updates init containers and containers resource requirements of a pod +// updates init containers and containers resource requirements of a pod base of config_defaults configmap. func updateResourceRequirements(resourceRequirementsMap map[string]corev1.ResourceRequirements, pod *corev1.Pod) { if len(resourceRequirementsMap) == 0 { return @@ -514,7 +514,7 @@ func updateResourceRequirements(resourceRequirementsMap map[string]corev1.Resour } } - // update the containers name which does not have resource requirements + // update the containers resource requirements which does not have resource requirements for _, containerName := range containerNames { resourceRequirements := resourceRequirementsMap[containerName] if resourceRequirements.Size() == 0 { @@ -537,7 +537,7 @@ func updateResourceRequirements(resourceRequirementsMap map[string]corev1.Resour } } - // update the containers name which does not have resource requirements with the mentioned prefix + // update the containers resource requirements which does not have resource requirements with the mentioned prefix for _, containerPrefix := range containerNamesWithPrefix { resourceRequirements := resourceRequirementsMap[containerPrefix] if resourceRequirements.Size() == 0 { @@ -565,7 +565,7 @@ func updateResourceRequirements(resourceRequirementsMap map[string]corev1.Resour } } - // update reset of the containers resource requirements which has empty resource requirements + // reset of the containers resource requirements which has empty resource requirements if resourceRequirements, found := resourceRequirementsMap[config.ResourceRequirementDefaultContainerKey]; found && resourceRequirements.Size() != 0 { // update init containers for index := range pod.Spec.InitContainers {