You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apis/placement/v1/clusterresourceplacement_types.go
+35Lines changed: 35 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -51,12 +51,15 @@ import (
51
51
//
52
52
// `ClusterSchedulingPolicySnapshot` and `ClusterResourceSnapshot` objects are created when there are changes in the
53
53
// system to keep the history of the changes affecting a `ClusterResourcePlacement`.
54
+
// +kubebuilder:validation:XValidation:rule="size(self.metadata.name) <= 63",message="name must not exceed 63 characters"
54
55
typeClusterResourcePlacementstruct {
55
56
metav1.TypeMeta`json:",inline"`
56
57
metav1.ObjectMeta`json:"metadata,omitempty"`
57
58
58
59
// The desired state of ClusterResourcePlacement.
59
60
// +required
61
+
// +kubebuilder:validation:XValidation:rule="!(has(oldSelf.policy) && !has(self.policy) && oldSelf.policy.placementType != 'PickAll')",message="policy cannot be removed once set"
62
+
// +kubebuilder:validation:XValidation:rule="has(oldSelf.policy) || !has(self.policy) || self.policy.placementType == 'PickAll'",message="placement type is immutable"
60
63
SpecClusterResourcePlacementSpec`json:"spec"`
61
64
62
65
// The observed status of ClusterResourcePlacement.
@@ -77,6 +80,7 @@ type ClusterResourcePlacementSpec struct {
77
80
// Policy defines how to select member clusters to place the selected resources.
78
81
// If unspecified, all the joined member clusters are selected.
79
82
// +optional
83
+
// +kubebuilder:validation:XValidation:rule="self.placementType == oldSelf.placementType",message="placement type is immutable"
80
84
Policy*PlacementPolicy`json:"policy,omitempty"`
81
85
82
86
// The rollout strategy to use to replace existing placement with new ones.
@@ -97,6 +101,7 @@ type ClusterResourcePlacementSpec struct {
97
101
// ClusterResourceSelector is used to select cluster scoped resources as the target resources to be placed.
98
102
// If a namespace is selected, ALL the resources under the namespace are selected automatically.
99
103
// All the fields are `ANDed`. In other words, a resource must match all the fields to be selected.
104
+
// +kubebuilder:validation:XValidation:rule="!has(self.labelSelector) || !has(self.name) || size(self.name) == 0",message="labelSelector and name are mutually exclusive"
100
105
typeClusterResourceSelectorstruct {
101
106
// Group name of the cluster-scoped resource.
102
107
// Use an empty string to select resources under the core API group (e.g., namespaces).
@@ -130,6 +135,19 @@ type ClusterResourceSelector struct {
130
135
//
131
136
// You can only specify at most one of the two fields: ClusterNames and Affinity.
132
137
// If none is specified, all the joined clusters are selected.
138
+
//
139
+
// +kubebuilder:validation:XValidation:rule="self.placementType != 'PickFixed' || (has(self.clusterNames) && size(self.clusterNames) > 0)",message="clusterNames cannot be empty for PickFixed placement type"
140
+
// +kubebuilder:validation:XValidation:rule="self.placementType != 'PickFixed' || !has(self.numberOfClusters)",message="numberOfClusters must not be set for PickFixed placement type"
141
+
// +kubebuilder:validation:XValidation:rule="self.placementType != 'PickFixed' || !has(self.affinity)",message="affinity must not be set for PickFixed placement type"
142
+
// +kubebuilder:validation:XValidation:rule="self.placementType != 'PickFixed' || !has(self.topologySpreadConstraints) || size(self.topologySpreadConstraints) == 0",message="topologySpreadConstraints must be empty for PickFixed placement type"
143
+
// +kubebuilder:validation:XValidation:rule="self.placementType != 'PickFixed' || !has(self.tolerations) || size(self.tolerations) == 0",message="tolerations must be empty for PickFixed placement type"
144
+
// +kubebuilder:validation:XValidation:rule="self.placementType != 'PickAll' || !has(self.clusterNames) || size(self.clusterNames) == 0",message="clusterNames must be empty for PickAll placement type"
145
+
// +kubebuilder:validation:XValidation:rule="self.placementType != 'PickAll' || !has(self.numberOfClusters)",message="numberOfClusters must not be set for PickAll placement type"
146
+
// +kubebuilder:validation:XValidation:rule="self.placementType != 'PickAll' || !has(self.topologySpreadConstraints) || size(self.topologySpreadConstraints) == 0",message="topologySpreadConstraints must be empty for PickAll placement type"
147
+
// +kubebuilder:validation:XValidation:rule="self.placementType != 'PickAll' || !has(self.affinity) || !has(self.affinity.clusterAffinity) || !has(self.affinity.clusterAffinity.preferredDuringSchedulingIgnoredDuringExecution) || size(self.affinity.clusterAffinity.preferredDuringSchedulingIgnoredDuringExecution) == 0",message="preferredDuringSchedulingIgnoredDuringExecution is not allowed for PickAll placement type"
148
+
// +kubebuilder:validation:XValidation:rule="self.placementType != 'PickN' || !has(self.clusterNames) || size(self.clusterNames) == 0",message="clusterNames must be empty for PickN placement type"
149
+
// +kubebuilder:validation:XValidation:rule="self.placementType != 'PickN' || has(self.numberOfClusters)",message="numberOfClusters must be set for PickN placement type"
150
+
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.tolerations) || oldSelf.tolerations.all(t, has(self.tolerations) && self.tolerations.exists(nt, nt == t))",message="tolerations have been updated/deleted, only additions to tolerations are allowed"
133
151
typePlacementPolicystruct {
134
152
// Type of placement. Can be "PickAll", "PickN" or "PickFixed". Default is PickAll.
// +kubebuilder:validation:XValidation:rule="self.clusterSelectorTerms.all(t, !has(t.propertySorter))",message="propertySorter is not allowed in requiredDuringSchedulingIgnoredDuringExecution affinity terms"
203
223
typeClusterSelectorstruct {
204
224
// +kubebuilder:validation:MaxItems=10
205
225
// ClusterSelectorTerms is a list of cluster selector terms. The terms are `ORed`.
// +kubebuilder:validation:XValidation:rule="!has(self.preference.propertySelector)",message="propertySelector is not allowed in preferredDuringSchedulingIgnoredDuringExecution affinity terms"
210
231
typePreferredClusterSelectorstruct {
211
232
// Weight associated with matching the corresponding clusterSelectorTerm, in the range [-100, 100].
212
233
// +required
@@ -286,6 +307,7 @@ const (
286
307
typePropertySelectorRequirementstruct {
287
308
// Name is the name of the property; it should be a Kubernetes label name.
288
309
// +required
310
+
// +kubebuilder:validation:MaxLength=317
289
311
Namestring`json:"name"`
290
312
291
313
// Operator specifies the relationship between a cluster's observed value of the specified
@@ -304,6 +326,7 @@ type PropertySelectorRequirement struct {
304
326
// or `Le` (less than or equal to), Eq (equal to), or Ne (ne), exactly one value must be
305
327
// specified in the list.
306
328
//
329
+
// +kubebuilder:validation:MinItems=1
307
330
// +kubebuilder:validation:MaxItems=1
308
331
// +required
309
332
Values []string`json:"values"`
@@ -321,10 +344,12 @@ type PropertySelector struct {
321
344
typePropertySorterstruct {
322
345
// Name is the name of the property which Fleet sorts clusters by.
323
346
// +required
347
+
// +kubebuilder:validation:MaxLength=317
324
348
Namestring`json:"name"`
325
349
326
350
// SortOrder explains how Fleet should perform the sort; specifically, whether Fleet should
// and whether it's allowed to be co-owned by other non-fleet appliers.
432
458
// Note: If multiple CRPs try to place the same resource with different apply strategy, the later ones will fail with the
433
459
// reason ApplyConflictBetweenPlacements.
460
+
// +kubebuilder:validation:XValidation:rule="self.type == 'ServerSideApply' || !has(self.serverSideApplyConfig)",message="serverSideApplyConfig is only valid for ServerSideApply strategy type"
434
461
typeApplyStrategystruct {
435
462
// ComparisonOption controls how Fleet compares the desired state of a resource, as kept in
436
463
// a hub cluster manifest, with the current state of the resource (if applicable) in the
@@ -793,6 +820,7 @@ type RollingUpdateConfig struct {
793
820
// have passed since they were successfully applied to the target cluster.
@@ -1052,9 +1080,15 @@ type DiffedResourcePlacement struct {
1052
1080
1053
1081
// Toleration allows ClusterResourcePlacement to tolerate any taint that matches
1054
1082
// the triple <key,value,effect> using the matching operator <operator>.
1083
+
// +kubebuilder:validation:XValidation:rule="self.operator != 'Exists' || !has(self.value) || size(self.value) == 0",message="value must be empty when operator is Exists"
1084
+
// +kubebuilder:validation:XValidation:rule="self.operator != 'Equal' || (has(self.key) && size(self.key) > 0)",message="key must not be empty when operator is Equal"
1085
+
// +kubebuilder:validation:XValidation:rule="!has(self.key) || size(self.key) == 0 || self.key.matches('^([a-z0-9]([-a-z0-9]*[a-z0-9])?([.][a-z0-9]([-a-z0-9]*[a-z0-9])?)*[/])?[a-zA-Z0-9]([a-zA-Z0-9._-]*[a-zA-Z0-9])?$')",message="toleration key must be a valid qualified name"
1086
+
// +kubebuilder:validation:XValidation:rule="!has(self.key) || size(self.key) == 0 || self.key.matches('^([^/]+/)?[a-zA-Z0-9]([a-zA-Z0-9._-]{0,61}[a-zA-Z0-9])?$')",message="toleration key name segment must not exceed 63 characters"
1087
+
// +kubebuilder:validation:XValidation:rule="!has(self.value) || size(self.value) == 0 || self.value.matches('^[a-zA-Z0-9]([a-zA-Z0-9._-]*[a-zA-Z0-9])?$')",message="toleration value must be a valid label value"
1055
1088
typeTolerationstruct {
1056
1089
// Key is the taint key that the toleration applies to. Empty means match all taint keys.
1057
1090
// If the key is empty, operator must be Exists; this combination means to match all values and all keys.
1091
+
// +kubebuilder:validation:MaxLength=317
1058
1092
// +optional
1059
1093
Keystring`json:"key,omitempty"`
1060
1094
@@ -1069,6 +1103,7 @@ type Toleration struct {
1069
1103
1070
1104
// Value is the taint value the toleration matches to.
1071
1105
// If the operator is Exists, the value should be empty, otherwise just a regular string.
0 commit comments