Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d1fac49
resolve merge conflicts
vivzbansal Nov 6, 2024
0e392f9
Disable e2e test for now
vivzbansal Nov 6, 2024
34ddb91
Fix some unit tests error
vivzbansal Nov 6, 2024
cdddaed
Added sidecar support in and
vivzbansal Nov 6, 2024
3885d2f
Added sidecar support in ValidatePodResize and dropNonResizeUpdates
vivzbansal Nov 6, 2024
5d5e903
Revert e2e tests added for sidecar
vivzbansal Nov 7, 2024
591b0f5
Fix issue of pod spec mismatch if there is any non-restarble init con…
vivzbansal Nov 7, 2024
a0d3cb0
Added proper validation msg when non-sidecar containers are resized
vivzbansal Nov 7, 2024
1eb966c
Added unit test for sidecar containers in TestValidatePodResize
vivzbansal Nov 8, 2024
1cf4587
Fix build error
vivzbansal Nov 8, 2024
6cf5b80
Fix some unit test error
vivzbansal Nov 8, 2024
6c5cf68
Resolved latest review comments
vivzbansal Nov 8, 2024
9a5c578
test: pod-resize tests for sidecar containers
AnishShah Nov 8, 2024
2ba6132
Fix e2e test error due to ContainersToUpdate map not created
vivzbansal Nov 9, 2024
8fa8277
Added some unit tests
vivzbansal Nov 9, 2024
5ed5732
Refactored status manager code of updatePodFromAllocation
vivzbansal Nov 9, 2024
242dec3
Updated some unit tests and resolved some review comments
vivzbansal Nov 9, 2024
5889da1
Resolved latest review comments
vivzbansal Dec 17, 2024
ab964a7
Fix e2e tests failure
vivzbansal Jan 1, 2025
c479f00
Update field to use feature gate
vivzbansal Jan 7, 2025
c31b1b3
Resolved some review comments
vivzbansal Jan 7, 2025
cfa0349
Update validation code
vivzbansal Jan 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions pkg/api/pod/util.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inPlacePodVerticalScalingInUse needs to be updated too. Change the containers mask to include init containers:

VisitContainers(podSpec, Containers, func(c *api.Container, containerType ContainerType) bool {

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package pod
import (
"strings"

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

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

opts.AllowPodLifecycleSleepActionZeroValue = opts.AllowPodLifecycleSleepActionZeroValue || podLifecycleSleepActionZeroValueInUse(podSpec)
// If oldPod has resize policy set on the restartable init container, we must allow it
opts.AllowSidecarResizePolicy = hasRestartableInitContainerResizePolicy(oldPodSpec)
opts.AllowSidecarResizePolicy = opts.AllowSidecarResizePolicy || hasRestartableInitContainerResizePolicy(oldPodSpec)
}
if oldPodMeta != nil && !opts.AllowInvalidPodDeletionCost {
// This is an update, so validate only if the existing object was valid.
Expand Down Expand Up @@ -1092,7 +1093,8 @@ func inPlacePodVerticalScalingInUse(podSpec *api.PodSpec) bool {
return false
}
var inUse bool
VisitContainers(podSpec, Containers, func(c *api.Container, containerType ContainerType) bool {
containersMask := Containers | InitContainers
VisitContainers(podSpec, containersMask, func(c *api.Container, containerType ContainerType) bool {
if len(c.ResizePolicy) > 0 {
inUse = true
return false
Expand Down Expand Up @@ -1289,19 +1291,35 @@ func MarkPodProposedForResize(oldPod, newPod *api.Pod) {
return
}

if utilfeature.DefaultFeatureGate.Enabled(features.SidecarContainers) && len(newPod.Spec.InitContainers) != len(oldPod.Spec.InitContainers) {
return
}

for i, c := range newPod.Spec.Containers {
if c.Name != oldPod.Spec.Containers[i].Name {
return // Update is invalid (container mismatch): let validation handle it.
}
if c.Resources.Requests == nil {
continue
}
if cmp.Equal(oldPod.Spec.Containers[i].Resources, c.Resources) {
if apiequality.Semantic.DeepEqual(oldPod.Spec.Containers[i].Resources, c.Resources) {
continue
}
newPod.Status.Resize = api.PodResizeStatusProposed
return
}

if utilfeature.DefaultFeatureGate.Enabled(features.SidecarContainers) {
for i, c := range newPod.Spec.InitContainers {
if IsRestartableInitContainer(&c) {
if c.Name != oldPod.Spec.InitContainers[i].Name {
return // Update is invalid (container mismatch): let validation handle it.
}
if apiequality.Semantic.DeepEqual(oldPod.Spec.InitContainers[i].Resources, c.Resources) {
continue
}
newPod.Status.Resize = api.PodResizeStatusProposed
return
}
}
}
}

// KEP: https://kep.k8s.io/4639
Expand Down
Loading