@@ -148,6 +148,11 @@ func getCodecForObject(obj runtime.Object) (runtime.Codec, error) {
148
148
}
149
149
150
150
func validateObject (obj runtime.Object ) (errors field.ErrorList ) {
151
+ podValidationOptions := validation.PodValidationOptions {
152
+ AllowMultipleHugePageResources : true ,
153
+ AllowDownwardAPIHugePages : true ,
154
+ }
155
+
151
156
// Enable CustomPodDNS for testing
152
157
// feature.DefaultFeatureGate.Set("CustomPodDNS=true")
153
158
switch t := obj .(type ) {
@@ -182,7 +187,7 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
182
187
opts := validation.PodValidationOptions {
183
188
AllowMultipleHugePageResources : true ,
184
189
}
185
- errors = validation .ValidatePod (t , opts )
190
+ errors = validation .ValidatePodCreate (t , opts )
186
191
case * api.PodList :
187
192
for i := range t .Items {
188
193
errors = append (errors , validateObject (& t .Items [i ])... )
@@ -191,12 +196,12 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
191
196
if t .Namespace == "" {
192
197
t .Namespace = api .NamespaceDefault
193
198
}
194
- errors = validation .ValidatePodTemplate (t )
199
+ errors = validation .ValidatePodTemplate (t , podValidationOptions )
195
200
case * api.ReplicationController :
196
201
if t .Namespace == "" {
197
202
t .Namespace = api .NamespaceDefault
198
203
}
199
- errors = validation .ValidateReplicationController (t )
204
+ errors = validation .ValidateReplicationController (t , podValidationOptions )
200
205
case * api.ReplicationControllerList :
201
206
for i := range t .Items {
202
207
errors = append (errors , validateObject (& t .Items [i ])... )
@@ -215,7 +220,11 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
215
220
if t .Namespace == "" {
216
221
t .Namespace = api .NamespaceDefault
217
222
}
218
- errors = validation .ValidateService (t , true )
223
+ // handle clusterIPs, logic copied from service strategy
224
+ if len (t .Spec .ClusterIP ) > 0 && len (t .Spec .ClusterIPs ) == 0 {
225
+ t .Spec .ClusterIPs = []string {t .Spec .ClusterIP }
226
+ }
227
+ errors = validation .ValidateService (t )
219
228
case * api.ServiceAccount :
220
229
if t .Namespace == "" {
221
230
t .Namespace = api .NamespaceDefault
@@ -250,12 +259,12 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
250
259
if t .Namespace == "" {
251
260
t .Namespace = api .NamespaceDefault
252
261
}
253
- errors = apps_validation .ValidateDaemonSet (t )
262
+ errors = apps_validation .ValidateDaemonSet (t , podValidationOptions )
254
263
case * apps.Deployment :
255
264
if t .Namespace == "" {
256
265
t .Namespace = api .NamespaceDefault
257
266
}
258
- errors = apps_validation .ValidateDeployment (t )
267
+ errors = apps_validation .ValidateDeployment (t , podValidationOptions )
259
268
case * networking.Ingress :
260
269
if t .Namespace == "" {
261
270
t .Namespace = api .NamespaceDefault
@@ -265,18 +274,30 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
265
274
Version : legacyscheme .Scheme .PrioritizedVersionsForGroup (networking .GroupName )[0 ].Version ,
266
275
}
267
276
errors = networking_validation .ValidateIngressCreate (t , gv )
277
+ case * networking.IngressClass :
278
+ /*
279
+ if t.Namespace == "" {
280
+ t.Namespace = api.NamespaceDefault
281
+ }
282
+ gv := schema.GroupVersion{
283
+ Group: networking.GroupName,
284
+ Version: legacyscheme.Scheme.PrioritizedVersionsForGroup(networking.GroupName)[0].Version,
285
+ }
286
+ */
287
+ errors = networking_validation .ValidateIngressClass (t )
288
+
268
289
case * policy.PodSecurityPolicy :
269
290
errors = policy_validation .ValidatePodSecurityPolicy (t )
270
291
case * apps.ReplicaSet :
271
292
if t .Namespace == "" {
272
293
t .Namespace = api .NamespaceDefault
273
294
}
274
- errors = apps_validation .ValidateReplicaSet (t )
295
+ errors = apps_validation .ValidateReplicaSet (t , podValidationOptions )
275
296
case * batch.CronJob :
276
297
if t .Namespace == "" {
277
298
t .Namespace = api .NamespaceDefault
278
299
}
279
- errors = batch_validation .ValidateCronJob (t )
300
+ errors = batch_validation .ValidateCronJob (t , podValidationOptions )
280
301
case * networking.NetworkPolicy :
281
302
if t .Namespace == "" {
282
303
t .Namespace = api .NamespaceDefault
@@ -287,6 +308,9 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
287
308
t .Namespace = api .NamespaceDefault
288
309
}
289
310
errors = policy_validation .ValidatePodDisruptionBudget (t )
311
+ case * rbac.ClusterRole :
312
+ // clusterole does not accept namespace
313
+ errors = rbac_validation .ValidateClusterRole (t )
290
314
case * rbac.ClusterRoleBinding :
291
315
// clusterolebinding does not accept namespace
292
316
errors = rbac_validation .ValidateClusterRoleBinding (t )
@@ -414,6 +438,7 @@ func TestExampleObjectSchemas(t *testing.T) {
414
438
"storagelimits" : {& api.LimitRange {}},
415
439
},
416
440
"admin/sched" : {
441
+ "clusterrole" : {& rbac.ClusterRole {}},
417
442
"my-scheduler" : {& api.ServiceAccount {}, & rbac.ClusterRoleBinding {}, & rbac.ClusterRoleBinding {}, & apps.Deployment {}},
418
443
"pod1" : {& api.Pod {}},
419
444
"pod2" : {& api.Pod {}},
@@ -539,6 +564,7 @@ func TestExampleObjectSchemas(t *testing.T) {
539
564
"dapi-envars-pod" : {& api.Pod {}},
540
565
"dapi-volume" : {& api.Pod {}},
541
566
"dapi-volume-resources" : {& api.Pod {}},
567
+ "dependent-envars" : {& api.Pod {}},
542
568
"envars" : {& api.Pod {}},
543
569
"pod-multiple-secret-env-variable" : {& api.Pod {}},
544
570
"pod-secret-envFrom" : {& api.Pod {}},
@@ -596,29 +622,41 @@ func TestExampleObjectSchemas(t *testing.T) {
596
622
"load-balancer-example" : {& apps.Deployment {}},
597
623
},
598
624
"service/access" : {
599
- "frontend" : {& api.Service {}, & apps.Deployment {}},
600
- "hello-application" : {& apps.Deployment {}},
601
- "hello-service" : {& api.Service {}},
602
- "hello" : {& apps.Deployment {}},
625
+ "backend-deployment" : {& apps.Deployment {}},
626
+ "backend-service" : {& api.Service {}},
627
+ "frontend-deployment" : {& apps.Deployment {}},
628
+ "frontend-service" : {& api.Service {}},
629
+ "hello-application" : {& apps.Deployment {}},
603
630
},
604
631
"service/networking" : {
605
- "curlpod" : {& apps.Deployment {}},
606
- "custom-dns" : {& api.Pod {}},
607
- "dual-stack-default-svc" : {& api.Service {}},
608
- "dual-stack-ipv4-svc" : {& api.Service {}},
609
- "dual-stack-ipv6-lb-svc" : {& api.Service {}},
610
- "dual-stack-ipv6-svc" : {& api.Service {}},
611
- "hostaliases-pod" : {& api.Pod {}},
612
- "ingress" : {& networking.Ingress {}},
613
- "network-policy-allow-all-egress" : {& networking.NetworkPolicy {}},
614
- "network-policy-allow-all-ingress" : {& networking.NetworkPolicy {}},
615
- "network-policy-default-deny-egress" : {& networking.NetworkPolicy {}},
616
- "network-policy-default-deny-ingress" : {& networking.NetworkPolicy {}},
617
- "network-policy-default-deny-all" : {& networking.NetworkPolicy {}},
618
- "nginx-policy" : {& networking.NetworkPolicy {}},
619
- "nginx-secure-app" : {& api.Service {}, & apps.Deployment {}},
620
- "nginx-svc" : {& api.Service {}},
621
- "run-my-nginx" : {& apps.Deployment {}},
632
+ "curlpod" : {& apps.Deployment {}},
633
+ "custom-dns" : {& api.Pod {}},
634
+ "dual-stack-default-svc" : {& api.Service {}},
635
+ "dual-stack-ipfamilies-ipv6" : {& api.Service {}},
636
+ "dual-stack-ipv6-svc" : {& api.Service {}},
637
+ "dual-stack-prefer-ipv6-lb-svc" : {& api.Service {}},
638
+ "dual-stack-preferred-ipfamilies-svc" : {& api.Service {}},
639
+ "dual-stack-preferred-svc" : {& api.Service {}},
640
+ "external-lb" : {& networking.IngressClass {}},
641
+ "example-ingress" : {& networking.Ingress {}},
642
+ "hostaliases-pod" : {& api.Pod {}},
643
+ "ingress-resource-backend" : {& networking.Ingress {}},
644
+ "ingress-wildcard-host" : {& networking.Ingress {}},
645
+ "minimal-ingress" : {& networking.Ingress {}},
646
+ "name-virtual-host-ingress" : {& networking.Ingress {}},
647
+ "name-virtual-host-ingress-no-third-host" : {& networking.Ingress {}},
648
+ "network-policy-allow-all-egress" : {& networking.NetworkPolicy {}},
649
+ "network-policy-allow-all-ingress" : {& networking.NetworkPolicy {}},
650
+ "network-policy-default-deny-egress" : {& networking.NetworkPolicy {}},
651
+ "network-policy-default-deny-ingress" : {& networking.NetworkPolicy {}},
652
+ "network-policy-default-deny-all" : {& networking.NetworkPolicy {}},
653
+ "nginx-policy" : {& networking.NetworkPolicy {}},
654
+ "nginx-secure-app" : {& api.Service {}, & apps.Deployment {}},
655
+ "nginx-svc" : {& api.Service {}},
656
+ "run-my-nginx" : {& apps.Deployment {}},
657
+ "simple-fanout-example" : {& networking.Ingress {}},
658
+ "test-ingress" : {& networking.Ingress {}},
659
+ "tls-example-ingress" : {& networking.Ingress {}},
622
660
},
623
661
"windows" : {
624
662
"configmap-pod" : {& api.ConfigMap {}, & api.Pod {}},
0 commit comments