forked from openkruise/kruise
/
uniteddeployment_types.go
263 lines (214 loc) · 10.6 KB
/
uniteddeployment_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
/*
Copyright 2019 The Kruise 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 (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
// UpdateStrategyType is a string enumeration type that enumerates
// all possible update strategies for the UnitedDeployment controller.
type UpdateStrategyType string
const (
// ManualUpdateStrategyType indicates the partition of each subset.
// The update progress is able to be controlled by updating the partitions
// of each subset.
ManualUpdateStrategyType UpdateStrategyType = "Manual"
)
// UnitedDeploymentConditionType indicates valid conditions type of a UnitedDeployment.
type UnitedDeploymentConditionType string
const (
// SubsetProvisioned means all the expected subsets are provisioned and unexpected subsets are deleted.
SubsetProvisioned UnitedDeploymentConditionType = "SubsetProvisioned"
// SubsetUpdated means all the subsets are updated.
SubsetUpdated UnitedDeploymentConditionType = "SubsetUpdated"
// SubsetFailure is added to a UnitedDeployment when one of its subsets has failure during its own reconciling.
SubsetFailure UnitedDeploymentConditionType = "SubsetFailure"
)
// UnitedDeploymentSpec defines the desired state of UnitedDeployment.
type UnitedDeploymentSpec struct {
// Replicas is the total desired replicas of all the subsets.
// If unspecified, defaults to 1.
// +optional
Replicas *int32 `json:"replicas,omitempty"`
// Selector is a label query over pods that should match the replica count.
// It must match the pod template's labels.
Selector *metav1.LabelSelector `json:"selector"`
// Template describes the subset that will be created.
// +optional
Template SubsetTemplate `json:"template,omitempty"`
// Topology describes the pods distribution detail between each of subsets.
// +optional
Topology Topology `json:"topology,omitempty"`
// UpdateStrategy indicates the strategy the UnitedDeployment use to preform the update,
// when template is changed.
// +optional
UpdateStrategy UnitedDeploymentUpdateStrategy `json:"updateStrategy,omitempty"`
// Indicates the number of histories to be conserved.
// If unspecified, defaults to 10.
// +optional
RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty"`
}
// SubsetTemplate defines the subset template under the UnitedDeployment.
// UnitedDeployment will provision every subset based on one workload templates in SubsetTemplate.
type SubsetTemplate struct {
// StatefulSet template
// +optional
StatefulSetTemplate *StatefulSetTemplateSpec `json:"statefulSetTemplate,omitempty"`
// AdvancedStatefulSet template
// +optional
AdvancedStatefulSetTemplate *AdvancedStatefulSetTemplateSpec `json:"advancedStatefulSetTemplate,omitempty"`
}
// StatefulSetTemplateSpec defines the subset template of StatefulSet.
type StatefulSetTemplateSpec struct {
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec appsv1.StatefulSetSpec `json:"spec"`
}
// AdvancedStatefulSetTemplateSpec defines the subset template of AdvancedStatefulSet.
type AdvancedStatefulSetTemplateSpec struct {
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec StatefulSetSpec `json:"spec"`
}
// UnitedDeploymentUpdateStrategy defines the update performance
// when template of UnitedDeployment is changed.
type UnitedDeploymentUpdateStrategy struct {
// Type of UnitedDeployment update strategy.
// Default is Manual.
// +optional
Type UpdateStrategyType `json:"type,omitempty"`
// Includes all of the parameters a Manual update strategy needs.
// +optional
ManualUpdate *ManualUpdate `json:"manualUpdate,omitempty"`
}
// ManualUpdate is a update strategy which allows users to control the update progress
// by providing the partition of each subset.
type ManualUpdate struct {
// Indicates number of subset partition.
// +optional
Partitions map[string]int32 `json:"partitions,omitempty"`
}
// Topology defines the spread detail of each subset under UnitedDeployment.
// A UnitedDeployment manages multiple homogeneous workloads which are called subset.
// Each of subsets under the UnitedDeployment is described in Topology.
type Topology struct {
// Contains the details of each subset. Each element in this array represents one subset
// which will be provisioned and managed by UnitedDeployment.
// +optional
Subsets []Subset `json:"subsets,omitempty"`
}
// Subset defines the detail of a subset.
type Subset struct {
// Indicates subset name as a DNS_LABEL, which will be used to generate
// subset workload name prefix in the format '<deployment-name>-<subset-name>-'.
// Name should be unique between all of the subsets under one UnitedDeployment.
Name string `json:"name"`
// Indicates the node selector to form the subset. Depending on the node selector,
// pods provisioned could be distributed across multiple groups of nodes.
// A subset's nodeSelectorTerm is not allowed to be updated.
// +optional
NodeSelectorTerm corev1.NodeSelectorTerm `json:"nodeSelectorTerm,omitempty"`
// Indicates the tolerations the pods under this subset have.
// A subset's tolerations is not allowed to be updated.
// +optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
// Indicates the number of the pod to be created under this subset. Replicas could also be
// percentage like '10%', which means 10% of UnitedDeployment replicas of pods will be distributed
// under this subset. If nil, the number of replicas in this subset is determined by controller.
// Controller will try to keep all the subsets with nil replicas have average pods.
// +optional
Replicas *intstr.IntOrString `json:"replicas,omitempty"`
}
// UnitedDeploymentStatus defines the observed state of UnitedDeployment.
type UnitedDeploymentStatus struct {
// ObservedGeneration is the most recent generation observed for this UnitedDeployment. It corresponds to the
// UnitedDeployment's generation, which is updated on mutation by the API Server.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// The number of ready replicas.
// +optional
ReadyReplicas int32 `json:"readyReplicas,omitempty"`
// Replicas is the most recently observed number of replicas.
Replicas int32 `json:"replicas"`
// The number of pods in current version.
UpdatedReplicas int32 `json:"updatedReplicas"`
// The number of ready current revision replicas for this UnitedDeployment.
// +optional
UpdatedReadyReplicas int32 `json:"updatedReadyReplicas,omitempty"`
// Count of hash collisions for the UnitedDeployment. The UnitedDeployment controller
// uses this field as a collision avoidance mechanism when it needs to
// create the name for the newest ControllerRevision.
// +optional
CollisionCount *int32 `json:"collisionCount,omitempty"`
// CurrentRevision, if not empty, indicates the current version of the UnitedDeployment.
CurrentRevision string `json:"currentRevision"`
// Records the topology detail information of the replicas of each subset.
// +optional
SubsetReplicas map[string]int32 `json:"subsetReplicas,omitempty"`
// Represents the latest available observations of a UnitedDeployment's current state.
// +optional
Conditions []UnitedDeploymentCondition `json:"conditions,omitempty"`
// Records the information of update progress.
// +optional
UpdateStatus *UpdateStatus `json:"updateStatus,omitempty"`
}
// UnitedDeploymentCondition describes current state of a UnitedDeployment.
type UnitedDeploymentCondition struct {
// Type of in place set condition.
Type UnitedDeploymentConditionType `json:"type,omitempty"`
// Status of the condition, one of True, False, Unknown.
Status corev1.ConditionStatus `json:"status,omitempty"`
// Last time the condition transitioned from one status to another.
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// The reason for the condition's last transition.
Reason string `json:"reason,omitempty"`
// A human readable message indicating details about the transition.
Message string `json:"message,omitempty"`
}
// UpdateStatus defines the observed update state of UnitedDeployment.
type UpdateStatus struct {
// Records the latest revision.
// +optional
UpdatedRevision string `json:"updatedRevision,omitempty"`
// Records the current partition.
// +optional
CurrentPartitions map[string]int32 `json:"currentPartitions,omitempty"`
}
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// UnitedDeployment is the Schema for the uniteddeployments API
// +k8s:openapi-gen=true
// +kubebuilder:subresource:status
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
// +kubebuilder:resource:shortName=ud
// +kubebuilder:printcolumn:name="DESIRED",type="integer",JSONPath=".spec.replicas",description="The desired number of pods."
// +kubebuilder:printcolumn:name="CURRENT",type="integer",JSONPath=".status.replicas",description="The number of currently all pods."
// +kubebuilder:printcolumn:name="UPDATED",type="integer",JSONPath=".status.updatedReplicas",description="The number of pods updated."
// +kubebuilder:printcolumn:name="READY",type="integer",JSONPath=".status.readyReplicas",description="The number of pods ready."
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp",description="CreationTimestamp is a timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is represented in RFC3339 form and is in UTC."
type UnitedDeployment struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec UnitedDeploymentSpec `json:"spec,omitempty"`
Status UnitedDeploymentStatus `json:"status,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// UnitedDeploymentList contains a list of UnitedDeployment.
type UnitedDeploymentList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []UnitedDeployment `json:"items"`
}
func init() {
SchemeBuilder.Register(&UnitedDeployment{}, &UnitedDeploymentList{})
}