Skip to content

Commit

Permalink
Update docstring and example for default resources requirements
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Demeester <[email protected]>
  • Loading branch information
vdemeester authored and tekton-robot committed Jan 18, 2024
1 parent 9a3d50c commit 85bc064
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 4 deletions.
53 changes: 53 additions & 0 deletions config/config-defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
63 changes: 63 additions & 0 deletions docs/additional-configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions pkg/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 85bc064

Please sign in to comment.