-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go
404 lines (338 loc) · 18.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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
package v1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strings"
)
// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:openapi-gen=true
// Environment represents an environment like Dev, Test, Staging, Production where code lives
type Environment struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Spec EnvironmentSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
Status EnvironmentStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}
// EnvironmentSpec is the specification of an Environment
type EnvironmentSpec struct {
Label string `json:"label,omitempty" protobuf:"bytes,1,opt,name=label"`
Namespace string `json:"namespace,omitempty" protobuf:"bytes,2,opt,name=namespace"`
Cluster string `json:"cluster,omitempty" protobuf:"bytes,3,opt,name=cluster"`
PromotionStrategy PromotionStrategyType `json:"promotionStrategy,omitempty" protobuf:"bytes,4,opt,name=promotionStrategy"`
Source EnvironmentRepository `json:"source,omitempty" protobuf:"bytes,5,opt,name=source"`
Order int32 `json:"order,omitempty" protobuf:"bytes,6,opt,name=order"`
Kind EnvironmentKindType `json:"kind,omitempty" protobuf:"bytes,7,opt,name=kind"`
PullRequestURL string `json:"pullRequestURL,omitempty" protobuf:"bytes,8,opt,name=pullRequestURL"`
TeamSettings TeamSettings `json:"teamSettings,omitempty" protobuf:"bytes,9,opt,name=teamSettings"`
//PreviewGitSpec PreviewGitSpec `json:"previewGitSpec,omitempty" protobuf:"bytes,8,opt,name=previewGitSpec"`
}
// EnvironmentStatus is the status for an Environment resource
type EnvironmentStatus struct {
Version string `json:"version,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// EnvironmentList is a list of TypeMeta resources
type EnvironmentList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []Environment `json:"items"`
}
// PromotionStrategyType is the type of a promotion strategy
type PromotionStrategyType string
const (
// PromotionStrategyTypeManual specifies that promotion happens manually
PromotionStrategyTypeManual PromotionStrategyType = "Manual"
// PromotionStrategyTypeAutomatic specifies that promotion happens automatically
PromotionStrategyTypeAutomatic PromotionStrategyType = "Auto"
// PromotionStrategyTypeNever specifies that promotion is disabled for this environment
PromotionStrategyTypeNever PromotionStrategyType = "Never"
)
// EnvironmentKindType is the kind of an environment
type EnvironmentKindType string
const (
// EnvironmentKindTypePermanent specifies that the environment is a regular permanent one
EnvironmentKindTypePermanent EnvironmentKindType = "Permanent"
// EnvironmentKindTypePreview specifies that an environment is a Preview environment that lasts as long as a Pull Request
EnvironmentKindTypePreview EnvironmentKindType = "Preview"
// EnvironmentKindTypeTest specifies that an environment is a temporary one for a test
EnvironmentKindTypeTest EnvironmentKindType = "Test"
// EnvironmentKindTypeEdit specifies that an environment is a developers editing workspace
EnvironmentKindTypeEdit EnvironmentKindType = "Edit"
// EnvironmentKindTypeDevelopment specifies that an environment is a development environment; for developer tools like Jenkins, Nexus etc
EnvironmentKindTypeDevelopment EnvironmentKindType = "Development"
)
// IsPermanent returns true if this environment is permanent
func (e EnvironmentKindType) IsPermanent() bool {
switch e {
case EnvironmentKindTypePreview, EnvironmentKindTypeTest, EnvironmentKindTypeEdit:
return false
default:
return true
}
}
// PromotionStrategyTypeValues is the list of all values
var PromotionStrategyTypeValues = []string{
string(PromotionStrategyTypeAutomatic),
string(PromotionStrategyTypeManual),
string(PromotionStrategyTypeNever),
}
// EnvironmentRepositoryType is the repository type
type EnvironmentRepositoryType string
const (
// EnvironmentRepositoryTypeGit specifies that a git repository is used
EnvironmentRepositoryTypeGit EnvironmentRepositoryType = "Git"
)
// EnvironmentRepository is the repository for an environment using GitOps
type EnvironmentRepository struct {
Kind EnvironmentRepositoryType `json:"kind,omitempty" protobuf:"bytes,1,opt,name=kind"`
URL string `json:"url,omitempty" protobuf:"bytes,2,opt,name=url"`
Ref string `json:"ref,omitempty" protobuf:"bytes,3,opt,name=ref"`
}
// TeamSettings the default settings for a team
type TeamSettings struct {
UseGitOPs bool `json:"useGitOps,omitempty" protobuf:"bytes,1,opt,name=useGitOps"`
AskOnCreate bool `json:"askOnCreate,omitempty" protobuf:"bytes,1,opt,name=askOnCreate"`
}
// PreviewGitSpec is the preview git branch/pull request details
type PreviewGitSpec struct {
Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"`
URL string `json:"url,omitempty" protobuf:"bytes,2,opt,name=url"`
User UserSpec `json:"user,omitempty" protobuf:"bytes,3,opt,name=user"`
}
// UserSpec is the user details
type UserSpec struct {
Username string `json:"username,omitempty" protobuf:"bytes,1,opt,name=username"`
Name string `json:"name,omitempty" protobuf:"bytes,2,opt,name=name"`
LinkURL string `json:"linkUrl,omitempty" protobuf:"bytes,3,opt,name=linkUrl"`
ImageURL string `json:"imageUrl,omitempty" protobuf:"bytes,4,opt,name=imageUrl"`
}
// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:openapi-gen=true
// PipelineActivity represents pipeline activity for a particular run of a pipeline
type PipelineActivity struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Spec PipelineActivitySpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
Status PipelineActivityStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}
// PipelineActivitySpec is the specification of the pipeline activity
type PipelineActivitySpec struct {
Pipeline string `json:"pipeline,omitempty" protobuf:"bytes,1,opt,name=pipeline"`
Build string `json:"build,omitempty" protobuf:"bytes,2,opt,name=build"`
Version string `json:"version,omitempty" protobuf:"bytes,3,opt,name=version"`
Status ActivityStatusType `json:"status,omitempty" protobuf:"bytes,4,opt,name=status"`
StartedTimestamp *metav1.Time `json:"startedTimestamp,omitempty" protobuf:"bytes,5,opt,name=startedTimestamp"`
CompletedTimestamp *metav1.Time `json:"completedTimestamp,omitempty" protobuf:"bytes,6,opt,name=completedTimestamp"`
Steps []PipelineActivityStep `json:"steps,omitempty" protobuf:"bytes,7,opt,name=steps"`
BuildURL string `json:"buildUrl,omitempty" protobuf:"bytes,8,opt,name=buildUrl"`
BuildLogsURL string `json:"buildLogsUrl,omitempty" protobuf:"bytes,9,opt,name=buildLogsUrl"`
GitURL string `json:"gitUrl,omitempty" protobuf:"bytes,10,opt,name=gitUrl"`
GitRepository string `json:"gitRepository,omitempty" protobuf:"bytes,10,opt,name=gitRepository"`
GitOwner string `json:"gitOwner,omitempty" protobuf:"bytes,10,opt,name=gitOwner"`
ReleaseNotesURL string `json:"releaseNotesURL,omitempty" protobuf:"bytes,11,opt,name=releaseNotesURL"`
}
// PipelineActivityStep represents a step in a pipeline activity
type PipelineActivityStep struct {
Kind ActivityStepKindType `json:"kind,omitempty" protobuf:"bytes,1,opt,name=kind"`
Stage *StageActivityStep `json:"stage,omitempty" protobuf:"bytes,2,opt,name=stage"`
Promote *PromoteActivityStep `json:"promote,omitempty" protobuf:"bytes,3,opt,name=promote"`
}
// CoreActivityStep is a base step included in Stages of a pipeline or other kinds of step
type CoreActivityStep struct {
Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"`
Description string `json:"description,omitempty" protobuf:"bytes,2,opt,name=description"`
Status ActivityStatusType `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
StartedTimestamp *metav1.Time `json:"startedTimestamp,omitempty" protobuf:"bytes,4,opt,name=startedTimestamp"`
CompletedTimestamp *metav1.Time `json:"completedTimestamp,omitempty" protobuf:"bytes,5,opt,name=completedTimestamp"`
}
// StageActivityStep represents a stage of zero to more sub steps in a jenkins pipeline
type StageActivityStep struct {
CoreActivityStep
Steps []CoreActivityStep `json:"steps,omitempty" protobuf:"bytes,1,opt,name=steps"`
}
// PromoteActivityStep is the step of promoting a version of an application to an environment
type PromoteActivityStep struct {
CoreActivityStep
Environment string `json:"environment,omitempty" protobuf:"bytes,1,opt,name=environment"`
PullRequest *PromotePullRequestStep `json:"pullRequest,omitempty" protobuf:"bytes,2,opt,name=pullRequest"`
Update *PromoteUpdateStep `json:"update,omitempty" protobuf:"bytes,3,opt,name=update"`
ApplicationURL string `json:"applicationURL,omitempty" protobuf:"bytes,4,opt,name=environment"`
}
// GitStatus the status of a git commit in terms of CI / CD
type GitStatus struct {
URL string `json:"url,omitempty" protobuf:"bytes,1,opt,name=url"`
Status string `json:"status,omitempty" protobuf:"bytes,2,opt,name=status"`
}
// PromotePullRequestStep is the step for promoting a version to an environment by raising a Pull Request on the
// git repository of the environment
type PromotePullRequestStep struct {
CoreActivityStep
PullRequestURL string `json:"pullRequestURL,omitempty" protobuf:"bytes,1,opt,name=pullRequestURL"`
MergeCommitSHA string `json:"mergeCommitSHA,omitempty" protobuf:"bytes,2,opt,name=mergeCommitSHA"`
}
// PromoteUpdateStep is the step for updating a promotion after the Pull Request merges to master
type PromoteUpdateStep struct {
CoreActivityStep
Statuses []GitStatus `json:"statuses,omitempty" protobuf:"bytes,1,opt,name=statuses"`
}
// PipelineActivityStatus is the status for an Environment resource
type PipelineActivityStatus struct {
Version string `json:"version,omitempty" protobuf:"bytes,1,opt,name=version"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// PipelineActivityList is a list of PipelineActivity resources
type PipelineActivityList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []PipelineActivity `json:"items"`
}
// ActivityStepKindType is a kind of step
type ActivityStepKindType string
const (
// ActivityStepKindTypeNone no kind yet
ActivityStepKindTypeNone ActivityStepKindType = ""
// ActivityStepKindTypeStage a group of low level steps
ActivityStepKindTypeStage ActivityStepKindType = "Stage"
// ActivityStepKindTypePromote a promote activity
ActivityStepKindTypePromote ActivityStepKindType = "Promote"
)
// ActivityStatusType is the status of an activity; usually succeeded or failed/error on completion
type ActivityStatusType string
const (
// ActivityStatusTypeNone an activity step has not started yet
ActivityStatusTypeNone ActivityStatusType = ""
// ActivityStatusTypePending an activity step is waiting to start
ActivityStatusTypePending ActivityStatusType = "Pending"
// ActivityStatusTypeRunning an activity is running
ActivityStatusTypeRunning ActivityStatusType = "Running"
// ActivityStatusTypeSucceeded an activity completed successfully
ActivityStatusTypeSucceeded ActivityStatusType = "Succeeded"
// ActivityStatusTypeFailed an activity failed
ActivityStatusTypeFailed ActivityStatusType = "Failed"
// ActivityStatusTypeWaitingForApproval an activity is waiting for approval
ActivityStatusTypeWaitingForApproval ActivityStatusType = "WaitingForApproval"
// ActivityStatusTypeError there is some error with an activity
ActivityStatusTypeError ActivityStatusType = "Error"
)
func (s ActivityStatusType) String() string {
return string(s)
}
// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:openapi-gen=true
// Release represents a single version of an app that has been released
type Release struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Spec ReleaseSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
Status ReleaseStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ReleaseList is a list of Release resources
type ReleaseList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []Release `json:"items"`
}
// ReleaseSpec is the specification of the Release
type ReleaseSpec struct {
Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"`
Version string `json:"version,omitempty" protobuf:"bytes,2,opt,name=version"`
GitHTTPURL string `json:"gitHttpUrl,omitempty" protobuf:"bytes,3,opt,name=gitHttpUrl"`
GitCloneURL string `json:"gitCloneUrl,omitempty" protobuf:"bytes,4,opt,name=gitCloneUrl"`
Commits []CommitSummary `json:"commits,omitempty" protobuf:"bytes,5,opt,name=commits"`
Issues []IssueSummary `json:"issues,omitempty" protobuf:"bytes,6,opt,name=issues"`
PullRequests []IssueSummary `json:"pullRequests,omitempty" protobuf:"bytes,7,opt,name=pullRequests"`
ReleaseNotesURL string `json:"releaseNotesURL,omitempty" protobuf:"bytes,8,opt,name=releaseNotesURL"`
GitRepository string `json:"gitRepository,omitempty" protobuf:"bytes,9,opt,name=gitRepository"`
GitOwner string `json:"gitOwner,omitempty" protobuf:"bytes,10,opt,name=gitOwner"`
}
// ReleaseStatus is the status of a release
type ReleaseStatus struct {
Status ReleaseStatusType `json:"status,omitempty" protobuf:"bytes,1,opt,name=status"`
}
// IssueSummary is the summary of an issue
type IssueSummary struct {
ID string `json:"id,omitempty" protobuf:"bytes,1,opt,name=id"`
URL string `json:"url,omitempty" protobuf:"bytes,2,opt,name=url"`
Title string `json:"title,omitempty" protobuf:"bytes,3,opt,name=title"`
Body string `json:"body,omitempty" protobuf:"bytes,4,opt,name=body"`
State string `json:"state,omitempty" protobuf:"bytes,5,opt,name=state"`
Message string `json:"message,omitempty" protobuf:"bytes,6,opt,name=message"`
User *UserDetails `json:"user,omitempty" protobuf:"bytes,7,opt,name=user"`
Assignees []UserDetails `json:"assignees,omitempty" protobuf:"bytes,8,opt,name=assignees"`
ClosedBy *UserDetails `json:"closedBy,omitempty" protobuf:"bytes,9,opt,name=closedBy"`
}
// CommitSummary is the summary of a commit
type CommitSummary struct {
Message string `json:"message,omitempty" protobuf:"bytes,1,opt,name=message"`
SHA string `json:"sha,omitempty" protobuf:"bytes,2,opt,name=sha"`
URL string `json:"url,omitempty" protobuf:"bytes,3,opt,name=url"`
Author *UserDetails `json:"author,omitempty" protobuf:"bytes,4,opt,name=author"`
Committer *UserDetails `json:"committer,omitempty" protobuf:"bytes,5,opt,name=committer"`
Branch string `json:"branch,omitempty" protobuf:"bytes,6,opt,name=branch"`
}
// UserDetails containers details of a user
type UserDetails struct {
Login string `json:"login,omitempty" protobuf:"bytes,1,opt,name=login"`
Name string `json:"name,omitempty" protobuf:"bytes,2,opt,name=name"`
Email string `json:"email,omitempty" protobuf:"bytes,3,opt,name=email"`
CreationTimestamp *metav1.Time `json:"creationTimestamp,omitempty" protobuf:"bytes,4,opt,name=creationTimestamp"`
URL string `json:"url,omitempty" protobuf:"bytes,5,opt,name=url"`
AvatarURL string `json:"avatarUrl,omitempty" protobuf:"bytes,6,opt,name=avatarUrl"`
}
// ReleaseStatusType is the status of a release; usually deployed or failed at completion
type ReleaseStatusType string
const (
// ReleaseStatusTypeNone an activity step has not started yet
ReleaseStatusTypeNone ReleaseStatusType = ""
// ReleaseStatusTypePending the release is pending
ReleaseStatusTypePending ReleaseStatusType = "Pending"
// ReleaseStatusTypeDeployed a release has been deployed
ReleaseStatusTypeDeployed ReleaseStatusType = "Deployed"
// ReleaseStatusTypeFailed release failed
ReleaseStatusTypeFailed ReleaseStatusType = "Failed"
)
// IsClosed returns true if this issue is closed or fixed
func (i *IssueSummary) IsClosed() bool {
lower := strings.ToLower(i.State)
return strings.HasPrefix(lower, "clos") || strings.HasPrefix(lower, "fix")
}
// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:openapi-gen=true
// GitService represents a git provider so we can map the host name to a kinda of git service
type GitService struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Spec GitServiceSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
}
// GitServiceSpec is the specification of an GitService
type GitServiceSpec struct {
GitKind string `json:"gitKind,omitempty" protobuf:"bytes,1,opt,name=gitKind"`
Host string `json:"host,omitempty" protobuf:"bytes,2,opt,name=host"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// GitServiceList is a list of GitService resources
type GitServiceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []GitService `json:"items"`
}