Skip to content

Commit 089bf48

Browse files
authored
feat(validation): cannot overlay pod labels starting with pingcap.com/ (#6216)
1 parent 8f3ac3a commit 089bf48

22 files changed

+115
-0
lines changed

api/core/v1alpha1/common_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ type Overlay struct {
194194
}
195195

196196
type PodOverlay struct {
197+
// +kubebuilder:validation:XValidation:rule="!has(self.labels) || self.labels.all(key, !key.startsWith('pingcap.com/'))",message="cannot overlay pod labels starting with 'pingcap.com/'"
197198
ObjectMeta `json:"metadata,omitempty"`
198199
Spec *corev1.PodSpec `json:"spec,omitempty"`
199200
}

manifests/crd/core.pingcap.com_pdgroups.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ spec:
232232
More info: http://kubernetes.io/docs/user-guide/identifiers#names
233233
type: string
234234
type: object
235+
x-kubernetes-validations:
236+
- message: cannot overlay pod labels starting with
237+
'pingcap.com/'
238+
rule: '!has(self.labels) || self.labels.all(key,
239+
!key.startsWith(''pingcap.com/''))'
235240
spec:
236241
description: PodSpec is a description of a pod.
237242
properties:

manifests/crd/core.pingcap.com_pds.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ spec:
127127
More info: http://kubernetes.io/docs/user-guide/identifiers#names
128128
type: string
129129
type: object
130+
x-kubernetes-validations:
131+
- message: cannot overlay pod labels starting with 'pingcap.com/'
132+
rule: '!has(self.labels) || self.labels.all(key, !key.startsWith(''pingcap.com/''))'
130133
spec:
131134
description: PodSpec is a description of a pod.
132135
properties:

manifests/crd/core.pingcap.com_schedulergroups.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ spec:
218218
More info: http://kubernetes.io/docs/user-guide/identifiers#names
219219
type: string
220220
type: object
221+
x-kubernetes-validations:
222+
- message: cannot overlay pod labels starting with
223+
'pingcap.com/'
224+
rule: '!has(self.labels) || self.labels.all(key,
225+
!key.startsWith(''pingcap.com/''))'
221226
spec:
222227
description: PodSpec is a description of a pod.
223228
properties:

manifests/crd/core.pingcap.com_schedulers.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ spec:
119119
More info: http://kubernetes.io/docs/user-guide/identifiers#names
120120
type: string
121121
type: object
122+
x-kubernetes-validations:
123+
- message: cannot overlay pod labels starting with 'pingcap.com/'
124+
rule: '!has(self.labels) || self.labels.all(key, !key.startsWith(''pingcap.com/''))'
122125
spec:
123126
description: PodSpec is a description of a pod.
124127
properties:

manifests/crd/core.pingcap.com_ticdcgroups.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ spec:
213213
More info: http://kubernetes.io/docs/user-guide/identifiers#names
214214
type: string
215215
type: object
216+
x-kubernetes-validations:
217+
- message: cannot overlay pod labels starting with
218+
'pingcap.com/'
219+
rule: '!has(self.labels) || self.labels.all(key,
220+
!key.startsWith(''pingcap.com/''))'
216221
spec:
217222
description: PodSpec is a description of a pod.
218223
properties:

manifests/crd/core.pingcap.com_ticdcs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ spec:
116116
More info: http://kubernetes.io/docs/user-guide/identifiers#names
117117
type: string
118118
type: object
119+
x-kubernetes-validations:
120+
- message: cannot overlay pod labels starting with 'pingcap.com/'
121+
rule: '!has(self.labels) || self.labels.all(key, !key.startsWith(''pingcap.com/''))'
119122
spec:
120123
description: PodSpec is a description of a pod.
121124
properties:

manifests/crd/core.pingcap.com_tidbgroups.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ spec:
240240
More info: http://kubernetes.io/docs/user-guide/identifiers#names
241241
type: string
242242
type: object
243+
x-kubernetes-validations:
244+
- message: cannot overlay pod labels starting with
245+
'pingcap.com/'
246+
rule: '!has(self.labels) || self.labels.all(key,
247+
!key.startsWith(''pingcap.com/''))'
243248
spec:
244249
description: PodSpec is a description of a pod.
245250
properties:

