/
types.go
356 lines (307 loc) · 12.4 KB
/
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/*
Copyright 2018 The Kubernetes 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 apiv1 taken from test-infra/prow/apis/prowjobs/v1/types.go without
// knative
package apiv1
import (
"fmt"
"strings"
"time"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// Config loads a subset of the Prow config definition.
type Config struct {
// Plank is the default plank configuration.
Plank PlankConfig `json:"plank"`
// Periodics uses the definitions of periodic jobs to invoke
// special actions. Only a subset of fields is supported.
Periodics []PeriodicConfig `json:"periodics"`
}
type PlankConfig struct {
// DecorationConfig holds configuration options for
// decorating PodSpecs that users provide.
DefaultDecorationConfig *DecorationConfig `json:"default_decoration_config,omitempty"`
}
// PeriodicConfig is a subset of the configuration of a periodic job.
type PeriodicConfig struct {
Name string `json:"name"`
// Labels are added in prowjobs created for this job.
Labels map[string]string `json:"labels,omitempty"`
// Agent that will take care of running this job.
Agent string `json:"agent"`
// Kubernetes pod spec.
Spec *corev1.PodSpec `json:"spec,omitempty"`
// Tags for config entries
Tags []string `json:"tags,omitempty"`
}
// ProwJobType specifies how the job is triggered.
type ProwJobType string
// Various job types.
const (
// PresubmitJob means it runs on unmerged PRs.
PresubmitJob ProwJobType = "presubmit"
// PostsubmitJob means it runs on each new commit.
PostsubmitJob = "postsubmit"
// Periodic job means it runs on a time-basis, unrelated to git changes.
PeriodicJob = "periodic"
// BatchJob tests multiple unmerged PRs at the same time.
BatchJob = "batch"
)
// ProwJobState specifies whether the job is running
type ProwJobState string
// Various job states.
const (
// TriggeredState means the job has been created but not yet scheduled.
TriggeredState ProwJobState = "triggered"
// PendingState means the job is scheduled but not yet running.
PendingState = "pending"
// SuccessState means the job completed without error (exit 0)
SuccessState = "success"
// FailureState means the job completed with errors (exit non-zero)
FailureState = "failure"
// AbortedState means prow killed the job early (new commit pushed, perhaps).
AbortedState = "aborted"
// ErrorState means the job could not schedule (bad config, perhaps).
ErrorState = "error"
)
// ProwJobAgent specifies the controller (such as plank or jenkins-agent) that runs the job.
type ProwJobAgent string
const (
// KubernetesAgent means prow will create a pod to run this job.
KubernetesAgent ProwJobAgent = "kubernetes"
// JenkinsAgent means prow will schedule the job on jenkins.
JenkinsAgent = "jenkins"
// KnativeBuildAgent means prow will schedule the job via a build-crd resource.
KnativeBuildAgent = "knative-build"
)
const (
// DefaultClusterAlias specifies the default cluster key to schedule jobs.
DefaultClusterAlias = "default"
)
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ProwJob contains the spec as well as runtime metadata.
type ProwJob struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ProwJobSpec `json:"spec,omitempty"`
Status ProwJobStatus `json:"status,omitempty"`
}
// ProwJobSpec configures the details of the prow job.
//
// Details include the podspec, code to clone, the cluster it runs
// any child jobs, concurrency limitations, etc.
type ProwJobSpec struct {
// Type is the type of job and informs how
// the jobs is triggered
Type ProwJobType `json:"type,omitempty"`
// Agent determines which controller fulfills
// this specific ProwJobSpec and runs the job
Agent ProwJobAgent `json:"agent,omitempty"`
// Cluster is which Kubernetes cluster is used
// to run the job, only applicable for that
// specific agent
Cluster string `json:"cluster,omitempty"`
// Job is the name of the job
Job string `json:"job,omitempty"`
// Refs is the code under test, determined at
// runtime by Prow itself
Refs *Refs `json:"refs,omitempty"`
// ExtraRefs are auxiliary repositories that
// need to be cloned, determined from config
ExtraRefs []*Refs `json:"extra_refs,omitempty"`
// Report determines if the result of this job should
// be posted as a status on GitHub
Report bool `json:"report,omitempty"`
// Context is the name of the status context used to
// report back to GitHub
Context string `json:"context,omitempty"`
// RerunCommand is the command a user would write to
// trigger this job on their pull request
RerunCommand string `json:"rerun_command,omitempty"`
// MaxConcurrency restricts the total number of instances
// of this job that can run in parallel at once
MaxConcurrency int `json:"max_concurrency,omitempty"`
// PodSpec provides the basis for running the test under
// a Kubernetes agent
PodSpec *corev1.PodSpec `json:"pod_spec,omitempty"`
// DecorationConfig holds configuration options for
// decorating PodSpecs that users provide
DecorationConfig *DecorationConfig `json:"decoration_config,omitempty"`
// RunAfterSuccess are jobs that should be triggered if
// this job runs and does not fail
RunAfterSuccess []ProwJobSpec `json:"run_after_success,omitempty"`
}
// DecorationConfig specifies how to augment pods.
//
// This is primarily used to provide automatic integration with gubernator
// and testgrid.
type DecorationConfig struct {
// Timeout is how long the pod utilities will wait
// before aborting a job with SIGINT.
Timeout time.Duration `json:"timeout,omitempty"`
// GracePeriod is how long the pod utilities will wait
// after sending SIGINT to send SIGKILL when aborting
// a job. Only applicable if decorating the PodSpec.
GracePeriod time.Duration `json:"grace_period,omitempty"`
// UtilityImages holds pull specs for utility container
// images used to decorate a PodSpec.
UtilityImages *UtilityImages `json:"utility_images,omitempty"`
// GCSConfiguration holds options for pushing logs and
// artifacts to GCS from a job.
GCSConfiguration *GCSConfiguration `json:"gcs_configuration,omitempty"`
// GCSCredentialsSecret is the name of the Kubernetes secret
// that holds GCS push credentials
GCSCredentialsSecret string `json:"gcs_credentials_secret,omitempty"`
// SSHKeySecrets are the names of Kubernetes secrets that contain
// SSK keys which should be used during the cloning process
SSHKeySecrets []string `json:"ssh_key_secrets,omitempty"`
// SkipCloning determines if we should clone source code in the
// initcontainers for jobs that specify refs
SkipCloning bool `json:"skip_cloning,omitempty"`
// CookieFileSecret is the name of a kubernetes secret that contains
// a git http.cookiefile, which should be used during the cloning process.
CookiefileSecret string `json:"cookiefile_secret,omitempty"`
}
// UtilityImages holds pull specs for the utility images
// to be used for a job
type UtilityImages struct {
// CloneRefs is the pull spec used for the clonerefs utility
CloneRefs string `json:"clonerefs,omitempty"`
// InitUpload is the pull spec used for the initupload utility
InitUpload string `json:"initupload,omitempty"`
// Entrypoint is the pull spec used for the entrypoint utility
Entrypoint string `json:"entrypoint,omitempty"`
// sidecar is the pull spec used for the sidecar utility
Sidecar string `json:"sidecar,omitempty"`
}
// PathStrategy specifies minutia about how to contruct the url.
// Usually consumed by gubernator/testgrid.
const (
PathStrategyLegacy = "legacy"
PathStrategySingle = "single"
PathStrategyExplicit = "explicit"
)
// GCSConfiguration holds options for pushing logs and
// artifacts to GCS from a job.
type GCSConfiguration struct {
// Bucket is the GCS bucket to upload to
Bucket string `json:"bucket,omitempty"`
// PathPrefix is an optional path that follows the
// bucket name and comes before any structure
PathPrefix string `json:"path_prefix,omitempty"`
// PathStrategy dictates how the org and repo are used
// when calculating the full path to an artifact in GCS
PathStrategy string `json:"path_strategy,omitempty"`
// DefaultOrg is omitted from GCS paths when using the
// legacy or simple strategy
DefaultOrg string `json:"default_org,omitempty"`
// DefaultRepo is omitted from GCS paths when using the
// legacy or simple strategy
DefaultRepo string `json:"default_repo,omitempty"`
}
// ProwJobStatus provides runtime metadata, such as when it finished, whether it is running, etc.
type ProwJobStatus struct {
StartTime metav1.Time `json:"startTime,omitempty"`
CompletionTime *metav1.Time `json:"completionTime,omitempty"`
State ProwJobState `json:"state,omitempty"`
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
// PodName applies only to ProwJobs fulfilled by
// plank. This field should always be the same as
// the ProwJob.ObjectMeta.Name field.
PodName string `json:"pod_name,omitempty"`
// BuildID is the build identifier vended either by tot
// or the snowflake library for this job and used as an
// identifier for grouping artifacts in GCS for views in
// TestGrid and Gubernator. Idenitifiers vended by tot
// are monotonically increasing whereas identifiers vended
// by the snowflake library are not.
BuildID string `json:"build_id,omitempty"`
// JenkinsBuildID applies only to ProwJobs fulfilled
// by the jenkins-operator. This field is the build
// identifier that Jenkins gave to the build for this
// ProwJob.
JenkinsBuildID string `json:"jenkins_build_id,omitempty"`
// PrevReportState stores the previous reported prowjob state
// So crier won't make duplicated report attempt
PrevReportState ProwJobState `json:"prev_report_state, omitempty"`
}
// Complete returns true if the prow job has finished
func (j *ProwJob) Complete() bool {
// TODO(fejta): support a timeout?
return j.Status.CompletionTime != nil
}
// SetComplete marks the job as completed (at time now).
func (j *ProwJob) SetComplete() {
j.Status.CompletionTime = new(metav1.Time)
*j.Status.CompletionTime = metav1.Now()
}
// ClusterAlias specifies the key in the clusters map to use.
//
// This allows scheduling a prow job somewhere aside from the default build cluster.
func (j *ProwJob) ClusterAlias() string {
if j.Spec.Cluster == "" {
return DefaultClusterAlias
}
return j.Spec.Cluster
}
// Pull describes a pull request at a particular point in time.
type Pull struct {
Number int `json:"number,omitempty"`
Author string `json:"author,omitempty"`
SHA string `json:"sha,omitempty"`
// Ref is git ref can be checked out for a change
// for example,
// github: pull/123/head
// gerrit: refs/changes/00/123/1
Ref string `json:"ref,omitempty"`
}
// Refs describes how the repo was constructed.
type Refs struct {
// Org is something like kubernetes or k8s.io
Org string `json:"org,omitempty"`
// Repo is something like test-infra
Repo string `json:"repo,omitempty"`
BaseRef string `json:"base_ref,omitempty"`
BaseSHA string `json:"base_sha,omitempty"`
Pulls []Pull `json:"pulls,omitempty"`
// PathAlias is the location under <root-dir>/src
// where this repository is cloned. If this is not
// set, <root-dir>/src/github.com/org/repo will be
// used as the default.
PathAlias string `json:"path_alias,omitempty"`
// CloneURI is the URI that is used to clone the
// repository. If unset, will default to
// `https://github.com/org/repo.git`.
CloneURI string `json:"clone_uri,omitempty"`
}
func (r Refs) String() string {
rs := []string{fmt.Sprintf("%s:%s", r.BaseRef, r.BaseSHA)}
for _, pull := range r.Pulls {
ref := fmt.Sprintf("%d:%s", pull.Number, pull.SHA)
if pull.Ref != "" {
ref = fmt.Sprintf("%s:%s", ref, pull.Ref)
}
rs = append(rs, ref)
}
return strings.Join(rs, ",")
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ProwJobList is a list of ProwJob resources
type ProwJobList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []ProwJob `json:"items"`
}