Skip to content

Commit c14e098

Browse files
authored
Merge pull request kubernetes#116684 from vinaykul/restart-free-pod-vertical-scaling-fixes
Add missing unit test for resource resize policy defaulting
2 parents 05740da + 0c2c132 commit c14e098

File tree

2 files changed

+221
-9
lines changed

2 files changed

+221
-9
lines changed

CHANGELOG/CHANGELOG-1.27.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ name | architectures
229229
- Updated: Redefine AppProtocol field description and add new standard values ([#115433](https://github.com/kubernetes/kubernetes/pull/115433), [@LiorLieberman](https://github.com/LiorLieberman)) [SIG API Machinery, Apps and Network]
230230
- ValidatingAdmissionPolicy now provides a status field that contains results of type checking the validation expression.
231231
The type checking is fully informational, and the behavior of the policy is unchanged. ([#115668](https://github.com/kubernetes/kubernetes/pull/115668), [@jiahuif](https://github.com/jiahuif)) [SIG API Machinery, Auth, Cloud Provider and Testing]
232-
- Vpa: ResourceResizePolicy type is renamed to ResourceResizeRestartPolicy and RestartRequired policy value is renamed to RestartContainer. If not specified by the user, RestartNotRequired policy defaults for CPU and memory resources. ([#116119](https://github.com/kubernetes/kubernetes/pull/116119), [@vinaykul](https://github.com/vinaykul)) [SIG API Machinery, Apps, Node and Testing]
233232
- We have removed support for the v1alpha1 kubeletplugin API of DynamicResourceManagement. All plugins must update to v1alpha2 in order to function properly going forward. ([#116558](https://github.com/kubernetes/kubernetes/pull/116558), [@klueska](https://github.com/klueska)) [SIG API Machinery, Apps, CLI, Node, Scheduling and Testing]
234233

235234
### Feature
@@ -502,13 +501,13 @@ name | architectures
502501
Add SendInitialEvents field to the ListOptions. When the new option is set together with watch=true, it begins the watch stream with synthetic init events followed by a synthetic "Bookmark" after which the server continues streaming events. ([#115402](https://github.com/kubernetes/kubernetes/pull/115402), [@p0lyn0mial](https://github.com/p0lyn0mial)) [SIG API Machinery]
503502
- Kubelet: a "maxParallelImagePulls" field can now be specified in the kubelet configuration file to control how many image pulls the kubelet can perform in parallel. ([#115220](https://github.com/kubernetes/kubernetes/pull/115220), [@ruiwen-zhao](https://github.com/ruiwen-zhao)) [SIG API Machinery, Node and Scalability]
504503
- PodSchedulingReadiness is graduated to beta. ([#115815](https://github.com/kubernetes/kubernetes/pull/115815), [@Huang-Wei](https://github.com/Huang-Wei)) [SIG API Machinery, Apps, Scheduling and Testing]
505-
- PodSpec.Container.Resources becomes mutable for CPU and memory resource types.
506-
- PodSpec.Container.ResizePolicy (new object) gives users control over how their containers are resized.
507-
- PodStatus.Resize status describes the state of a requested Pod resize.
508-
- PodStatus.AllocatedResources describes node resources allocated to Pod.
509-
- PodStatus.Resources describes node resources applied to running containers by CRI.
510-
- UpdateContainerResources CRI API now supports both Linux and Windows.
511-
504+
- In-place resize feature for Kubernetes Pods
505+
- Changed the Pod API so that the `resources` defined for containers are mutable for `cpu` and `memory` resource types.
506+
- Added `resizePolicy` for containers in a pod to allow users control over how their containers are resized.
507+
- Added `allocatedResources` field to container status in pod status that describes the node resources allocated to a pod.
508+
- Added `resources` field to container status that reports actual resources applied to running containers.
509+
- Added `resize` field to pod status that describes the state of a requested pod resize.
510+
512511
For details, see KEPs below. ([#102884](https://github.com/kubernetes/kubernetes/pull/102884), [@vinaykul](https://github.com/vinaykul)) [SIG API Machinery, Apps, Instrumentation, Node, Scheduling and Testing]
513512
- The PodDisruptionBudget `spec.unhealthyPodEvictionPolicy` field has graduated to beta and is enabled by default. On servers with the feature enabled, this field may be set to `AlwaysAllow` to always allow unhealthy pods covered by the PodDisruptionBudget to be evicted. ([#115363](https://github.com/kubernetes/kubernetes/pull/115363), [@ravisantoshgudimetla](https://github.com/ravisantoshgudimetla)) [SIG Apps, Auth and Node]
514513
- The `DownwardAPIHugePages` kubelet feature graduated to stable / GA. ([#115721](https://github.com/kubernetes/kubernetes/pull/115721), [@saschagrunert](https://github.com/saschagrunert)) [SIG Apps and Node]
@@ -992,4 +991,4 @@ name | architectures
992991

993992
### Removed
994993
- github.com/elazarl/goproxy: [947c36d](https://github.com/elazarl/goproxy/tree/947c36d)
995-
- github.com/mindprince/gonvml: [9ebdce4](https://github.com/mindprince/gonvml/tree/9ebdce4)
994+
- github.com/mindprince/gonvml: [9ebdce4](https://github.com/mindprince/gonvml/tree/9ebdce4)

pkg/apis/core/v1/defaults_test.go

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
featuregatetesting "k8s.io/component-base/featuregate/testing"
3434
"k8s.io/kubernetes/pkg/api/legacyscheme"
3535
corev1 "k8s.io/kubernetes/pkg/apis/core/v1"
36+
"k8s.io/kubernetes/pkg/features"
3637
utilpointer "k8s.io/utils/pointer"
3738

3839
// ensure types are installed
@@ -1906,3 +1907,215 @@ func TestSetDefaultServiceInternalTrafficPolicy(t *testing.T) {
19061907
})
19071908
}
19081909
}
1910+
1911+
func TestSetDefaultResizePolicy(t *testing.T) {
1912+
// verify we default to NotRequired restart policy for resize when resources are specified
1913+
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.InPlacePodVerticalScaling, true)()
1914+
1915+
for desc, tc := range map[string]struct {
1916+
testContainer v1.Container
1917+
expectedResizePolicy []v1.ContainerResizePolicy
1918+
}{
1919+
"CPU and memory limits are specified": {
1920+
testContainer: v1.Container{
1921+
Resources: v1.ResourceRequirements{
1922+
Limits: v1.ResourceList{
1923+
v1.ResourceCPU: resource.MustParse("100m"),
1924+
v1.ResourceMemory: resource.MustParse("200Mi"),
1925+
},
1926+
},
1927+
},
1928+
expectedResizePolicy: []v1.ContainerResizePolicy{
1929+
{
1930+
ResourceName: v1.ResourceCPU,
1931+
RestartPolicy: v1.NotRequired,
1932+
},
1933+
{
1934+
ResourceName: v1.ResourceMemory,
1935+
RestartPolicy: v1.NotRequired,
1936+
},
1937+
},
1938+
},
1939+
"CPU requests are specified": {
1940+
testContainer: v1.Container{
1941+
Resources: v1.ResourceRequirements{
1942+
Requests: v1.ResourceList{
1943+
v1.ResourceCPU: resource.MustParse("100m"),
1944+
},
1945+
},
1946+
},
1947+
expectedResizePolicy: []v1.ContainerResizePolicy{
1948+
{
1949+
ResourceName: v1.ResourceCPU,
1950+
RestartPolicy: v1.NotRequired,
1951+
},
1952+
},
1953+
},
1954+
"Memory limits are specified": {
1955+
testContainer: v1.Container{
1956+
Resources: v1.ResourceRequirements{
1957+
Limits: v1.ResourceList{
1958+
v1.ResourceMemory: resource.MustParse("200Mi"),
1959+
},
1960+
},
1961+
},
1962+
expectedResizePolicy: []v1.ContainerResizePolicy{
1963+
{
1964+
ResourceName: v1.ResourceMemory,
1965+
RestartPolicy: v1.NotRequired,
1966+
},
1967+
},
1968+
},
1969+
"No resources are specified": {
1970+
testContainer: v1.Container{Name: "besteffort"},
1971+
expectedResizePolicy: nil,
1972+
},
1973+
"CPU and memory limits are specified with restartContainer resize policy for memory": {
1974+
testContainer: v1.Container{
1975+
Resources: v1.ResourceRequirements{
1976+
Limits: v1.ResourceList{
1977+
v1.ResourceCPU: resource.MustParse("100m"),
1978+
v1.ResourceMemory: resource.MustParse("200Mi"),
1979+
},
1980+
},
1981+
ResizePolicy: []v1.ContainerResizePolicy{
1982+
{
1983+
ResourceName: v1.ResourceMemory,
1984+
RestartPolicy: v1.RestartContainer,
1985+
},
1986+
},
1987+
},
1988+
expectedResizePolicy: []v1.ContainerResizePolicy{
1989+
{
1990+
ResourceName: v1.ResourceMemory,
1991+
RestartPolicy: v1.RestartContainer,
1992+
},
1993+
{
1994+
ResourceName: v1.ResourceCPU,
1995+
RestartPolicy: v1.NotRequired,
1996+
},
1997+
},
1998+
},
1999+
"CPU requests and memory limits are specified with restartContainer resize policy for CPU": {
2000+
testContainer: v1.Container{
2001+
Resources: v1.ResourceRequirements{
2002+
Limits: v1.ResourceList{
2003+
v1.ResourceMemory: resource.MustParse("200Mi"),
2004+
},
2005+
Requests: v1.ResourceList{
2006+
v1.ResourceCPU: resource.MustParse("100m"),
2007+
},
2008+
},
2009+
ResizePolicy: []v1.ContainerResizePolicy{
2010+
{
2011+
ResourceName: v1.ResourceCPU,
2012+
RestartPolicy: v1.RestartContainer,
2013+
},
2014+
},
2015+
},
2016+
expectedResizePolicy: []v1.ContainerResizePolicy{
2017+
{
2018+
ResourceName: v1.ResourceCPU,
2019+
RestartPolicy: v1.RestartContainer,
2020+
},
2021+
{
2022+
ResourceName: v1.ResourceMemory,
2023+
RestartPolicy: v1.NotRequired,
2024+
},
2025+
},
2026+
},
2027+
"CPU and memory requests are specified with restartContainer resize policy for both": {
2028+
testContainer: v1.Container{
2029+
Resources: v1.ResourceRequirements{
2030+
Requests: v1.ResourceList{
2031+
v1.ResourceCPU: resource.MustParse("100m"),
2032+
v1.ResourceMemory: resource.MustParse("200Mi"),
2033+
},
2034+
},
2035+
ResizePolicy: []v1.ContainerResizePolicy{
2036+
{
2037+
ResourceName: v1.ResourceCPU,
2038+
RestartPolicy: v1.RestartContainer,
2039+
},
2040+
{
2041+
ResourceName: v1.ResourceMemory,
2042+
RestartPolicy: v1.RestartContainer,
2043+
},
2044+
},
2045+
},
2046+
expectedResizePolicy: []v1.ContainerResizePolicy{
2047+
{
2048+
ResourceName: v1.ResourceCPU,
2049+
RestartPolicy: v1.RestartContainer,
2050+
},
2051+
{
2052+
ResourceName: v1.ResourceMemory,
2053+
RestartPolicy: v1.RestartContainer,
2054+
},
2055+
},
2056+
},
2057+
"Ephemeral storage limits are specified": {
2058+
testContainer: v1.Container{
2059+
Resources: v1.ResourceRequirements{
2060+
Limits: v1.ResourceList{
2061+
v1.ResourceEphemeralStorage: resource.MustParse("500Mi"),
2062+
},
2063+
},
2064+
},
2065+
expectedResizePolicy: nil,
2066+
},
2067+
"Ephemeral storage requests and CPU limits are specified": {
2068+
testContainer: v1.Container{
2069+
Resources: v1.ResourceRequirements{
2070+
Limits: v1.ResourceList{
2071+
v1.ResourceCPU: resource.MustParse("100m"),
2072+
},
2073+
Requests: v1.ResourceList{
2074+
v1.ResourceEphemeralStorage: resource.MustParse("500Mi"),
2075+
},
2076+
},
2077+
},
2078+
expectedResizePolicy: []v1.ContainerResizePolicy{
2079+
{
2080+
ResourceName: v1.ResourceCPU,
2081+
RestartPolicy: v1.NotRequired,
2082+
},
2083+
},
2084+
},
2085+
"Ephemeral storage requests and limits, memory requests with restartContainer policy are specified": {
2086+
testContainer: v1.Container{
2087+
Resources: v1.ResourceRequirements{
2088+
Limits: v1.ResourceList{
2089+
v1.ResourceEphemeralStorage: resource.MustParse("500Mi"),
2090+
},
2091+
Requests: v1.ResourceList{
2092+
v1.ResourceEphemeralStorage: resource.MustParse("500Mi"),
2093+
v1.ResourceMemory: resource.MustParse("200Mi"),
2094+
},
2095+
},
2096+
ResizePolicy: []v1.ContainerResizePolicy{
2097+
{
2098+
ResourceName: v1.ResourceMemory,
2099+
RestartPolicy: v1.RestartContainer,
2100+
},
2101+
},
2102+
},
2103+
expectedResizePolicy: []v1.ContainerResizePolicy{
2104+
{
2105+
ResourceName: v1.ResourceMemory,
2106+
RestartPolicy: v1.RestartContainer,
2107+
},
2108+
},
2109+
},
2110+
} {
2111+
t.Run(desc, func(t *testing.T) {
2112+
testPod := v1.Pod{}
2113+
testPod.Spec.Containers = append(testPod.Spec.Containers, tc.testContainer)
2114+
output := roundTrip(t, runtime.Object(&testPod))
2115+
pod2 := output.(*v1.Pod)
2116+
if diff.ObjectDiff(pod2.Spec.Containers[0].ResizePolicy, tc.expectedResizePolicy) != "" {
2117+
t.Errorf("expected resize policy %+v, but got %+v", tc.expectedResizePolicy, pod2.Spec.Containers[0].ResizePolicy)
2118+
}
2119+
})
2120+
}
2121+
}

0 commit comments

Comments
 (0)