@@ -27,6 +27,7 @@ import (
27
27
"strings"
28
28
"testing"
29
29
30
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30
31
"k8s.io/apimachinery/pkg/runtime"
31
32
"k8s.io/apimachinery/pkg/runtime/schema"
32
33
"k8s.io/apimachinery/pkg/types"
@@ -65,7 +66,6 @@ import (
65
66
storage_validation "k8s.io/kubernetes/pkg/apis/storage/validation"
66
67
67
68
"k8s.io/kubernetes/pkg/capabilities"
68
- "k8s.io/kubernetes/pkg/registry/batch/job"
69
69
70
70
// initialize install packages
71
71
_ "k8s.io/kubernetes/pkg/apis/admissionregistration/install"
@@ -195,17 +195,13 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
195
195
case * api.Namespace :
196
196
errors = validation .ValidateNamespace (t )
197
197
case * api.PersistentVolume :
198
- opts := validation.PersistentVolumeSpecValidationOptions {
199
- AllowReadWriteOncePod : true ,
200
- }
198
+ opts := validation.PersistentVolumeSpecValidationOptions {}
201
199
errors = validation .ValidatePersistentVolume (t , opts )
202
200
case * api.PersistentVolumeClaim :
203
201
if t .Namespace == "" {
204
202
t .Namespace = api .NamespaceDefault
205
203
}
206
- opts := validation.PersistentVolumeClaimSpecValidationOptions {
207
- AllowReadWriteOncePod : true ,
208
- }
204
+ opts := validation.PersistentVolumeClaimSpecValidationOptions {}
209
205
errors = validation .ValidatePersistentVolumeClaim (t , opts )
210
206
case * api.Pod :
211
207
if t .Namespace == "" {
@@ -292,16 +288,34 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
292
288
if t .Namespace == "" {
293
289
t .Namespace = api .NamespaceDefault
294
290
}
291
+
295
292
// Job needs generateSelector called before validation, and job.Validate does this.
296
- // See: https://github.com/kubernetes/kubernetes/issues/20951#issuecomment-187787040
297
- t .ObjectMeta .UID = types .UID ("fakeuid" )
298
293
if strings .Index (t .ObjectMeta .Name , "$" ) > - 1 {
299
294
t .ObjectMeta .Name = "skip-for-good"
300
295
}
301
- errors = job .Strategy .Validate (nil , t )
296
+ t .ObjectMeta .UID = types .UID ("fakeuid" )
297
+ if t .Spec .Template .ObjectMeta .Labels == nil {
298
+ t .Spec .Template .ObjectMeta .Labels = make (map [string ]string )
299
+ }
300
+ t .Spec .Template .ObjectMeta .Labels ["controller-uid" ] = "fakeuid"
301
+ t .Spec .Template .ObjectMeta .Labels ["job-name" ] = t .ObjectMeta .Name
302
+ if t .Spec .Selector == nil {
303
+ t .Spec .Selector = & metav1.LabelSelector {
304
+ MatchLabels : map [string ]string {
305
+ "controller-uid" : "fakeuid" ,
306
+ "job-name" : t .ObjectMeta .Name ,
307
+ },
308
+ }
309
+ }
310
+ opts := batch_validation.JobValidationOptions {
311
+ RequirePrefixedLabels : false ,
312
+ }
313
+ errors = batch_validation .ValidateJob (t , opts )
314
+
302
315
// case *flowcontrol.FlowSchema:
303
316
// TODO: This is still failing
304
317
// errors = flowcontrol_validation.ValidateFlowSchema(t)
318
+
305
319
case * networking.Ingress :
306
320
if t .Namespace == "" {
307
321
t .Namespace = api .NamespaceDefault
@@ -314,8 +328,6 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
314
328
t .Namespace = api .NamespaceDefault
315
329
}
316
330
errors = networking_validation .ValidateNetworkPolicy (t , netValidationOptions )
317
- case * policy.PodSecurityPolicy :
318
- errors = policy_validation .ValidatePodSecurityPolicy (t )
319
331
case * policy.PodDisruptionBudget :
320
332
if t .Namespace == "" {
321
333
t .Namespace = api .NamespaceDefault
@@ -509,7 +521,9 @@ func TestExampleObjectSchemas(t *testing.T) {
509
521
"indexed-job-vol" : {& batch.Job {}},
510
522
},
511
523
"application/job/rabbitmq" : {
512
- "job" : {& batch.Job {}},
524
+ "job" : {& batch.Job {}},
525
+ "rabbitmq-statefulset" : {& apps.StatefulSet {}},
526
+ "rabbitmq-service" : {& api.Service {}},
513
527
},
514
528
"application/job/redis" : {
515
529
"job" : {& batch.Job {}},
@@ -671,18 +685,15 @@ func TestExampleObjectSchemas(t *testing.T) {
671
685
"pv-pod" : {& api.Pod {}},
672
686
"pv-volume" : {& api.PersistentVolume {}},
673
687
"redis" : {& api.Pod {}},
688
+ "projected-clustertrustbundle" : {& api.Pod {}},
674
689
},
675
690
"pods/topology-spread-constraints" : {
676
691
"one-constraint" : {& api.Pod {}},
677
692
"one-constraint-with-nodeaffinity" : {& api.Pod {}},
678
693
"two-constraints" : {& api.Pod {}},
679
694
},
680
695
"policy" : {
681
- "baseline-psp" : {& policy.PodSecurityPolicy {}},
682
- "example-psp" : {& policy.PodSecurityPolicy {}},
683
- "priority-class-resourcequota" : {& api.ResourceQuota {}},
684
- "privileged-psp" : {& policy.PodSecurityPolicy {}},
685
- "restricted-psp" : {& policy.PodSecurityPolicy {}},
696
+ "priority-class-resourcequota" : {& api.ResourceQuota {}},
686
697
"zookeeper-pod-disruption-budget-maxunavailable" : {& policy.PodDisruptionBudget {}},
687
698
"zookeeper-pod-disruption-budget-minavailable" : {& policy.PodDisruptionBudget {}},
688
699
},
@@ -766,6 +777,13 @@ func TestExampleObjectSchemas(t *testing.T) {
766
777
"audit" : {
767
778
"audit-policy" : true ,
768
779
},
780
+ // PSP is dropped in v1.29, do not validate them
781
+ "policy" : {
782
+ "baseline-psp" : true ,
783
+ "example-psp" : true ,
784
+ "privileged-psp" : true ,
785
+ "restricted-psp" : true ,
786
+ },
769
787
}
770
788
capabilities .SetForTests (capabilities.Capabilities {
771
789
AllowPrivileged : true ,
0 commit comments