@@ -19,7 +19,7 @@ package pod
19
19
import (
20
20
"strings"
21
21
22
- "github.com/google/go-cmp/cmp" //nolint:depguard
22
+ apiequality "k8s.io/apimachinery/pkg/api/equality"
23
23
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24
24
metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
25
25
"k8s.io/apimachinery/pkg/util/sets"
@@ -386,6 +386,7 @@ func GetValidationOptionsFromPodSpecAndMeta(podSpec, oldPodSpec *api.PodSpec, po
386
386
AllowPodLifecycleSleepActionZeroValue : utilfeature .DefaultFeatureGate .Enabled (features .PodLifecycleSleepActionAllowZero ),
387
387
PodLevelResourcesEnabled : utilfeature .DefaultFeatureGate .Enabled (features .PodLevelResources ),
388
388
AllowInvalidLabelValueInRequiredNodeAffinity : false ,
389
+ AllowSidecarResizePolicy : utilfeature .DefaultFeatureGate .Enabled (features .InPlacePodVerticalScaling ),
389
390
}
390
391
391
392
// If old spec uses relaxed validation or enabled the RelaxedEnvironmentVariableValidation feature gate,
@@ -419,7 +420,7 @@ func GetValidationOptionsFromPodSpecAndMeta(podSpec, oldPodSpec *api.PodSpec, po
419
420
420
421
opts .AllowPodLifecycleSleepActionZeroValue = opts .AllowPodLifecycleSleepActionZeroValue || podLifecycleSleepActionZeroValueInUse (podSpec )
421
422
// If oldPod has resize policy set on the restartable init container, we must allow it
422
- opts .AllowSidecarResizePolicy = hasRestartableInitContainerResizePolicy (oldPodSpec )
423
+ opts .AllowSidecarResizePolicy = opts . AllowSidecarResizePolicy || hasRestartableInitContainerResizePolicy (oldPodSpec )
423
424
}
424
425
if oldPodMeta != nil && ! opts .AllowInvalidPodDeletionCost {
425
426
// This is an update, so validate only if the existing object was valid.
@@ -1092,7 +1093,8 @@ func inPlacePodVerticalScalingInUse(podSpec *api.PodSpec) bool {
1092
1093
return false
1093
1094
}
1094
1095
var inUse bool
1095
- VisitContainers (podSpec , Containers , func (c * api.Container , containerType ContainerType ) bool {
1096
+ containersMask := Containers | InitContainers
1097
+ VisitContainers (podSpec , containersMask , func (c * api.Container , containerType ContainerType ) bool {
1096
1098
if len (c .ResizePolicy ) > 0 {
1097
1099
inUse = true
1098
1100
return false
@@ -1289,19 +1291,35 @@ func MarkPodProposedForResize(oldPod, newPod *api.Pod) {
1289
1291
return
1290
1292
}
1291
1293
1294
+ if utilfeature .DefaultFeatureGate .Enabled (features .SidecarContainers ) && len (newPod .Spec .InitContainers ) != len (oldPod .Spec .InitContainers ) {
1295
+ return
1296
+ }
1297
+
1292
1298
for i , c := range newPod .Spec .Containers {
1293
1299
if c .Name != oldPod .Spec .Containers [i ].Name {
1294
1300
return // Update is invalid (container mismatch): let validation handle it.
1295
1301
}
1296
- if c .Resources .Requests == nil {
1297
- continue
1298
- }
1299
- if cmp .Equal (oldPod .Spec .Containers [i ].Resources , c .Resources ) {
1302
+ if apiequality .Semantic .DeepEqual (oldPod .Spec .Containers [i ].Resources , c .Resources ) {
1300
1303
continue
1301
1304
}
1302
1305
newPod .Status .Resize = api .PodResizeStatusProposed
1303
1306
return
1304
1307
}
1308
+
1309
+ if utilfeature .DefaultFeatureGate .Enabled (features .SidecarContainers ) {
1310
+ for i , c := range newPod .Spec .InitContainers {
1311
+ if IsRestartableInitContainer (& c ) {
1312
+ if c .Name != oldPod .Spec .InitContainers [i ].Name {
1313
+ return // Update is invalid (container mismatch): let validation handle it.
1314
+ }
1315
+ if apiequality .Semantic .DeepEqual (oldPod .Spec .InitContainers [i ].Resources , c .Resources ) {
1316
+ continue
1317
+ }
1318
+ newPod .Status .Resize = api .PodResizeStatusProposed
1319
+ return
1320
+ }
1321
+ }
1322
+ }
1305
1323
}
1306
1324
1307
1325
// KEP: https://kep.k8s.io/4639
0 commit comments