|
| 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