Skip to content

Commit 887bb0c

Browse files
Adds support for group of users in Manual Approval
This patch aligns Approval Task spec with some new fields - adds `type` field for both `User` and `Group` - adds support for approver groups - enhanced status tracking with `approverResponse` including group and users To refer group name in pipelinerun add `group:` keyword ``` params: - name: approvers value: - foo - bar - group:tekton # 👉 `group:<groupName>` - group:example ``` With this patch now when the approvalTask is created it will look as ``` apiVersion: openshift-pipelines.org/v1alpha1 kind: ApprovalTask metadata: annotations: tekton.dev/last-applied-hash: 45f48c89406b77d2c7be34c01fca34587a867e5c1db74d87958e7d5995d2c895 creationTimestamp: "2025-07-07T11:13:04Z" generation: 3 labels: tekton.dev/customRun: pr-custom-task-beta-cgb54-wait tekton.dev/memberOf: tasks tekton.dev/pipeline: pr-custom-task-beta-cgb54 tekton.dev/pipelineRun: pr-custom-task-beta-cgb54 tekton.dev/pipelineRunUID: 8d44f040-1740-404c-b9d9-f77f52d5e5f4 tekton.dev/pipelineTask: wait name: pr-custom-task-beta-cgb54-wait namespace: default ownerReferences: - apiVersion: tekton.dev/v1beta1 blockOwnerDeletion: true controller: true kind: CustomRun name: pr-custom-task-beta-cgb54-wait uid: 84debd0b-5b03-4d28-b0f5-474f8e602dac resourceVersion: "1856714" uid: e014fb1b-e6ea-48e2-af72-7455f300a308 spec: approvers: - input: pending name: foo type: User # 👉 New field added - input: pending name: bar type: User - input: pending name: user3 type: User - input: reject name: user2 type: User - input: pending name: tekton type: Group - input: reject name: example type: Group # 👉 New field added users: # 👉 When users from group approve or reject - name: user1 input: approve - name: user2 input: reject description: Approval Task Rocks!!! numberOfApprovalsRequired: 2 status: approvers: - foo - bar - user3 - user2 - group:tekton - group:example approversResponse: - response: approved name: foo type: User # New field added - response: approved name: abc type: User # New field added - response: rejected name: tekton-team type: Group # New field added groupMembers: - name: user1 response: rejected startTime: "2025-07-07T11:13:04Z" state: rejected ``` Scenarios handled: Controller - Until and unless approval task does not get approval from the users as true, till that approvalState will be `wait` - If any one use disapproves the approval task we will mark the approvalState as false and then the pipelinerun will fail - If a user approves for the first time and still approvalsRequired limit is not reached i.e. approvalState is `wait` then user can still change his input and mark the approval task as `false` - Approvals from both type as `user` and type as `group` is allowed at once Adds e2e test for support of group of users Signed-off-by: PuneetPunamiya <[email protected]> refactor the design Signed-off-by: PuneetPunamiya <[email protected]>
1 parent 50c2ec5 commit 887bb0c

File tree

18 files changed

+858
-361
lines changed

18 files changed

+858
-361
lines changed

pkg/apis/approvaltask/v1alpha1/approvaltask_types.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,17 @@ type ApprovalTaskSpec struct {
4646
Description string `json:"description,omitempty"`
4747
}
4848

49+
type UserDetails struct {
50+
Name string `json:"name"`
51+
Input string `json:"input"`
52+
}
53+
4954
type ApproverDetails struct {
50-
Name string `json:"name"`
51-
Input string `json:"input"`
52-
Message string `json:"message,omitempty"`
55+
Name string `json:"name"`
56+
Input string `json:"input"`
57+
Message string `json:"message,omitempty"`
58+
Type string `json:"type"`
59+
Users []UserDetails `json:"users,omitempty"`
5360
}
5461

5562
type ApprovalTaskStatus struct {
@@ -61,12 +68,20 @@ type ApprovalTaskStatus struct {
6168
StartTime *metav1.Time `json:"startTime,omitempty"`
6269
}
6370

64-
type ApproverState struct {
71+
type GroupMemberState struct {
6572
Name string `json:"name"`
6673
Response string `json:"response"`
6774
Message string `json:"message,omitempty"`
6875
}
6976

77+
type ApproverState struct {
78+
Name string `json:"name"`
79+
Response string `json:"response"`
80+
Message string `json:"message,omitempty"`
81+
Type string `json:"type"`
82+
GroupMembers []GroupMemberState `json:"groupMembers,omitempty"`
83+
}
84+
7085
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
7186

7287
// ApprovalTaskList contains a list of ApprovalTasks

pkg/apis/approvaltask/v1alpha1/zz_generated.deepcopy.go

Lines changed: 48 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cli/cmd/approve/approve_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ func TestApproveApprovalTask(t *testing.T) {
2626
{
2727
Name: "tekton",
2828
Input: "pending",
29+
Type: "User",
2930
},
3031
{
3132
Name: "cli",
3233
Input: "pending",
34+
Type: "User",
3335
},
3436
},
3537
NumberOfApprovalsRequired: 2,
@@ -52,10 +54,12 @@ func TestApproveApprovalTask(t *testing.T) {
5254
{
5355
Name: "tekton",
5456
Input: "pending",
57+
Type: "User",
5558
},
5659
{
5760
Name: "cli",
5861
Input: "pending",
62+
Type: "User",
5963
},
6064
},
6165
NumberOfApprovalsRequired: 2,
@@ -78,10 +82,12 @@ func TestApproveApprovalTask(t *testing.T) {
7882
{
7983
Name: "tekton",
8084
Input: "pending",
85+
Type: "User",
8186
},
8287
{
8388
Name: "cli",
8489
Input: "pending",
90+
Type: "User",
8591
},
8692
},
8793
NumberOfApprovalsRequired: 2,

pkg/client/clientset/versioned/clientset.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/client/clientset/versioned/fake/clientset_generated.go

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/client/clientset/versioned/typed/approvaltask/v1alpha1/approvaltask.go

Lines changed: 19 additions & 144 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)