manifests/crd/core.pingcap.com_tidbs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ spec:
117117
More info: http://kubernetes.io/docs/user-guide/identifiers#names
118118
type: string
119119
type: object
120+
x-kubernetes-validations:
121+
- message: cannot overlay pod labels starting with 'pingcap.com/'
122+
rule: '!has(self.labels) || self.labels.all(key, !key.startsWith(''pingcap.com/''))'
120123
spec:
121124
description: PodSpec is a description of a pod.
122125
properties:

manifests/crd/core.pingcap.com_tiflashes.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ spec:
149149
More info: http://kubernetes.io/docs/user-guide/identifiers#names
150150
type: string
151151
type: object
152+
x-kubernetes-validations:
153+
- message: cannot overlay pod labels starting with 'pingcap.com/'
154+
rule: '!has(self.labels) || self.labels.all(key, !key.startsWith(''pingcap.com/''))'
152155
spec:
153156
description: PodSpec is a description of a pod.
154157
properties:

manifests/crd/core.pingcap.com_tiflashgroups.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ spec:
242242
More info: http://kubernetes.io/docs/user-guide/identifiers#names
243243
type: string
244244
type: object
245+
x-kubernetes-validations:
246+
- message: cannot overlay pod labels starting with
247+
'pingcap.com/'
248+
rule: '!has(self.labels) || self.labels.all(key,
249+
!key.startsWith(''pingcap.com/''))'
245250
spec:
246251
description: PodSpec is a description of a pod.
247252
properties:

manifests/crd/core.pingcap.com_tikvgroups.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ spec:
216216
More info: http://kubernetes.io/docs/user-guide/identifiers#names
217217
type: string
218218
type: object
219+
x-kubernetes-validations:
220+
- message: cannot overlay pod labels starting with
221+
'pingcap.com/'
222+
rule: '!has(self.labels) || self.labels.all(key,
223+
!key.startsWith(''pingcap.com/''))'
219224
spec:
220225
description: PodSpec is a description of a pod.
221226
properties:

manifests/crd/core.pingcap.com_tikvs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ spec:
121121
More info: http://kubernetes.io/docs/user-guide/identifiers#names
122122
type: string
123123
type: object
124+
x-kubernetes-validations:
125+
- message: cannot overlay pod labels starting with 'pingcap.com/'
126+
rule: '!has(self.labels) || self.labels.all(key, !key.startsWith(''pingcap.com/''))'
124127
spec:
125128
description: PodSpec is a description of a pod.
126129
properties:

manifests/crd/core.pingcap.com_tiproxies.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ spec:
117117
More info: http://kubernetes.io/docs/user-guide/identifiers#names
118118
type: string
119119
type: object
120+
x-kubernetes-validations:
121+
- message: cannot overlay pod labels starting with 'pingcap.com/'
122+
rule: '!has(self.labels) || self.labels.all(key, !key.startsWith(''pingcap.com/''))'
120123
spec:
121124
description: PodSpec is a description of a pod.
122125
properties:

manifests/crd/core.pingcap.com_tiproxygroups.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ spec:
216216
More info: http://kubernetes.io/docs/user-guide/identifiers#names
217217
type: string
218218
type: object
219+
x-kubernetes-validations:
220+
- message: cannot overlay pod labels starting with
221+
'pingcap.com/'
222+
rule: '!has(self.labels) || self.labels.all(key,
223+
!key.startsWith(''pingcap.com/''))'
219224
spec:
220225
description: PodSpec is a description of a pod.
221226
properties:

manifests/crd/core.pingcap.com_tsogroups.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ spec:
218218
More info: http://kubernetes.io/docs/user-guide/identifiers#names
219219
type: string
220220
type: object
221+
x-kubernetes-validations:
222+
- message: cannot overlay pod labels starting with
223+
'pingcap.com/'
224+
rule: '!has(self.labels) || self.labels.all(key,
225+
!key.startsWith(''pingcap.com/''))'
221226
spec:
222227
description: PodSpec is a description of a pod.
223228
properties:

