-
Notifications
You must be signed in to change notification settings - Fork 1
/
types_pipeline.go
195 lines (163 loc) · 9.17 KB
/
types_pipeline.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
package v1
import (
"strings"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +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"`
LastCommitSHA string `json:"lastCommitSHA,omitempty" protobuf:"bytes,12,opt,name=lastCommitSHA"`
LastCommitMessage string `json:"lastCommitMessage,omitempty" protobuf:"bytes,13,opt,name=lastCommitMessage"`
LastCommitURL string `json:"lastCommitURL,omitempty" protobuf:"bytes,14,opt,name=lastCommitURL"`
Workflow string `json:"workflow,omitempty" protobuf:"bytes,15,opt,name=workflow"`
WorkflowStatus ActivityStatusType `json:"workflowStatus,omitempty" protobuf:"bytes,16,opt,name=workflowStatus"`
WorkflowMessage string `json:"workflowMessage,omitempty" protobuf:"bytes,17,opt,name=workflowMessage"`
}
// 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"`
Preview *PreviewActivityStep `json:"preview,omitempty" protobuf:"bytes,4,opt,name=preview"`
}
// 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"`
}
// PreviewActivityStep is the step of creating a preview environment as part of a Pull Request pipeline
type PreviewActivityStep struct {
CoreActivityStep
Environment string `json:"environment,omitempty" protobuf:"bytes,1,opt,name=environment"`
PullRequestURL string `json:"pullRequestURL,omitempty" protobuf:"bytes,2,opt,name=pullRequestURL"`
ApplicationURL string `json:"applicationURL,omitempty" protobuf:"bytes,3,opt,name=applicationURL"`
}
// 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"
// ActivityStepKindTypePreview a promote activity
ActivityStepKindTypePreview ActivityStepKindType = "Preview"
// 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"
// ActivityStatusTypeAborted if the workflow was aborted
ActivityStatusTypeAborted ActivityStatusType = "Aborted"
)
// IsTerminated returns true if this activity has stopped executing
func (s ActivityStatusType) IsTerminated() bool {
return s == ActivityStatusTypeSucceeded || s == ActivityStatusTypeFailed || s == ActivityStatusTypeError || s == ActivityStatusTypeAborted
}
func (s ActivityStatusType) String() string {
return string(s)
}
// RepositoryName returns the repository name for the given pipeline
func (p *PipelineActivity) RepositoryName() string {
repoName := p.Spec.GitRepository
pipelineName := p.Spec.Pipeline
paths := strings.Split(pipelineName, "/")
if repoName == "" && len(paths) > 1 {
repoName = paths[len(paths)-2]
p.Spec.GitRepository = repoName
}
return repoName
}
// BranchName returns the name of the branch for the pipeline
func (p *PipelineActivity) BranchName() string {
pipelineName := p.Spec.Pipeline
if pipelineName == "" {
return ""
}
paths := strings.Split(pipelineName, "/")
return paths[len(paths)-1]
}