-
Notifications
You must be signed in to change notification settings - Fork 7
/
approvaltask_types.go
134 lines (106 loc) · 4.68 KB
/
approvaltask_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
Copyright 2022 The OpenShift Pipelines Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1alpha1
import (
"context"
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/clock"
duckv1 "knative.dev/pkg/apis/duck/v1"
)
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ApprovalTask is a "wait for manual approval" Task.
// +k8s:openapi-gen=true
type ApprovalTask struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata"`
// Spec holds the desired state of the TaskGroup from the client
// +optional
Spec ApprovalTaskSpec `json:"spec"`
Status ApprovalTaskStatus `json:"status"`
}
type ApprovalTaskSpec struct {
Approvers []ApproverDetails `json:"approvers"`
NumberOfApprovalsRequired int `json:"numberOfApprovalsRequired"`
Description string `json:"description,omitempty"`
}
type ApproverDetails struct {
Name string `json:"name"`
Input string `json:"input"`
Message string `json:"message,omitempty"`
}
type ApprovalTaskStatus struct {
duckv1.Status `json:",inline"`
State string `json:"state"`
Approvers []string `json:"approvers,omitempty"`
ApproversResponse []ApproverState `json:"approversResponse,omitempty"`
// StartTime is the time the build is actually started.
StartTime *metav1.Time `json:"startTime,omitempty"`
}
type ApproverState struct {
Name string `json:"name"`
Response string `json:"response"`
Message string `json:"message,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ApprovalTaskList contains a list of ApprovalTasks
type ApprovalTaskList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
Items []ApprovalTask `json:"items"`
}
// ApprovalTaskRunStatus contains the status stored in the ExtraFields of a Run that references a ApprovalTask.
type ApprovalTaskRunStatus struct {
// ApprovalTaskSpec contains the exact spec used to instantiate the Run
// FIXME(openshift-pipelines) can probably remove
ApprovalTaskSpec *ApprovalTaskSpec `json:"taskLoopSpec,omitempty"`
// +optional
// TaskRun *v1beta1.TaskRunStatus `json:"status,omitempty"`
}
// ApprovalTaskRunReason represents a reason for the Run "Succeeded" condition
type ApprovalTaskRunReason string
const (
// ApprovalTaskRunReasonStarted is the reason set when the Run has just started
ApprovalTaskRunReasonStarted ApprovalTaskRunReason = "Started"
// ApprovalTaskRunReasonRunning indicates that the Run is in progress
ApprovalTaskRunReasonRunning ApprovalTaskRunReason = "Running"
// ApprovalTaskRunReasonFailed indicates that one of the TaskRuns created from the Run failed
ApprovalTaskRunReasonFailed ApprovalTaskRunReason = "Failed"
// ApprovalTaskRunReasonSucceeded indicates that all of the TaskRuns created from the Run completed successfully
ApprovalTaskRunReasonSucceeded ApprovalTaskRunReason = "Succeeded"
// ApprovalTaskRunReasonCouldntCancel indicates that a Run was cancelled but attempting to update
// the running TaskRun as cancelled failed.
ApprovalTaskRunReasonCouldntCancel ApprovalTaskRunReason = "ApprovalTaskRunCouldntCancel"
// ApprovalTaskRunReasonCouldntGetApprovalTask indicates that the associated ApprovalTask couldn't be retrieved
ApprovalTaskRunReasonCouldntGetApprovalTask ApprovalTaskRunReason = "CouldntGetApprovalTask"
// ApprovalTaskRunReasonFailedValidation indicates that the ApprovalTask failed runtime validation
ApprovalTaskRunReasonFailedValidation ApprovalTaskRunReason = "ApprovalTaskValidationFailed"
// ApprovalTaskRunReasonInternalError indicates that the ApprovalTask failed due to an internal error in the reconciler
ApprovalTaskRunReasonInternalError ApprovalTaskRunReason = "ApprovalTaskInternalError"
)
func (t ApprovalTaskRunReason) String() string {
return string(t)
}
func (at ApprovalTask) HasStarted() bool {
return at.Status.StartTime != nil
}
func (at ApprovalTask) ApprovalTaskHasTimedOut(ctx context.Context, c clock.PassiveClock, timeout time.Duration) bool {
if at.Status.StartTime.IsZero() {
return false
}
runtime := c.Since(at.Status.StartTime.Time)
return runtime > timeout
}