Skip to content

Commit 0634e21

Browse files
authored
Merge pull request kubernetes#128367 from vivzbansal/sidecar-2
[FG:InPlacePodVerticalScaling] Implement resize for sidecar containers
2 parents e54be1e + cfa0349 commit 0634e21

File tree

23 files changed

+1811
-498
lines changed

23 files changed

+1811
-498
lines changed

pkg/api/pod/util.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package pod
1919
import (
2020
"strings"
2121

22-
"github.com/google/go-cmp/cmp" //nolint:depguard
22+
apiequality "k8s.io/apimachinery/pkg/api/equality"
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
metavalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
2525
"k8s.io/apimachinery/pkg/util/sets"
@@ -386,6 +386,7 @@ func GetValidationOptionsFromPodSpecAndMeta(podSpec, oldPodSpec *api.PodSpec, po
386386
AllowPodLifecycleSleepActionZeroValue: utilfeature.DefaultFeatureGate.Enabled(features.PodLifecycleSleepActionAllowZero),
387387
PodLevelResourcesEnabled: utilfeature.DefaultFeatureGate.Enabled(features.PodLevelResources),
388388
AllowInvalidLabelValueInRequiredNodeAffinity: false,
389+
AllowSidecarResizePolicy: utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling),
389390
}
390391

391392
// If old spec uses relaxed validation or enabled the RelaxedEnvironmentVariableValidation feature gate,
@@ -419,7 +420,7 @@ func GetValidationOptionsFromPodSpecAndMeta(podSpec, oldPodSpec *api.PodSpec, po
419420

420421
opts.AllowPodLifecycleSleepActionZeroValue = opts.AllowPodLifecycleSleepActionZeroValue || podLifecycleSleepActionZeroValueInUse(podSpec)
421422
// 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)
423424
}
424425
if oldPodMeta != nil && !opts.AllowInvalidPodDeletionCost {
425426
// This is an update, so validate only if the existing object was valid.
@@ -1092,7 +1093,8 @@ func inPlacePodVerticalScalingInUse(podSpec *api.PodSpec) bool {
10921093
return false
10931094
}
10941095
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 {
10961098
if len(c.ResizePolicy) > 0 {
10971099
inUse = true
10981100
return false
@@ -1289,19 +1291,35 @@ func MarkPodProposedForResize(oldPod, newPod *api.Pod) {
12891291
return
12901292
}
12911293

1294+
if utilfeature.DefaultFeatureGate.Enabled(features.SidecarContainers) && len(newPod.Spec.InitContainers) != len(oldPod.Spec.InitContainers) {
1295+
return
1296+
}
1297+
12921298
for i, c := range newPod.Spec.Containers {
12931299
if c.Name != oldPod.Spec.Containers[i].Name {
12941300
return // Update is invalid (container mismatch): let validation handle it.
12951301
}
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) {
13001303
continue
13011304
}
13021305
newPod.Status.Resize = api.PodResizeStatusProposed
13031306
return
13041307
}
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+
}
13051323
}
13061324

13071325
// KEP: https://kep.k8s.io/4639

0 commit comments

Comments
 (0)