-
Notifications
You must be signed in to change notification settings - Fork 4.3k
VPA: (InPlaceOrRecreate) Allow updater to actuate InPlaceOrRecreate updates #7962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
k8s-ci-robot
merged 7 commits into
kubernetes:in-place-updates
from
maxcao13:in-place-updates-updater
May 5, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
85d5681
VPA: Add metrics gauges for in-place updates
jkyros 7c4e0ab
VPA: Allow updater to actuate InPlaceOrRecreate updates
maxcao13 c3c8177
VPA: Updater in-place updates unit tests
maxcao13 453e600
VPA: fixup vpa-process-yaml.sh script
maxcao13 afc3ec3
VPA: Update vpa-rbac.yaml for allowing in place resize requests
maxcao13 ed9358c
VPA: refactor in-place and eviction logic
maxcao13 7819a2b
address raywainman and omerap12 comments
maxcao13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
vertical-pod-autoscaler/pkg/updater/inplace/inplace_updated.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| Copyright 2025 The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package inplace | ||
|
|
||
| import ( | ||
| core "k8s.io/api/core/v1" | ||
|
|
||
| resource_admission "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/resource" | ||
| "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/resource/pod/patch" | ||
|
|
||
| vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1" | ||
| "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/annotations" | ||
| ) | ||
|
|
||
| type inPlaceUpdate struct{} | ||
|
|
||
| // CalculatePatches returns a patch that adds a "vpaInPlaceUpdated" annotation | ||
| // to the pod, marking it as having been requested to be updated in-place by VPA. | ||
| func (*inPlaceUpdate) CalculatePatches(pod *core.Pod, _ *vpa_types.VerticalPodAutoscaler) ([]resource_admission.PatchRecord, error) { | ||
| vpaInPlaceUpdatedValue := annotations.GetVpaInPlaceUpdatedValue() | ||
| return []resource_admission.PatchRecord{patch.GetAddAnnotationPatch(annotations.VpaInPlaceUpdatedLabel, vpaInPlaceUpdatedValue)}, nil | ||
| } | ||
|
|
||
| func (*inPlaceUpdate) PatchResourceTarget() patch.PatchResourceTarget { | ||
| return patch.Pod | ||
| } | ||
|
|
||
| // NewInPlaceUpdatedCalculator returns calculator for | ||
| // observed containers patches. | ||
| func NewInPlaceUpdatedCalculator() patch.Calculator { | ||
| return &inPlaceUpdate{} | ||
| } | ||
88 changes: 88 additions & 0 deletions
88
vertical-pod-autoscaler/pkg/updater/inplace/resource_updates.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* | ||
| Copyright 2025 The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package inplace | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| core "k8s.io/api/core/v1" | ||
|
|
||
| resource_admission "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/resource" | ||
| "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/resource/pod/patch" | ||
| "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/admission-controller/resource/pod/recommendation" | ||
| vpa_types "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1" | ||
| vpa_api_util "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/utils/vpa" | ||
| ) | ||
|
|
||
| type resourcesInplaceUpdatesPatchCalculator struct { | ||
| recommendationProvider recommendation.Provider | ||
| } | ||
|
|
||
| // NewResourceInPlaceUpdatesCalculator returns a calculator for | ||
| // in-place resource update patches. | ||
| func NewResourceInPlaceUpdatesCalculator(recommendationProvider recommendation.Provider) patch.Calculator { | ||
| return &resourcesInplaceUpdatesPatchCalculator{ | ||
| recommendationProvider: recommendationProvider, | ||
| } | ||
| } | ||
|
|
||
| // PatchResourceTarget returns the resize subresource to apply calculator patches. | ||
| func (*resourcesInplaceUpdatesPatchCalculator) PatchResourceTarget() patch.PatchResourceTarget { | ||
| return patch.Resize | ||
| } | ||
|
|
||
| // CalculatePatches calculates a JSON patch from a VPA's recommendation to send to the pod "resize" subresource as an in-place resize. | ||
| func (c *resourcesInplaceUpdatesPatchCalculator) CalculatePatches(pod *core.Pod, vpa *vpa_types.VerticalPodAutoscaler) ([]resource_admission.PatchRecord, error) { | ||
| result := []resource_admission.PatchRecord{} | ||
|
|
||
| containersResources, _, err := c.recommendationProvider.GetContainersResourcesForPod(pod, vpa) | ||
| if err != nil { | ||
| return []resource_admission.PatchRecord{}, fmt.Errorf("Failed to calculate resource patch for pod %s/%s: %v", pod.Namespace, pod.Name, err) | ||
| } | ||
|
|
||
| for i, containerResources := range containersResources { | ||
| newPatches := getContainerPatch(pod, i, containerResources) | ||
| result = append(result, newPatches...) | ||
| } | ||
|
|
||
| return result, nil | ||
| } | ||
|
|
||
| func getContainerPatch(pod *core.Pod, i int, containerResources vpa_api_util.ContainerResources) []resource_admission.PatchRecord { | ||
| var patches []resource_admission.PatchRecord | ||
| // Add empty resources object if missing. | ||
| if pod.Spec.Containers[i].Resources.Limits == nil && | ||
| pod.Spec.Containers[i].Resources.Requests == nil { | ||
| patches = append(patches, patch.GetPatchInitializingEmptyResources(i)) | ||
| } | ||
|
|
||
| patches = appendPatches(patches, pod.Spec.Containers[i].Resources.Requests, i, containerResources.Requests, "requests") | ||
| patches = appendPatches(patches, pod.Spec.Containers[i].Resources.Limits, i, containerResources.Limits, "limits") | ||
|
|
||
| return patches | ||
| } | ||
|
|
||
| func appendPatches(patches []resource_admission.PatchRecord, current core.ResourceList, containerIndex int, resources core.ResourceList, fieldName string) []resource_admission.PatchRecord { | ||
| // Add empty object if it's missing and we're about to fill it. | ||
| if current == nil && len(resources) > 0 { | ||
| patches = append(patches, patch.GetPatchInitializingEmptyResourcesSubfield(containerIndex, fieldName)) | ||
| } | ||
| for resource, request := range resources { | ||
| patches = append(patches, patch.GetAddResourceRequirementValuePatch(containerIndex, fieldName, resource, request)) | ||
| } | ||
| return patches | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.