manifests/crd/core.pingcap.com_tsos.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ spec:
118118
More info: http://kubernetes.io/docs/user-guide/identifiers#names
119119
type: string
120120
type: object
121+
x-kubernetes-validations:
122+
- message: cannot overlay pod labels starting with 'pingcap.com/'
123+
rule: '!has(self.labels) || self.labels.all(key, !key.startsWith(''pingcap.com/''))'
121124
spec:
122125
description: PodSpec is a description of a pod.
123126
properties:

tests/validation/common_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,45 @@ func Topology() []Case {
170170

171171
return cases
172172
}
173+
174+
func PodOverlayLabels() []Case {
175+
cases := []Case{
176+
{
177+
desc: "no label overlay is ok",
178+
isCreate: true,
179+
current: map[string]any{},
180+
},
181+
{
182+
desc: "ok to overlay normal labels",
183+
isCreate: true,
184+
current: map[string]any{
185+
"labels": map[string]any{
186+
"component": "bbb",
187+
},
188+
},
189+
},
190+
{
191+
desc: "cannot overlay pingcap.com/xxx labels",
192+
isCreate: true,
193+
current: map[string]any{
194+
"labels": map[string]any{
195+
"pingcap.com/xxx": "bbb",
196+
},
197+
},
198+
wantErrs: []string{
199+
`spec.overlay.pod.metadata: Invalid value: "object": cannot overlay pod labels starting with 'pingcap.com/'`,
200+
},
201+
},
202+
{
203+
desc: "ok to overlay pingcap.com label",
204+
isCreate: true,
205+
current: map[string]any{
206+
"labels": map[string]any{
207+
"pingcap.com": "bbb",
208+
},
209+
},
210+
},
211+
}
212+
213+
return cases
214+
}

tests/validation/pd_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func TestPD(t *testing.T) {
3030
transferPDCases(t, ClusterReference(), "spec", "cluster")...)
3131
cases = append(cases,
3232
transferPDCases(t, PDMode(), "spec", "mode")...)
33+
cases = append(cases,
34+
transferPDCases(t, PodOverlayLabels(), "spec", "overlay", "pod", "metadata")...)
3335

3436
Validate(t, "crd/core.pingcap.com_pds.yaml", cases)
3537
}

tests/validation/scheduler_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ func TestScheduler(t *testing.T) {
2727
transferSchedulerCases(t, Topology(), "spec", "topology"),
2828
transferSchedulerCases(t, ClusterReference(), "spec", "cluster")...,
2929
)
30+
cases = append(cases,
31+
transferSchedulerCases(t, PodOverlayLabels(), "spec", "overlay", "pod", "metadata")...)
3032

3133
Validate(t, "crd/core.pingcap.com_schedulers.yaml", cases)
3234
}

tests/validation/tidb_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ func TestTiDB(t *testing.T) {
2727
cases = append(cases, transferTiDBCases(t, Topology(), "spec", "topology")...)
2828
cases = append(cases, transferTiDBCases(t, ClusterReference(), "spec", "cluster")...)
2929
cases = append(cases, transferTiDBCases(t, serverLabels(), "spec", "server", "labels")...)
30+
cases = append(cases,
31+
transferTiDBCases(t, PodOverlayLabels(), "spec", "overlay", "pod", "metadata")...)
3032

3133
Validate(t, "crd/core.pingcap.com_tidbs.yaml", cases)
3234
}

tests/validation/tso_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ func TestTSO(t *testing.T) {
2727
transferTSOCases(t, Topology(), "spec", "topology"),
2828
transferTSOCases(t, ClusterReference(), "spec", "cluster")...,
2929
)
30+
cases = append(cases,
31+
transferTSOCases(t, PodOverlayLabels(), "spec", "overlay", "pod", "metadata")...)
3032

3133
Validate(t, "crd/core.pingcap.com_tsos.yaml", cases)
3234
}

0 commit comments

Comments
 (0)