@@ -18,14 +18,12 @@ package v1alpha1
18
18
19
19
import (
20
20
"fmt"
21
- "time"
22
21
23
22
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
24
23
v1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
24
+ runv1alpha1 "github.com/tektoncd/pipeline/pkg/apis/run/v1alpha1"
25
25
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26
- "k8s.io/apimachinery/pkg/runtime"
27
26
"k8s.io/apimachinery/pkg/runtime/schema"
28
- "k8s.io/apimachinery/pkg/util/json"
29
27
"knative.dev/pkg/apis"
30
28
duckv1 "knative.dev/pkg/apis/duck/v1"
31
29
)
@@ -75,85 +73,16 @@ func (rs RunSpec) GetParam(name string) *v1beta1.Param {
75
73
return nil
76
74
}
77
75
78
- type RunStatus struct {
79
- duckv1.Status `json:",inline"`
76
+ const (
77
+ // RunReasonCancelled must be used in the Condition Reason to indicate that a Run was cancelled.
78
+ RunReasonCancelled = "RunCancelled"
79
+ )
80
80
81
- // RunStatusFields inlines the status fields.
82
- RunStatusFields `json:",inline"`
83
- }
81
+ // RunStatus defines the observed state of Run.
82
+ type RunStatus = runv1alpha1.RunStatus
84
83
85
84
var runCondSet = apis .NewBatchConditionSet ()
86
85
87
- // GetCondition returns the Condition matching the given type.
88
- func (r * RunStatus ) GetCondition (t apis.ConditionType ) * apis.Condition {
89
- return runCondSet .Manage (r ).GetCondition (t )
90
- }
91
-
92
- // InitializeConditions will set all conditions in runCondSet to unknown for the PipelineRun
93
- // and set the started time to the current time
94
- func (r * RunStatus ) InitializeConditions () {
95
- started := false
96
- if r .StartTime .IsZero () {
97
- r .StartTime = & metav1.Time {Time : time .Now ()}
98
- started = true
99
- }
100
- conditionManager := runCondSet .Manage (r )
101
- conditionManager .InitializeConditions ()
102
- // Ensure the started reason is set for the "Succeeded" condition
103
- if started {
104
- initialCondition := conditionManager .GetCondition (apis .ConditionSucceeded )
105
- initialCondition .Reason = "Started"
106
- conditionManager .SetCondition (* initialCondition )
107
- }
108
- }
109
-
110
- // SetCondition sets the condition, unsetting previous conditions with the same
111
- // type as necessary.
112
- func (r * RunStatus ) SetCondition (newCond * apis.Condition ) {
113
- if newCond != nil {
114
- runCondSet .Manage (r ).SetCondition (* newCond )
115
- }
116
- }
117
-
118
- // MarkRunSucceeded changes the Succeeded condition to True with the provided reason and message.
119
- func (r * RunStatus ) MarkRunSucceeded (reason , messageFormat string , messageA ... interface {}) {
120
- runCondSet .Manage (r ).MarkTrueWithReason (apis .ConditionSucceeded , reason , messageFormat , messageA ... )
121
- succeeded := r .GetCondition (apis .ConditionSucceeded )
122
- r .CompletionTime = & succeeded .LastTransitionTime .Inner
123
- }
124
-
125
- // MarkRunFailed changes the Succeeded condition to False with the provided reason and message.
126
- func (r * RunStatus ) MarkRunFailed (reason , messageFormat string , messageA ... interface {}) {
127
- runCondSet .Manage (r ).MarkFalse (apis .ConditionSucceeded , reason , messageFormat , messageA ... )
128
- succeeded := r .GetCondition (apis .ConditionSucceeded )
129
- r .CompletionTime = & succeeded .LastTransitionTime .Inner
130
- }
131
-
132
- // MarkRunRunning changes the Succeeded condition to Unknown with the provided reason and message.
133
- func (r * RunStatus ) MarkRunRunning (reason , messageFormat string , messageA ... interface {}) {
134
- runCondSet .Manage (r ).MarkUnknown (apis .ConditionSucceeded , reason , messageFormat , messageA ... )
135
- }
136
-
137
- // DecodeExtraFields deserializes the extra fields in the Run status.
138
- func (r * RunStatus ) DecodeExtraFields (into interface {}) error {
139
- if len (r .ExtraFields .Raw ) == 0 {
140
- return nil
141
- }
142
- return json .Unmarshal (r .ExtraFields .Raw , into )
143
- }
144
-
145
- // EncodeExtraFields serializes the extra fields in the Run status.
146
- func (r * RunStatus ) EncodeExtraFields (from interface {}) error {
147
- data , err := json .Marshal (from )
148
- if err != nil {
149
- return err
150
- }
151
- r .ExtraFields = runtime.RawExtension {
152
- Raw : data ,
153
- }
154
- return nil
155
- }
156
-
157
86
// GetConditionSet retrieves the condition set for this resource. Implements
158
87
// the KRShaped interface.
159
88
func (r * Run ) GetConditionSet () apis.ConditionSet { return runCondSet }
@@ -165,24 +94,10 @@ func (r *Run) GetStatus() *duckv1.Status { return &r.Status.Status }
165
94
// RunStatusFields holds the fields of Run's status. This is defined
166
95
// separately and inlined so that other types can readily consume these fields
167
96
// via duck typing.
168
- type RunStatusFields struct {
169
- // StartTime is the time the build is actually started.
170
- // +optional
171
- StartTime * metav1.Time `json:"startTime,omitempty"`
172
-
173
- // CompletionTime is the time the build completed.
174
- // +optional
175
- CompletionTime * metav1.Time `json:"completionTime,omitempty"`
176
-
177
- // Results reports any output result values to be consumed by later
178
- // tasks in a pipeline.
179
- // +optional
180
- Results []v1beta1.TaskRunResult `json:"results,omitempty"`
97
+ type RunStatusFields = runv1alpha1.RunStatusFields
181
98
182
- // ExtraFields holds arbitrary fields provided by the custom task
183
- // controller.
184
- ExtraFields runtime.RawExtension `json:"extraFields,omitempty"`
185
- }
99
+ // RunResult used to describe the results of a task
100
+ type RunResult = runv1alpha1.RunResult
186
101
187
102
// +genclient
188
103
// +genreconciler
0 commit comments