@@ -4041,7 +4041,7 @@ func TestHugePagesIsolation(t *testing.T) {
4041
4041
for tcName , tc := range testCases {
4042
4042
t .Run (tcName , func (t * testing.T ) {
4043
4043
defer featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .HugePageStorageMediumSize , tc .enableHugePageStorageMediumSize )()
4044
- errs := ValidatePod (tc .pod , PodValidationOptions {tc .enableHugePageStorageMediumSize })
4044
+ errs := ValidatePodCreate (tc .pod , PodValidationOptions {tc .enableHugePageStorageMediumSize })
4045
4045
if tc .expectError && len (errs ) == 0 {
4046
4046
t .Errorf ("Unexpected success" )
4047
4047
}
@@ -7426,7 +7426,7 @@ func TestValidatePod(t *testing.T) {
7426
7426
},
7427
7427
}
7428
7428
for _ , pod := range successCases {
7429
- if errs := ValidatePod (& pod , PodValidationOptions {}); len (errs ) != 0 {
7429
+ if errs := ValidatePodCreate (& pod , PodValidationOptions {}); len (errs ) != 0 {
7430
7430
t .Errorf ("expected success: %v" , errs )
7431
7431
}
7432
7432
}
@@ -8276,7 +8276,7 @@ func TestValidatePod(t *testing.T) {
8276
8276
},
8277
8277
}
8278
8278
for k , v := range errorCases {
8279
- if errs := ValidatePod (& v .spec , PodValidationOptions {}); len (errs ) == 0 {
8279
+ if errs := ValidatePodCreate (& v .spec , PodValidationOptions {}); len (errs ) == 0 {
8280
8280
t .Errorf ("expected failure for %q" , k )
8281
8281
} else if v .expectedError == "" {
8282
8282
t .Errorf ("missing expectedError for %q, got %q" , k , errs .ToAggregate ().Error ())
@@ -8485,7 +8485,10 @@ func TestValidatePodUpdate(t *testing.T) {
8485
8485
Spec : core.PodSpec {
8486
8486
Containers : []core.Container {
8487
8487
{
8488
- Image : "foo:V1" ,
8488
+ Name : "container" ,
8489
+ Image : "foo:V1" ,
8490
+ TerminationMessagePolicy : "File" ,
8491
+ ImagePullPolicy : "Always" ,
8489
8492
},
8490
8493
},
8491
8494
},
@@ -8495,7 +8498,10 @@ func TestValidatePodUpdate(t *testing.T) {
8495
8498
Spec : core.PodSpec {
8496
8499
Containers : []core.Container {
8497
8500
{
8498
- Image : "foo:V2" ,
8501
+ Name : "container" ,
8502
+ Image : "foo:V2" ,
8503
+ TerminationMessagePolicy : "File" ,
8504
+ ImagePullPolicy : "Always" ,
8499
8505
},
8500
8506
},
8501
8507
},
@@ -8509,7 +8515,10 @@ func TestValidatePodUpdate(t *testing.T) {
8509
8515
Spec : core.PodSpec {
8510
8516
InitContainers : []core.Container {
8511
8517
{
8512
- Image : "foo:V1" ,
8518
+ Name : "container" ,
8519
+ Image : "foo:V1" ,
8520
+ TerminationMessagePolicy : "File" ,
8521
+ ImagePullPolicy : "Always" ,
8513
8522
},
8514
8523
},
8515
8524
},
@@ -8519,7 +8528,10 @@ func TestValidatePodUpdate(t *testing.T) {
8519
8528
Spec : core.PodSpec {
8520
8529
InitContainers : []core.Container {
8521
8530
{
8522
- Image : "foo:V2" ,
8531
+ Name : "container" ,
8532
+ Image : "foo:V2" ,
8533
+ TerminationMessagePolicy : "File" ,
8534
+ ImagePullPolicy : "Always" ,
8523
8535
},
8524
8536
},
8525
8537
},
@@ -8532,7 +8544,11 @@ func TestValidatePodUpdate(t *testing.T) {
8532
8544
ObjectMeta : metav1.ObjectMeta {Name : "foo" },
8533
8545
Spec : core.PodSpec {
8534
8546
Containers : []core.Container {
8535
- {},
8547
+ {
8548
+ Name : "container" ,
8549
+ TerminationMessagePolicy : "File" ,
8550
+ ImagePullPolicy : "Always" ,
8551
+ },
8536
8552
},
8537
8553
},
8538
8554
},
@@ -8541,7 +8557,10 @@ func TestValidatePodUpdate(t *testing.T) {
8541
8557
Spec : core.PodSpec {
8542
8558
Containers : []core.Container {
8543
8559
{
8544
- Image : "foo:V2" ,
8560
+ Name : "container" ,
8561
+ Image : "foo:V2" ,
8562
+ TerminationMessagePolicy : "File" ,
8563
+ ImagePullPolicy : "Always" ,
8545
8564
},
8546
8565
},
8547
8566
},
@@ -8554,7 +8573,11 @@ func TestValidatePodUpdate(t *testing.T) {
8554
8573
ObjectMeta : metav1.ObjectMeta {Name : "foo" },
8555
8574
Spec : core.PodSpec {
8556
8575
InitContainers : []core.Container {
8557
- {},
8576
+ {
8577
+ Name : "container" ,
8578
+ TerminationMessagePolicy : "File" ,
8579
+ ImagePullPolicy : "Always" ,
8580
+ },
8558
8581
},
8559
8582
},
8560
8583
},
@@ -8563,7 +8586,10 @@ func TestValidatePodUpdate(t *testing.T) {
8563
8586
Spec : core.PodSpec {
8564
8587
InitContainers : []core.Container {
8565
8588
{
8566
- Image : "foo:V2" ,
8589
+ Name : "container" ,
8590
+ Image : "foo:V2" ,
8591
+ TerminationMessagePolicy : "File" ,
8592
+ ImagePullPolicy : "Always" ,
8567
8593
},
8568
8594
},
8569
8595
},
@@ -8690,7 +8716,7 @@ func TestValidatePodUpdate(t *testing.T) {
8690
8716
ActiveDeadlineSeconds : & activeDeadlineSecondsPositive ,
8691
8717
},
8692
8718
},
8693
- "" ,
8719
+ "spec.activeDeadlineSeconds " ,
8694
8720
"activeDeadlineSeconds change to zero from positive" ,
8695
8721
},
8696
8722
{
@@ -8700,7 +8726,7 @@ func TestValidatePodUpdate(t *testing.T) {
8700
8726
},
8701
8727
},
8702
8728
core.Pod {},
8703
- "" ,
8729
+ "spec.activeDeadlineSeconds " ,
8704
8730
"activeDeadlineSeconds change to zero from nil" ,
8705
8731
},
8706
8732
{
@@ -9047,6 +9073,29 @@ func TestValidatePodUpdate(t *testing.T) {
9047
9073
for _ , test := range tests {
9048
9074
test .new .ObjectMeta .ResourceVersion = "1"
9049
9075
test .old .ObjectMeta .ResourceVersion = "1"
9076
+
9077
+ // set required fields if old and new match and have no opinion on the value
9078
+ if test .new .Name == "" && test .old .Name == "" {
9079
+ test .new .Name = "name"
9080
+ test .old .Name = "name"
9081
+ }
9082
+ if test .new .Namespace == "" && test .old .Namespace == "" {
9083
+ test .new .Namespace = "namespace"
9084
+ test .old .Namespace = "namespace"
9085
+ }
9086
+ if test .new .Spec .Containers == nil && test .old .Spec .Containers == nil {
9087
+ test .new .Spec .Containers = []core.Container {{Name : "autoadded" , Image : "image" , TerminationMessagePolicy : "File" , ImagePullPolicy : "Always" }}
9088
+ test .old .Spec .Containers = []core.Container {{Name : "autoadded" , Image : "image" , TerminationMessagePolicy : "File" , ImagePullPolicy : "Always" }}
9089
+ }
9090
+ if len (test .new .Spec .DNSPolicy ) == 0 && len (test .old .Spec .DNSPolicy ) == 0 {
9091
+ test .new .Spec .DNSPolicy = core .DNSClusterFirst
9092
+ test .old .Spec .DNSPolicy = core .DNSClusterFirst
9093
+ }
9094
+ if len (test .new .Spec .RestartPolicy ) == 0 && len (test .old .Spec .RestartPolicy ) == 0 {
9095
+ test .new .Spec .RestartPolicy = "Always"
9096
+ test .old .Spec .RestartPolicy = "Always"
9097
+ }
9098
+
9050
9099
errs := ValidatePodUpdate (& test .new , & test .old , PodValidationOptions {})
9051
9100
if test .err == "" {
9052
9101
if len (errs ) != 0 {
@@ -15031,15 +15080,32 @@ func TestPodIPsValidation(t *testing.T) {
15031
15080
}
15032
15081
15033
15082
for _ , testCase := range testCases {
15034
- errs := ValidatePod (& testCase .pod , PodValidationOptions {})
15035
- if len (errs ) == 0 && testCase .expectError {
15036
- t .Errorf ("expected failure for %s, but there were none" , testCase .pod .Name )
15037
- return
15038
- }
15039
- if len (errs ) != 0 && ! testCase .expectError {
15040
- t .Errorf ("expected success for %s, but there were errors: %v" , testCase .pod .Name , errs )
15041
- return
15042
- }
15083
+ t .Run (testCase .pod .Name , func (t * testing.T ) {
15084
+ for _ , oldTestCase := range testCases {
15085
+ newPod := testCase .pod .DeepCopy ()
15086
+ newPod .ResourceVersion = "1"
15087
+
15088
+ oldPod := oldTestCase .pod .DeepCopy ()
15089
+ oldPod .ResourceVersion = "1"
15090
+ oldPod .Name = newPod .Name
15091
+
15092
+ errs := ValidatePodStatusUpdate (newPod , oldPod )
15093
+ if oldTestCase .expectError {
15094
+ // The old pod was invalid, tolerate invalid IPs in the new pod as well
15095
+ if len (errs ) > 0 {
15096
+ t .Fatalf ("expected success for update to pod with already-invalid IPs, got errors: %v" , errs )
15097
+ }
15098
+ continue
15099
+ }
15100
+
15101
+ if len (errs ) == 0 && testCase .expectError {
15102
+ t .Fatalf ("expected failure for %s, but there were none" , testCase .pod .Name )
15103
+ }
15104
+ if len (errs ) != 0 && ! testCase .expectError {
15105
+ t .Fatalf ("expected success for %s, but there were errors: %v" , testCase .pod .Name , errs )
15106
+ }
15107
+ }
15108
+ })
15043
15109
}
15044
15110
}
15045
15111
0 commit comments