Repository: kubernetes/kubernetes (language: go)

Issue:
[FG:InPlacePodVerticalScaling] Disable in-place resize for guaranteed pods on nodes with a static topology policy
See https://github.com/kubernetes/enhancements/blob/master/keps/sig-node/1287-in-place-update-pod-resources/README.md#static-cpu--memory-policy

We probably want to introduce a new feature gate to allow resize in this case to unblock development on https://github.com/kubernetes/kubernetes/issues/127262.

/sig node
/kind feature
/priority important-longterm


Discussion / hints:
/milestone v1.32
/triage accepted
@esotsal any interest in picking this up?
@tallclair let me try？
/assign
/assign
> [@tallclair](https://github.com/tallclair) let me try？ /assign

Do you working this issue? @olderTaoist 
> @esotsal any interest in picking this up?

Sure but I see other contributors have volunteered 😁 already.
> > [@tallclair](https://github.com/tallclair) let me try？ /assign
> 
> Do you working this issue? @olderTaoist

i already read  the [InPlacePodVerticalScaling](https://github.com/kubernetes/enhancements/blob/master/keps/sig-node/1287-in-place-update-pod-resources/README.md). but i notice @esotsal previous [implementation](https://github.com/kubernetes/kubernetes/pull/123319),  if @esotsal don't mind, i perfer want to work this issue.
/assign
> > > [@tallclair](https://github.com/tallclair) let me try？ /assign
> > 
> > 
> > Do you working this issue? @olderTaoist
> 
> i already read the [InPlacePodVerticalScaling](https://github.com/kubernetes/enhancements/blob/master/keps/sig-node/1287-in-place-update-pod-resources/README.md). but i notice @esotsal previous [implementation](https://github.com/kubernetes/kubernetes/pull/123319), if @esotsal don't mind, i perfer want to work this issue.

It links with the ongoing PR  I am working but it is not same Thanks for volunteering @olderTaoist and @lengrongfu but prefer to work on this, as initially asked by @tallclair . 
Hello @esotsal @olderTaoist @lengrongfu @tallclair 

Really appreciate all the activity here! If there's anything we can do, please let us know.

Friendly reminder that code freeze is starting `02:00 UTC Friday November 8th 2024` (about **3 weeks from now**), and while there is still time, we want to ensure that each PR has a chance to be merged on time.

Given this timeline, do we feel this will be able to release for `1.32`? Thanks!
> Hello @esotsal @olderTaoist @lengrongfu @tallclair
> 
> Really appreciate all the activity here! If there's anything we can do, please let us know.
> 
> Friendly reminder that code freeze is starting `02:00 UTC Friday November 8th 2024` (about **3 weeks from now**), and while there is still time, we want to ensure that each PR has a chance to be merged on time.
> 
> Given this timeline, do we feel this will be able to release for `1.32`? Thanks!

Yes, that’s the goal.

Fix patch:
diff --git a/pkg/features/kube_features.go b/pkg/features/kube_features.go
index 4fbfdee171cf6..d95fa0b6e6ff3 100644
--- a/pkg/features/kube_features.go
+++ b/pkg/features/kube_features.go
@@ -270,6 +270,14 @@ const (
 	// InPlacePodVerticalScaling also be enabled.
 	InPlacePodVerticalScalingAllocatedStatus featuregate.Feature = "InPlacePodVerticalScalingAllocatedStatus"
 
+	// owner: @tallclair @esotsal
+	// alpha: v1.32
+	//
+	// Allow resource resize for containers in Guaranteed pods with integer CPU requests ( default false ).
+	// Applies only in nodes with InPlacePodVerticalScaling and CPU Manager features enabled, and
+	// CPU Manager Static Policy option set.
+	InPlacePodVerticalScalingExclusiveCPUs featuregate.Feature = "InPlacePodVerticalScalingExclusiveCPUs"
+
 	// owner: @trierra
 	//
 	// Disables the Portworx in-tree driver.
diff --git a/pkg/features/versioned_kube_features.go b/pkg/features/versioned_kube_features.go
index 2211528cac026..ffebcbe75c8b2 100644
--- a/pkg/features/versioned_kube_features.go
+++ b/pkg/features/versioned_kube_features.go
@@ -397,6 +397,10 @@ var defaultVersionedKubernetesFeatureGates = map[featuregate.Feature]featuregate
 		{Version: version.MustParse("1.32"), Default: false, PreRelease: featuregate.Alpha},
 	},
 
+	InPlacePodVerticalScalingExclusiveCPUs: {
+		{Version: version.MustParse("1.32"), Default: false, PreRelease: featuregate.Alpha},
+	},
+
 	InTreePluginPortworxUnregister: {
 		{Version: version.MustParse("1.23"), Default: false, PreRelease: featuregate.Alpha},
 	},
diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go
index 94f2a9ded9544..d4416fce40165 100644
--- a/pkg/kubelet/kubelet.go
+++ b/pkg/kubelet/kubelet.go
@@ -2838,6 +2838,21 @@ func isPodResizeInProgress(pod *v1.Pod, podStatus *kubecontainer.PodStatus) bool
 // pod should hold the desired (pre-allocated) spec.
 // Returns true if the resize can proceed.
 func (kl *Kubelet) canResizePod(pod *v1.Pod) (bool, v1.PodResizeStatus) {
+	if v1qos.GetPodQOS(pod) == v1.PodQOSGuaranteed && !utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScalingExclusiveCPUs) {
+		if utilfeature.DefaultFeatureGate.Enabled(features.CPUManager) {
+			if kl.containerManager.GetNodeConfig().CPUManagerPolicy == "static" {
+				klog.V(3).InfoS("Resize is infeasible for Guaranteed Pods alongside CPU Manager static policy")
+				return false, v1.PodResizeStatusInfeasible
+			}
+		}
+		if utilfeature.DefaultFeatureGate.Enabled(features.MemoryManager) {
+			if kl.containerManager.GetNodeConfig().ExperimentalMemoryManagerPolicy == "static" {
+				klog.V(3).InfoS("Resize is infeasible for Guaranteed Pods alongside Memory Manager static policy")
+				return false, v1.PodResizeStatusInfeasible
+			}
+		}
+	}
+
 	node, err := kl.getNodeAnyWay()
 	if err != nil {
 		klog.ErrorS(err, "getNodeAnyway function failed")


Test patch:
diff --git a/test/featuregates_linter/test_data/versioned_feature_list.yaml b/test/featuregates_linter/test_data/versioned_feature_list.yaml
index f640e4b228003..6451f5e259c1b 100644
--- a/test/featuregates_linter/test_data/versioned_feature_list.yaml
+++ b/test/featuregates_linter/test_data/versioned_feature_list.yaml
@@ -522,6 +522,12 @@
     lockToDefault: false
     preRelease: Alpha
     version: "1.32"
+- name: InPlacePodVerticalScalingExclusiveCPUs
+  versionedSpecs:
+  - default: false
+    lockToDefault: false
+    preRelease: Alpha
+    version: "1.32"
 - name: InTreePluginPortworxUnregister
   versionedSpecs:
   - default: false