Este conteúdo não está disponível no idioma selecionado.
Chapter 4. Using manual approval in OpenShift Pipelines
You can specify a manual approval task in a pipeline. When the pipeline reaches this task, it pauses and awaits approval from one or several OpenShift Container Platform users. If any of the users chooses to rejects the task instead of approving it, the pipeline fails. The manual approval gate controller provides this functionality.
The manual approval gate is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
For more information about the support scope of Red Hat Technology Preview features, see Technology Preview Features Support Scope.
4.1. Enabling the manual approval gate controller Copiar o linkLink copiado para a área de transferência!
To use manual approval tasks, you must first enable the manual approval gate controller.
Prerequisites
- You installed the Red Hat OpenShift Pipelines Operator in your cluster.
-
You are logged on to the cluster using the
occommand-line utility. -
You have administrator permissions for the
openshift-pipelinesnamespace.
Procedure
Create a file named
manual-approval-gate-cr.yamlwith the following manifest for theManualApprovalGatecustom resource (CR):Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the
ManualApprovalGateCR by entering the following command:oc apply -f manual-approval-gate-cr.yaml
$ oc apply -f manual-approval-gate-cr.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the manual approval gate controller is running by entering the following command:
oc get manualapprovalgates.operator.tekton.dev
$ oc get manualapprovalgates.operator.tekton.devCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME VERSION READY REASON manual-approval-gate v0.1.0 True
NAME VERSION READY REASON manual-approval-gate v0.1.0 TrueCopy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure that the
READYstatus isTrue. If it is notTrue, wait for a few minutes and enter the command again. The controller might take some time to reach a ready state.
4.2. Specifying a manual approval task Copiar o linkLink copiado para a área de transferência!
You can specify a manual approval task in your pipeline to pause execution until specific stakeholders provide authorization. When a pipeline run reaches an approval task, the process stops and waits for approval from the designated users or groups.
Prerequisites
- You have enabled the manual approver gate controller.
- You have created a YAML specification of a pipeline.
- You have created the groups and added the required users before using group approval.
Procedure
Add an
ApprovalTaskto your pipeline by entering the task definition in yourPipelinedefinition.The following example shows how to include an approval task in a typical deployment pipeline:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optionally, specify status fields for the approval, such as the approval state and approver responses. These fields allow you to track the approval lifecycle during pipeline execution.
The following example demonstrates an approval task with status information:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
The following table describes the parameters for a manual approval task.
| Parameter | Type | Description |
|---|---|---|
|
| array | The OpenShift Container Platform users or groups who can approve the task. |
|
| string | Optional: A description of the approval task. OpenShift Pipelines displays this text to the user who can approve or reject the task. |
|
| string | The number of approvals required from different approvers. |
|
| string | Optional: The timeout period for approval. If the required approvals are not received within this period, the pipeline run fails. The default timeout is 1 hour. |
|
| string |
The current approval state: |
|
| int | The number of approvals received so far. |
|
| []ApproverState | Detailed response from each approver. |
You can define approval tasks for different workflows depending on your requirements. The following are a few examples of approval configurations.
The following is an example for multi user approval.
The following is an example for a group-based user approval.
The following is an example for mixed user and group approvals.
4.3. Approving a manual approval task Copiar o linkLink copiado para a área de transferência!
When you run a pipeline that includes an approval task and the execution reaches the approval task, the pipeline run pauses and waits for user approval or rejection.
Users can approve or reject the task by using either the web console or the opc command line utility.
If any one of the approvers configured in the task rejects the task, the pipeline run fails.
If one user approves the task but the configured number of approvals is still not reached, the same user can change to rejecting the task and the pipeline run fails
4.3.1. Approving a manual approval task by using the web console Copiar o linkLink copiado para a área de transferência!
You can approve or reject a manual approval task by using the OpenShift Container Platform web console.
If you are listed as an approver in a manual approval task and a pipeline run reaches this task, the web console displays a notification. You can view a list of tasks that require your approval and approve or reject these tasks.
Prerequisites
- You enabled the OpenShift Pipelines console plugin.
Procedure
View a list of tasks that you can approve by completing one of the following actions:
- When a notification about a task requiring your approval displays, click Go to Approvals tab in this notification.
-
In the Administrator perspective menu, select Pipelines
Pipelines and then click the Approvals tab. - In the Developer perspective menu, select Pipelines and then click the Approvals tab.
- In the PipelineRun details window, in the Details tab, click the rectangle that represents the manual approval task. The list displays only the approval for this task.
- In the PipelineRun details window, click the ApprovalTasks tab. The list displays only the approval for this pipeline run.
In the list of approval tasks, in the line that represents the task that you want to approve, click the
icon and then select one of the following options:
- To approve the task, select Approve.
- To reject the task, select Reject.
- Enter a message in the Reason field.
- Click Submit.
4.3.2. Approving a manual approval task by using the command line Copiar o linkLink copiado para a área de transferência!
You can approve or reject a manual approval task by using the opc command-line utility. You can view a list of tasks for which you are an approver and approve or reject the tasks that are pending approval.
Prerequisites
-
You downloaded and installed the
opccommand-line utility. This utility is available in the same package as thetkncommand-line utility. -
You are logged on to the cluster using the
occommand-line utility.
Procedure
View a list of manual approval tasks for which you are listed as an approver by entering the following command:
opc approvaltask list
$ opc approvaltask listCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME NumberOfApprovalsRequired PendingApprovals Rejected STATUS manual-approval-pipeline-01w6e1-task-2 2 0 0 Approved manual-approval-pipeline-6ywv82-task-2 2 2 0 Rejected manual-approval-pipeline-90gyki-task-2 2 2 0 Pending manual-approval-pipeline-jyrkb3-task-2 2 1 1 Rejected
NAME NumberOfApprovalsRequired PendingApprovals Rejected STATUS manual-approval-pipeline-01w6e1-task-2 2 0 0 Approved manual-approval-pipeline-6ywv82-task-2 2 2 0 Rejected manual-approval-pipeline-90gyki-task-2 2 2 0 Pending manual-approval-pipeline-jyrkb3-task-2 2 1 1 RejectedCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: To view information about a manual approval task, including its name, namespace, pipeline run name, list of approvers, and current status, enter the following command:
opc approvaltask describe <approval_task_name>
$ opc approvaltask describe <approval_task_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Approve or reject a manual approval task as necessary:
To approve a manual approval task, enter the following command:
opc approvaltask approve <approval_task_name>
$ opc approvaltask approve <approval_task_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optionally, you can specify a message for the approval by using the
-mparameter:opc approvaltask approve <approval_task_name> -m <message>
$ opc approvaltask approve <approval_task_name> -m <message>Copy to Clipboard Copied! Toggle word wrap Toggle overflow To reject a manual approval task, enter the following command:
opc approvaltask reject <approval_task_name>
$ opc approvaltask reject <approval_task_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optionally, you can specify a message for the rejection by using the
-mparameter:opc approvaltask reject <approval_task_name> -m <message>
$ opc approvaltask reject <approval_task_name> -m <message>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.4. Behavior of ApprovalTask with groups and users Copiar o linkLink copiado para a área de transferência!
You can define complex approval policies by combining individual users and groups in a single definition. This allows you to specify the total number of required approvals from different stakeholders, such as a tech lead, a QA engineer, and a member of the security team.
You can assign approval responsibility to a group. When a group is configured as an approver, the controller tracks individual approvals from group members and updates the group’s overall approval state automatically.
Example Initial ApprovalTask created by the controller with a group approver
spec:
approvers:
- name: dev-team
type: Group
input: pending
spec:
approvers:
- name: dev-team
type: Group
input: pending
As group members approve or reject the task, their individual actions appear in the users list. The group’s approval state changes automatically as soon as the necessary member-level approvals are recorded.
Example Group member approvals recorded by the controller
ApprovalTask also supports scenarios where approvals are required from both individual users and groups. You can combine users and groups in a single approval definition while specifying the total number of required approvals. This allows pipelines to enforce more granular approval policies, such as requiring sign-off from a tech lead, a QA engineer, and a member of the security team.
The following YAML represents a runtime ApprovalTask object created automatically by the Manual Approval Gate controller when a PipelineRun pauses at an approval step. Do not apply this manifest. It is provided for debugging and inspection only.