-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrolloutrun_types.go
More file actions
259 lines (220 loc) · 9.53 KB
/
Copy pathrolloutrun_types.go
File metadata and controls
259 lines (220 loc) · 9.53 KB
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
// Copyright 2023 The KusionStack 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 (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
// +genclient
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:storageversion
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=ror
// +kubebuilder:printcolumn:name="OWNER",type="string",JSONPath=".metadata.ownerReferences[0].name"
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="Canary State",type="string",JSONPath=".status.canaryStatus.state"
// +kubebuilder:printcolumn:name="Batch Index",type="string",JSONPath=".status.batchStatus.currentBatchIndex"
// +kubebuilder:printcolumn:name="Batch State",type="string",JSONPath=".status.batchStatus.currentBatchState"
// +kubebuilder:printcolumn:name="Error",type="string",JSONPath=".status.error.code"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp",format="date-time"
type RolloutRun struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec RolloutRunSpec `json:"spec,omitempty"`
Status RolloutRunStatus `json:"status,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// RolloutList contains a list of Rollout
type RolloutRunList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []RolloutRun `json:"items"`
}
type RolloutRunSpec struct {
// TargetType defines the GroupVersionKind of target resource
TargetType ObjectTypeRef `json:"targetType,omitempty"`
// Webhooks defines rollout webhook configuration
Webhooks []RolloutWebhook `json:"webhooks,omitempty"`
// TrafficTopologyRefs defines the networking traffic relationships between
// workloads, backend services, and routes.
TrafficTopologyRefs []string `json:"trafficTopologyRefs,omitempty"`
// Canary defines the canary strategy
// +optional
Canary *RolloutRunCanaryStrategy `json:"canary,omitempty"`
// Batch Strategy
// +optional
Batch *RolloutRunBatchStrategy `json:"batch,omitempty"`
// Rollback Strategy
// +optional
Rollback *RolloutRunRollbackStrategy `json:"rollback,omitempty"`
}
type RolloutRunBatchStrategy struct {
// Batches define the order of phases to execute release in batch release
Batches []RolloutRunStep `json:"batches,omitempty"`
// Toleration is the toleration policy of the canary strategy
// +optional
Toleration *TolerationStrategy `json:"toleration,omitempty"`
}
type RolloutRunRollbackStrategy struct {
// Batches define the order of phases to execute release in rollback release
Batches []RolloutRunRollbackStep `json:"batches,omitempty"`
}
type RolloutRunStep struct {
// desired target replicas
Targets []RolloutRunStepTarget `json:"targets"`
// traffic strategy
// +optional
Traffic *TrafficStrategy `json:"traffic,omitempty"`
// If set to true, the rollout will be paused before the step starts.
// +optional
Breakpoint bool `json:"breakpoint,omitempty"`
// Properties contains additional information for step
// +optional
Properties map[string]string `json:"properties,omitempty"`
}
type RolloutRunRollbackStep struct {
// desired target replicas
Targets []RolloutRunStepTarget `json:"targets"`
// If set to true, the rollout will be paused before the step starts.
// +optional
Breakpoint bool `json:"breakpoint,omitempty"`
// Properties contains additional information for step.
// +optional
Properties map[string]string `json:"properties,omitempty"`
}
type RolloutRunCanaryStrategy struct {
// desired target replicas
Targets []RolloutRunStepTarget `json:"targets"`
// traffic strategy
// +optional
Traffic *TrafficStrategy `json:"traffic,omitempty"`
// Properties contains additional information for step
// +optional
Properties map[string]string `json:"properties,omitempty"`
// PodTemplateMetadataPatch defines a patch for workload podTemplate metadata.
// +optional
TemplateMetadataPatch *MetadataPatch `json:"podTemplateMetadataPatch,omitempty"`
}
type RolloutRunStepTarget struct {
CrossClusterObjectNameReference `json:",inline"`
// Replicas is the replicas of the rollout task, which represents the number of pods to be upgraded
Replicas intstr.IntOrString `json:"replicas"`
// ReplicaSlidingWindow used to control the number of pods that are allowed to be upgraded in
// a sliding window for progressive rollout smoothly.
// +optional
ReplicaSlidingWindow *intstr.IntOrString `json:"replicaSlidingWindow,omitempty"`
}
type RolloutRunStatus struct {
// ObservedGeneration is the most recent generation observed for this Rollout. It corresponds to the
// Rollout's generation, which is updated on mutation by the API Server.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// Conditions is the list of conditions
Conditions []Condition `json:"conditions,omitempty"`
// Phase indecates the current phase of rollout
Phase RolloutRunPhase `json:"phase,omitempty"`
// The last time this status was updated.
// +optional
LastUpdateTime *metav1.Time `json:"lastUpdateTime,omitempty"`
// Error indicates the error info of progressing
Error *CodeReasonMessage `json:"error,omitempty"`
// CanaryStatus describes the state of the active canary release
// +optional
CanaryStatus *RolloutRunStepStatus `json:"canaryStatus,omitempty"`
// BatchStatus describes the state of the active batch release
// +optional
BatchStatus *RolloutRunBatchStatus `json:"batchStatus,omitempty"`
// RollbackStatus describes the state of the active rollback release
// +optional
RollbackStatus *RolloutRunBatchStatus `json:"rollbackStatus,omitempty"`
// TargetStatuses describes the referenced workloads status
// +optional
TargetStatuses []RolloutWorkloadStatus `json:"targetStatuses,omitempty"`
}
type RolloutRunBatchStatus struct {
// RolloutBatchStatus contains status of current batch
RolloutBatchStatus `json:",inline"`
// Records contains all batches status details.
Records []RolloutRunStepStatus `json:"records,omitempty"`
}
type RolloutRunPhase string
const (
// RolloutRunPhaseInitial defines the initial phase of rolloutRun
RolloutRunPhaseInitial RolloutRunPhase = "Initial"
// RolloutRunPhasePreRollout defines the phase of rolloutRun before rollout
RolloutRunPhasePreRollout RolloutRunPhase = "PreRollout"
// RolloutRunPhasePausing defines the phase of rolloutRun pausing
RolloutRunPhasePausing RolloutRunPhase = "Pausing"
// RolloutRunPhasePaused defines the phase of rolloutRun paused
RolloutRunPhasePaused RolloutRunPhase = "Paused"
// RolloutRunPhaseProgressing defines the phase of rolloutRun progressing
RolloutRunPhaseProgressing RolloutRunPhase = "Progressing"
// RolloutRunPhasePostRollout defines the phase of rollout after progressing
RolloutRunPhasePostRollout RolloutRunPhase = "PostRollout"
// RolloutRunPhaseCanceling defines the phase of rolloutRun canceling
RolloutRunPhaseCanceling RolloutRunPhase = "Canceling"
// RolloutRunPhaseCanceled defines the phase of rolloutRun canceled
RolloutRunPhaseCanceled RolloutRunPhase = "Canceled"
// RolloutRunPhaseRollbacking defines the phase of rolloutRun rollbacking
RolloutRunPhaseRollbacking RolloutRunPhase = "Rollbacking"
// RolloutRunPhaseRollbacked defines the phase of rolloutRun rollbacked
RolloutRunPhaseRollbacked RolloutRunPhase = "Rollbacked"
// RolloutRunPhaseSucceeded defines the phase of rolloutRun succeeded
RolloutRunPhaseSucceeded RolloutRunPhase = "Succeeded"
)
type RolloutRunStepStatus struct {
// Index is the id of the batch
Index *int32 `json:"index,omitempty"`
// State is Rollout step state
State RolloutStepState `json:"state,omitempty"`
// StartTime is the time when the stage started
// +optional
StartTime *metav1.Time `json:"startTime,omitempty"`
// FinishTime is the time when the stage finished
// +optional
FinishTime *metav1.Time `json:"finishTime,omitempty"`
// WorkloadDetails contains release details for each workload
// +optional
Targets []RolloutWorkloadStatus `json:"targets,omitempty"`
// Webhooks contains webhook status
// +optional
Webhooks []RolloutWebhookStatus `json:"webhooks,omitempty"`
}
type RolloutWebhookStatus struct {
// Current webhook worker state
State RolloutWebhookState `json:"state,omitempty"`
// Webhook Type
HookType HookType `json:"hookType,omitempty"`
// Webhook Name
Name string `json:"name,omitempty"`
// Webhook result
CodeReasonMessage `json:",inline"`
// Failure count
FailureCount int32 `json:"failureCount,omitempty"`
}
// RolloutWebhookState indicates current state of webhook webhook.
type RolloutWebhookState string
const (
WebhookRunning RolloutWebhookState = "Running"
WebhookOnHold RolloutWebhookState = "OnHold"
WebhookCompleted RolloutWebhookState = "Completed"
)
func (r *RolloutRun) IsCompleted() bool {
if r == nil {
return false
}
return r.Status.Phase == RolloutRunPhaseSucceeded || r.Status.Phase == RolloutRunPhaseCanceled || r.Status.Phase == RolloutRunPhaseRollbacked
}