Skip to content

Commit ee13160

Browse files
author
Souvik Sarkar
committed
pipelines resource quota
structural changes actual content added minor edits incorporating comments and refactoring incorporated comments and removed a redundant module fixed file path fixed file path fixed file path fixed file paths fixed path errors incorporated peer review comments build error resolution build error resolution build error resolution
1 parent 23ab9ff commit ee13160

5 files changed

+280
-4
lines changed

_topic_maps/_topic_map.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,8 @@ Topics:
14631463
File: working-with-pipelines-using-the-developer-perspective
14641464
- Name: Reducing resource consumption of OpenShift Pipelines
14651465
File: reducing-pipelines-resource-consumption
1466+
- Name: Setting compute resource quota for OpenShift Pipelines
1467+
File: setting-compute-resource-quota-for-openshift-pipelines
14661468
- Name: Using pods in a privileged security context
14671469
File: using-pods-in-a-privileged-security-context
14681470
- Name: Securing webhooks with event listeners

cicd/pipelines/reducing-pipelines-resource-consumption.adoc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[id="reducing-pipelines-resource-consumption"]
2-
= Reducing resource consumption of pipelines
2+
= Reducing resource consumption of OpenShift Pipelines
33
include::modules/common-attributes.adoc[]
44
include::modules/pipelines-document-attributes.adoc[]
55
:context: reducing-pipelines-resource-consumption
@@ -20,8 +20,10 @@ include::modules/op-understanding-pipelines-resource-consumption.adoc[leveloffse
2020

2121
include::modules/op-mitigating-extra-pipeline-resource-consumption.adoc[leveloffset=+1]
2222

23-
== Additional Resources
23+
[id="additional-resources_reducing-pipelines-resource-consumption"]
24+
== Additional resources
2425

25-
* xref:../../applications/quotas/quotas-setting-per-project.html[Resource Quotas]
26-
* xref:../../nodes/clusters/nodes-cluster-limit-ranges.html[Restricting resource consumption using limit ranges]
26+
* xref:../../cicd/pipelines/setting-compute-resource-quota-for-openshift-pipelines.adoc#setting-compute-resource-quota-for-openshift-pipelines[Setting compute resource quota for OpenShift Pipelines]
27+
* xref:../../applications/quotas/quotas-setting-per-project.adoc#quotas-setting-per-project[Resource quotas per project]
28+
* xref:../../nodes/clusters/nodes-cluster-limit-ranges.adoc#nodes-cluster-limit-ranges[Restricting resource consumption using limit ranges]
2729
* link:https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#resources[Resource requests and limits in Kubernetes]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[id="setting-compute-resource-quota-for-openshift-pipelines"]
2+
= Setting compute resource quota for OpenShift Pipelines
3+
include::modules/common-attributes.adoc[]
4+
include::modules/pipelines-document-attributes.adoc[]
5+
:context: setting-compute-resource-quota-for-openshift-pipelines
6+
7+
toc::[]
8+
9+
10+
A `ResourceQuota` object in {pipelines-title} controls the total resource consumption per namespace. You can use it to limit the quantity of objects created in a namespace, based on the type of the object. In addition, you can specify a compute resource quota to restrict the total amount of compute resources consumed in a namespace.
11+
12+
However, you might want to limit the amount of compute resources consumed by pods resulting from a pipeline run, rather than setting quotas for the entire namespace. Currently, {pipelines-title} does not enable you to directly specify the compute resource quota for a pipeline.
13+
14+
include::modules/op-alternative-approaches-compute-resource-quota-pipelines.adoc[leveloffset=+1]
15+
16+
[NOTE]
17+
====
18+
When using {pipelines-title} in a namespace configured with a `ResourceQuota` object, the pods resulting from task runs and pipeline runs might fail with an error, such as: `failed quota: <quota name> must specify cpu, memory`.
19+
20+
To avoid this error, do any one of the following:
21+
22+
* (Recommended) Specify a limit range for the namespace.
23+
* Explicitly define requests and limits for all containers.
24+
25+
For more information, refer to the link:https://issues.redhat.com/browse/SRVKP-1801[issue] and the link:https://access.redhat.com/solutions/2841971[resolution].
26+
====
27+
28+
If your use case is not addressed by these approaches, you can implement a workaround by using a resource quota for a priority class.
29+
30+
include::modules/op-specifying-pipelines-resource-quota-using-priority-class.adoc[leveloffset=+1]
31+
32+
[id="additional-resources_setting-compute-resource-quota-for-pipelines"]
33+
== Additional resources
34+
35+
* link:https://kubernetes.io/docs/concepts/policy/resource-quotas/[Resource quotas in Kubernetes]
36+
* link:https://kubernetes.io/docs/concepts/policy/limit-range/[Limit ranges in Kubernetes]
37+
* link:https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#resources[Resource requests and limits in Kubernetes]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// This module is included in the following assembly:
2+
//
3+
// */cicd/pipelines/setting-compute-resource-quota-for-openshift-pipelines.adoc
4+
5+
6+
[id="alternative-approaches-compute-resource-quota-pipelines_{context}"]
7+
= Alternative approaches for limiting compute resource consumption in OpenShift Pipelines
8+
9+
To attain some degree of control over the usage of compute resources by a pipeline, consider the following alternative approaches:
10+
11+
* Set resource requests and limits for each step in a task.
12+
+
13+
.Example: Set resource requests and limits for each step in a task.
14+
+
15+
[source,yaml]
16+
----
17+
...
18+
spec:
19+
steps:
20+
- name: step-with-limts
21+
resources:
22+
requests:
23+
memory: 1Gi
24+
cpu: 500m
25+
limits:
26+
memory: 2Gi
27+
cpu: 800m
28+
...
29+
----
30+
31+
* Set resource limits by specifying values for the `LimitRange` object. For more information on `LimitRange`, refer to xref:../../nodes/clusters/nodes-cluster-limit-ranges.adoc#nodes-cluster-limit-ranges[Restrict resource consumption with limit ranges].
32+
33+
* xref:../../cicd/pipelines/reducing-pipelines-resource-consumption.adoc#reducing-pipelines-resource-consumption[Reduce pipeline resource consumption].
34+
35+
* Set and manage xref:../../applications/quotas/quotas-setting-per-project.adoc#quotas-setting-per-project[resource quotas per project].
36+
37+
* Ideally, the compute resource quota for a pipeline should be same as the total amount of compute resources consumed by the concurrently running pods in a pipeline run. However, the pods running the tasks consume compute resources based on the use case. For example, a Maven build task might require different compute resources for different applications that it builds. As a result, you cannot predetermine the compute resource quotas for tasks in a generic pipeline. For greater predictability and control over usage of compute resources, use customized pipelines for different applications.
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
// This module is included in the following assembly:
2+
//
3+
// */cicd/pipelines/setting-compute-resource-quota-for-openshift-pipelines.adoc
4+
5+
6+
[id="specifying-pipelines-resource-quota-using-priority-class_{context}"]
7+
= Specifying pipelines resource quota using priority class
8+
9+
A `PriorityClass` object maps priority class names to the integer values that indicates their relative priorities. Higher values increase the priority of a class. After you create a priority class, you can create pods that specify the priority class name in their specifications. In addition, you can control a pod's consumption of system resources based on the pod's priority.
10+
11+
Specifying resource quota for a pipeline is similar to setting a resource quota for the subset of pods created by a pipeline run. The following steps provide an example of the workaround by specifying resource quota based on priority class.
12+
13+
.Procedure
14+
15+
. Create a priority class for a pipeline.
16+
+
17+
.Example: Priority class for a pipeline
18+
[source,yaml]
19+
----
20+
apiVersion: scheduling.k8s.io/v1
21+
kind: PriorityClass
22+
metadata:
23+
name: pipeline1-pc
24+
value: 1000000
25+
description: "Priority class for pipeline1"
26+
----
27+
28+
. Create a resource quota for a pipeline.
29+
+
30+
.Example: Resource quota for a pipeline
31+
[source,yaml]
32+
----
33+
apiVersion: v1
34+
kind: ResourceQuota
35+
metadata:
36+
name: pipeline1-rq
37+
spec:
38+
hard:
39+
cpu: "1000"
40+
memory: 200Gi
41+
pods: "10"
42+
scopeSelector:
43+
matchExpressions:
44+
- operator : In
45+
scopeName: PriorityClass
46+
values: ["pipeline1-pc"]
47+
----
48+
49+
. Verify the resource quota usage for the pipeline.
50+
+
51+
.Example: Verify resource quota usage for the pipeline
52+
[source,terminal]
53+
----
54+
$ kubectl describe quota
55+
56+
Name: pipeline1-rq
57+
Namespace: default
58+
Resource Used Hard
59+
-------- ---- ----
60+
cpu 0 1k
61+
memory 0 200Gi
62+
pods 0 10
63+
----
64+
+
65+
Because pods are not running, the quota is unused.
66+
67+
. Create the pipelines and tasks.
68+
+
69+
.Example: YAML for the pipeline
70+
[source,yaml]
71+
----
72+
apiVersion: tekton.dev/v1alpha1
73+
kind: Pipeline
74+
metadata:
75+
name: maven-build
76+
spec:
77+
workspaces:
78+
- name: local-maven-repo
79+
resources:
80+
- name: app-git
81+
type: git
82+
tasks:
83+
- name: build
84+
taskRef:
85+
name: mvn
86+
resources:
87+
inputs:
88+
- name: source
89+
resource: app-git
90+
params:
91+
- name: GOALS
92+
value: ["package"]
93+
workspaces:
94+
- name: maven-repo
95+
workspace: local-maven-repo
96+
- name: int-test
97+
taskRef:
98+
name: mvn
99+
runAfter: ["build"]
100+
resources:
101+
inputs:
102+
- name: source
103+
resource: app-git
104+
params:
105+
- name: GOALS
106+
value: ["verify"]
107+
workspaces:
108+
- name: maven-repo
109+
workspace: local-maven-repo
110+
- name: gen-report
111+
taskRef:
112+
name: mvn
113+
runAfter: ["build"]
114+
resources:
115+
inputs:
116+
- name: source
117+
resource: app-git
118+
params:
119+
- name: GOALS
120+
value: ["site"]
121+
workspaces:
122+
- name: maven-repo
123+
workspace: local-maven-repo
124+
----
125+
+
126+
.Example: YAML for a task in the pipeline
127+
[source,yaml]
128+
----
129+
apiVersion: tekton.dev/v1alpha1
130+
kind: Task
131+
metadata:
132+
name: mvn
133+
spec:
134+
workspaces:
135+
- name: maven-repo
136+
inputs:
137+
params:
138+
- name: GOALS
139+
description: The Maven goals to run
140+
type: array
141+
default: ["package"]
142+
resources:
143+
- name: source
144+
type: git
145+
steps:
146+
- name: mvn
147+
image: gcr.io/cloud-builders/mvn
148+
workingDir: /workspace/source
149+
command: ["/usr/bin/mvn"]
150+
args:
151+
- -Dmaven.repo.local=$(workspaces.maven-repo.path)
152+
- "$(inputs.params.GOALS)"
153+
priorityClassName: pipeline1-pc
154+
----
155+
+
156+
[NOTE]
157+
====
158+
Ensure that all tasks in the pipeline belongs to the same priority class.
159+
====
160+
161+
. Create and start the pipeline run.
162+
+
163+
.Example: YAML for a pipeline run
164+
[source,yaml]
165+
----
166+
apiVersion: tekton.dev/v1alpha1
167+
kind: PipelineRun
168+
metadata:
169+
generateName: petclinic-run-
170+
spec:
171+
pipelineRef:
172+
name: maven-build
173+
resources:
174+
- name: app-git
175+
resourceSpec:
176+
type: git
177+
params:
178+
- name: url
179+
value: https://github.com/spring-projects/spring-petclinic
180+
----
181+
182+
. After the pods are created, verify the resource quota usage for the pipeline run.
183+
+
184+
.Example: Verify resource quota usage for the pipeline
185+
[source,terminal]
186+
----
187+
$ kubectl describe quota
188+
189+
Name: pipeline1-rq
190+
Namespace: default
191+
Resource Used Hard
192+
-------- ---- ----
193+
cpu 500m 1k
194+
memory 10Gi 200Gi
195+
pods 1 10
196+
----
197+
+
198+
The output indicates that you can manage the combined resource quota for all concurrent running pods belonging to a priority class, by specifying the resource quota per priority class.

0 commit comments

Comments
 (0)