@@ -2950,13 +2950,13 @@ func TestDropSidecarContainers(t *testing.T) {
2950
2950
}
2951
2951
2952
2952
func TestMarkPodProposedForResize (t * testing.T ) {
2953
+ featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .SidecarContainers , true )
2953
2954
containerRestartPolicyAlways := api .ContainerRestartPolicyAlways
2954
2955
testCases := []struct {
2955
2956
desc string
2956
2957
newPodSpec api.PodSpec
2957
2958
oldPodSpec api.PodSpec
2958
2959
expectProposedResize bool
2959
- hasSidecarContainer bool
2960
2960
}{
2961
2961
{
2962
2962
desc : "nil requests" ,
@@ -3211,8 +3211,7 @@ func TestMarkPodProposedForResize(t *testing.T) {
3211
3211
expectProposedResize : false ,
3212
3212
},
3213
3213
{
3214
- desc : "resources unchanged with sidecar containers" ,
3215
- hasSidecarContainer : true ,
3214
+ desc : "resources unchanged with sidecar containers" ,
3216
3215
newPodSpec : api.PodSpec {
3217
3216
Containers : []api.Container {
3218
3217
{
@@ -3262,8 +3261,7 @@ func TestMarkPodProposedForResize(t *testing.T) {
3262
3261
expectProposedResize : false ,
3263
3262
},
3264
3263
{
3265
- desc : "requests resized with sidecar containers" ,
3266
- hasSidecarContainer : true ,
3264
+ desc : "requests resized with sidecar containers" ,
3267
3265
newPodSpec : api.PodSpec {
3268
3266
Containers : []api.Container {
3269
3267
{
@@ -3274,28 +3272,47 @@ func TestMarkPodProposedForResize(t *testing.T) {
3274
3272
Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("200m" )},
3275
3273
},
3276
3274
},
3275
+ },
3276
+ InitContainers : []api.Container {
3277
3277
{
3278
- Name : "c2 " ,
3278
+ Name : "i1 " ,
3279
3279
Image : "image" ,
3280
3280
Resources : api.ResourceRequirements {
3281
3281
Requests : api.ResourceList {api .ResourceCPU : resource .MustParse ("300m" )},
3282
3282
Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("400m" )},
3283
3283
},
3284
+ RestartPolicy : & containerRestartPolicyAlways ,
3285
+ },
3286
+ },
3287
+ },
3288
+ oldPodSpec : api.PodSpec {
3289
+ Containers : []api.Container {
3290
+ {
3291
+ Name : "c1" ,
3292
+ Image : "image" ,
3293
+ Resources : api.ResourceRequirements {
3294
+ Requests : api.ResourceList {api .ResourceCPU : resource .MustParse ("100m" )},
3295
+ Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("200m" )},
3296
+ },
3284
3297
},
3285
3298
},
3286
3299
InitContainers : []api.Container {
3287
3300
{
3288
3301
Name : "i1" ,
3289
3302
Image : "image" ,
3290
3303
Resources : api.ResourceRequirements {
3291
- Requests : api.ResourceList {api .ResourceCPU : resource .MustParse ("300m " )},
3292
- Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("400m " )},
3304
+ Requests : api.ResourceList {api .ResourceCPU : resource .MustParse ("200m " )},
3305
+ Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("300m " )},
3293
3306
},
3294
3307
RestartPolicy : & containerRestartPolicyAlways ,
3295
3308
},
3296
3309
},
3297
3310
},
3298
- oldPodSpec : api.PodSpec {
3311
+ expectProposedResize : true ,
3312
+ },
3313
+ {
3314
+ desc : "limits resized with sidecar containers" ,
3315
+ newPodSpec : api.PodSpec {
3299
3316
Containers : []api.Container {
3300
3317
{
3301
3318
Name : "c1" ,
@@ -3305,22 +3322,37 @@ func TestMarkPodProposedForResize(t *testing.T) {
3305
3322
Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("200m" )},
3306
3323
},
3307
3324
},
3325
+ },
3326
+ InitContainers : []api.Container {
3308
3327
{
3309
- Name : "c2 " ,
3328
+ Name : "i1 " ,
3310
3329
Image : "image" ,
3311
3330
Resources : api.ResourceRequirements {
3312
- Requests : api.ResourceList {api .ResourceCPU : resource .MustParse ("200m " )},
3331
+ Requests : api.ResourceList {api .ResourceCPU : resource .MustParse ("300m " )},
3313
3332
Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("400m" )},
3314
3333
},
3334
+ RestartPolicy : & containerRestartPolicyAlways ,
3335
+ },
3336
+ },
3337
+ },
3338
+ oldPodSpec : api.PodSpec {
3339
+ Containers : []api.Container {
3340
+ {
3341
+ Name : "c1" ,
3342
+ Image : "image" ,
3343
+ Resources : api.ResourceRequirements {
3344
+ Requests : api.ResourceList {api .ResourceCPU : resource .MustParse ("100m" )},
3345
+ Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("200m" )},
3346
+ },
3315
3347
},
3316
3348
},
3317
3349
InitContainers : []api.Container {
3318
3350
{
3319
3351
Name : "i1" ,
3320
3352
Image : "image" ,
3321
3353
Resources : api.ResourceRequirements {
3322
- Requests : api.ResourceList {api .ResourceCPU : resource .MustParse ("200m " )},
3323
- Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("300m " )},
3354
+ Requests : api.ResourceList {api .ResourceCPU : resource .MustParse ("300m " )},
3355
+ Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("500m " )},
3324
3356
},
3325
3357
RestartPolicy : & containerRestartPolicyAlways ,
3326
3358
},
@@ -3329,8 +3361,7 @@ func TestMarkPodProposedForResize(t *testing.T) {
3329
3361
expectProposedResize : true ,
3330
3362
},
3331
3363
{
3332
- desc : "limits resized with sidecar containers" ,
3333
- hasSidecarContainer : true ,
3364
+ desc : "requests resized should fail with non-sidecar init container" ,
3334
3365
newPodSpec : api.PodSpec {
3335
3366
Containers : []api.Container {
3336
3367
{
@@ -3341,28 +3372,45 @@ func TestMarkPodProposedForResize(t *testing.T) {
3341
3372
Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("200m" )},
3342
3373
},
3343
3374
},
3375
+ },
3376
+ InitContainers : []api.Container {
3344
3377
{
3345
- Name : "c2 " ,
3378
+ Name : "i1 " ,
3346
3379
Image : "image" ,
3347
3380
Resources : api.ResourceRequirements {
3348
3381
Requests : api.ResourceList {api .ResourceCPU : resource .MustParse ("300m" )},
3349
3382
Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("400m" )},
3350
3383
},
3351
3384
},
3352
3385
},
3386
+ },
3387
+ oldPodSpec : api.PodSpec {
3388
+ Containers : []api.Container {
3389
+ {
3390
+ Name : "c1" ,
3391
+ Image : "image" ,
3392
+ Resources : api.ResourceRequirements {
3393
+ Requests : api.ResourceList {api .ResourceCPU : resource .MustParse ("100m" )},
3394
+ Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("200m" )},
3395
+ },
3396
+ },
3397
+ },
3353
3398
InitContainers : []api.Container {
3354
3399
{
3355
3400
Name : "i1" ,
3356
3401
Image : "image" ,
3357
3402
Resources : api.ResourceRequirements {
3358
- Requests : api.ResourceList {api .ResourceCPU : resource .MustParse ("300m " )},
3359
- Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("400m " )},
3403
+ Requests : api.ResourceList {api .ResourceCPU : resource .MustParse ("200m " )},
3404
+ Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("300m " )},
3360
3405
},
3361
- RestartPolicy : & containerRestartPolicyAlways ,
3362
3406
},
3363
3407
},
3364
3408
},
3365
- oldPodSpec : api.PodSpec {
3409
+ expectProposedResize : false ,
3410
+ },
3411
+ {
3412
+ desc : "limits resized should fail with non-sidecar init containers" ,
3413
+ newPodSpec : api.PodSpec {
3366
3414
Containers : []api.Container {
3367
3415
{
3368
3416
Name : "c1" ,
@@ -3372,12 +3420,26 @@ func TestMarkPodProposedForResize(t *testing.T) {
3372
3420
Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("200m" )},
3373
3421
},
3374
3422
},
3423
+ },
3424
+ InitContainers : []api.Container {
3375
3425
{
3376
- Name : "c2 " ,
3426
+ Name : "i1 " ,
3377
3427
Image : "image" ,
3378
3428
Resources : api.ResourceRequirements {
3379
3429
Requests : api.ResourceList {api .ResourceCPU : resource .MustParse ("300m" )},
3380
- Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("500m" )},
3430
+ Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("400m" )},
3431
+ },
3432
+ },
3433
+ },
3434
+ },
3435
+ oldPodSpec : api.PodSpec {
3436
+ Containers : []api.Container {
3437
+ {
3438
+ Name : "c1" ,
3439
+ Image : "image" ,
3440
+ Resources : api.ResourceRequirements {
3441
+ Requests : api.ResourceList {api .ResourceCPU : resource .MustParse ("100m" )},
3442
+ Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("200m" )},
3381
3443
},
3382
3444
},
3383
3445
},
@@ -3389,11 +3451,10 @@ func TestMarkPodProposedForResize(t *testing.T) {
3389
3451
Requests : api.ResourceList {api .ResourceCPU : resource .MustParse ("300m" )},
3390
3452
Limits : api.ResourceList {api .ResourceCPU : resource .MustParse ("500m" )},
3391
3453
},
3392
- RestartPolicy : & containerRestartPolicyAlways ,
3393
3454
},
3394
3455
},
3395
3456
},
3396
- expectProposedResize : true ,
3457
+ expectProposedResize : false ,
3397
3458
},
3398
3459
{
3399
3460
desc : "the number of sidecar containers in the pod has increased; no action should be taken." ,
@@ -3524,7 +3585,6 @@ func TestMarkPodProposedForResize(t *testing.T) {
3524
3585
}
3525
3586
for _ , tc := range testCases {
3526
3587
t .Run (tc .desc , func (t * testing.T ) {
3527
- featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .SidecarContainers , tc .hasSidecarContainer )
3528
3588
newPod := & api.Pod {Spec : tc .newPodSpec }
3529
3589
newPodUnchanged := newPod .DeepCopy ()
3530
3590
oldPod := & api.Pod {Spec : tc .oldPodSpec }
0 commit comments