@@ -7774,6 +7774,34 @@ func TestValidateContainers(t *testing.T) {
7774
7774
ImagePullPolicy: "IfNotPresent",
7775
7775
TerminationMessagePolicy: "File",
7776
7776
},
7777
+ {
7778
+ Name: "resize-policy-cpu",
7779
+ Image: "image",
7780
+ ImagePullPolicy: "IfNotPresent",
7781
+ TerminationMessagePolicy: "File",
7782
+ ResizePolicy: []core.ContainerResizePolicy{
7783
+ {ResourceName: "cpu", RestartPolicy: "NotRequired"},
7784
+ },
7785
+ },
7786
+ {
7787
+ Name: "resize-policy-mem",
7788
+ Image: "image",
7789
+ ImagePullPolicy: "IfNotPresent",
7790
+ TerminationMessagePolicy: "File",
7791
+ ResizePolicy: []core.ContainerResizePolicy{
7792
+ {ResourceName: "memory", RestartPolicy: "RestartContainer"},
7793
+ },
7794
+ },
7795
+ {
7796
+ Name: "resize-policy-cpu-and-mem",
7797
+ Image: "image",
7798
+ ImagePullPolicy: "IfNotPresent",
7799
+ TerminationMessagePolicy: "File",
7800
+ ResizePolicy: []core.ContainerResizePolicy{
7801
+ {ResourceName: "memory", RestartPolicy: "NotRequired"},
7802
+ {ResourceName: "cpu", RestartPolicy: "RestartContainer"},
7803
+ },
7804
+ },
7777
7805
}
7778
7806
if errs := validateContainers(successCase, volumeDevices, nil, field.NewPath("field"), PodValidationOptions{}); len(errs) != 0 {
7779
7807
t.Errorf("expected success: %v", errs)
@@ -8396,6 +8424,38 @@ func TestValidateContainers(t *testing.T) {
8396
8424
},
8397
8425
field.ErrorList{{Type: field.ErrorTypeInvalid, Field: "containers[0].envFrom[0].configMapRef.name"}},
8398
8426
},
8427
+ {
8428
+ "Unsupported resize policy for memory",
8429
+ line(),
8430
+ []core.Container{
8431
+ {
8432
+ Name: "resize-policy-mem-invalid",
8433
+ Image: "image",
8434
+ ImagePullPolicy: "IfNotPresent",
8435
+ TerminationMessagePolicy: "File",
8436
+ ResizePolicy: []core.ContainerResizePolicy{
8437
+ {ResourceName: "memory", RestartPolicy: "RestartContainerrrr"},
8438
+ },
8439
+ },
8440
+ },
8441
+ field.ErrorList{{Type: field.ErrorTypeNotSupported, Field: "containers[0].resizePolicy"}},
8442
+ },
8443
+ {
8444
+ "Unsupported resize policy for CPU",
8445
+ line(),
8446
+ []core.Container{
8447
+ {
8448
+ Name: "resize-policy-cpu-invalid",
8449
+ Image: "image",
8450
+ ImagePullPolicy: "IfNotPresent",
8451
+ TerminationMessagePolicy: "File",
8452
+ ResizePolicy: []core.ContainerResizePolicy{
8453
+ {ResourceName: "cpu", RestartPolicy: "RestartNotRequired"},
8454
+ },
8455
+ },
8456
+ },
8457
+ field.ErrorList{{Type: field.ErrorTypeNotSupported, Field: "containers[0].resizePolicy"}},
8458
+ },
8399
8459
}
8400
8460
for _, tc := range errorCases {
8401
8461
t.Run(tc.title+"__@L"+tc.line, func(t *testing.T) {
0 commit comments