Skip to content

Commit

Permalink
Merge pull request kubernetes#116450 from vinaykul/restart-free-pod-v…
Browse files Browse the repository at this point in the history
…ertical-scaling-api

Rename ContainerStatus.ResourcesAllocated to ContainerStatus.AllocatedResources
  • Loading branch information
k8s-ci-robot authored Mar 12, 2023
2 parents a32050e + d011cc4 commit 3c6e419
Show file tree
Hide file tree
Showing 40 changed files with 909 additions and 910 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG/CHANGELOG-1.27.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ name | architectures
- PodSpec.Container.Resources becomes mutable for CPU and memory resource types.
- PodSpec.Container.ResizePolicy (new object) gives users control over how their containers are resized.
- PodStatus.Resize status describes the state of a requested Pod resize.
- PodStatus.ResourcesAllocated describes node resources allocated to Pod.
- PodStatus.AllocatedResources describes node resources allocated to Pod.
- PodStatus.Resources describes node resources applied to running containers by CRI.
- UpdateContainerResources CRI API now supports both Linux and Windows.

Expand Down Expand Up @@ -640,4 +640,4 @@ name | architectures

### Removed
- github.com/elazarl/goproxy: [947c36d](https://github.com/elazarl/goproxy/tree/947c36d)
- github.com/mindprince/gonvml: [9ebdce4](https://github.com/mindprince/gonvml/tree/9ebdce4)
- github.com/mindprince/gonvml: [9ebdce4](https://github.com/mindprince/gonvml/tree/9ebdce4)
14 changes: 7 additions & 7 deletions api/openapi-spec/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions api/openapi-spec/v3/api__v1_openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,18 @@
"io.k8s.api.core.v1.ContainerStatus": {
"description": "ContainerStatus contains details for the current status of this container.",
"properties": {
"allocatedResources": {
"additionalProperties": {
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity"
}
],
"default": {}
},
"description": "AllocatedResources represents the compute resources allocated for this container by the node. Kubelet sets this value to Container.Resources.Requests upon successful pod admission and after successfully admitting desired pod resize.",
"type": "object"
},
"containerID": {
"description": "ContainerID is the ID of the container in the format '<type>://<container_id>'. Where type is a container runtime identifier, returned from Version call of CRI API (for example \"containerd\").",
"type": "string"
Expand Down Expand Up @@ -1478,18 +1490,6 @@
],
"description": "Resources represents the compute resource requests and limits that have been successfully enacted on the running container after it has been started or has been successfully resized."
},
"resourcesAllocated": {
"additionalProperties": {
"allOf": [
{
"$ref": "#/components/schemas/io.k8s.apimachinery.pkg.api.resource.Quantity"
}
],
"default": {}
},
"description": "ResourcesAllocated represents the compute resources allocated for this container by the node. Kubelet sets this value to Container.Resources.Requests upon successful pod admission and after successfully admitting desired pod resize.",
"type": "object"
},
"restartCount": {
"default": 0,
"description": "RestartCount holds the number of times the container has been restarted. Kubelet makes an effort to always increment the value, but there are cases when the state may be lost due to node restarts and then the value may be reset to 0. The value is never negative.",
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/pod/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,10 @@ func dropDisabledPodStatusFields(podStatus, oldPodStatus *api.PodStatus, podSpec
}

if !utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) && !inPlacePodVerticalScalingInUse(oldPodSpec) {
// Drop Resize, ResourcesAllocated, and Resources fields
// Drop Resize, AllocatedResources, and Resources fields
dropResourcesFields := func(csl []api.ContainerStatus) {
for i := range csl {
csl[i].ResourcesAllocated = nil
csl[i].AllocatedResources = nil
csl[i].Resources = nil
}
}
Expand Down Expand Up @@ -862,7 +862,7 @@ func MarkPodProposedForResize(oldPod, newPod *api.Pod) {
return api.ContainerStatus{}, false
}
if cs, ok := findContainerStatus(newPod.Status.ContainerStatuses, c.Name); ok {
if diff.ObjectDiff(c.Resources.Requests, cs.ResourcesAllocated) != "" {
if diff.ObjectDiff(c.Resources.Requests, cs.AllocatedResources) != "" {
newPod.Status.Resize = api.PodResizeStatusProposed
break
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/api/pod/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2302,7 +2302,7 @@ func TestDropInPlacePodVerticalScaling(t *testing.T) {
{
Name: "c1",
Image: "image",
ResourcesAllocated: api.ResourceList{api.ResourceCPU: resource.MustParse("100m")},
AllocatedResources: api.ResourceList{api.ResourceCPU: resource.MustParse("100m")},
Resources: &api.ResourceRequirements{
Requests: api.ResourceList{api.ResourceCPU: resource.MustParse("200m")},
Limits: api.ResourceList{api.ResourceCPU: resource.MustParse("300m")},
Expand Down Expand Up @@ -2573,12 +2573,12 @@ func TestMarkPodProposedForResize(t *testing.T) {
{
Name: "c1",
Image: "image",
ResourcesAllocated: api.ResourceList{api.ResourceCPU: resource.MustParse("100m")},
AllocatedResources: api.ResourceList{api.ResourceCPU: resource.MustParse("100m")},
},
{
Name: "c2",
Image: "image",
ResourcesAllocated: api.ResourceList{api.ResourceCPU: resource.MustParse("200m")},
AllocatedResources: api.ResourceList{api.ResourceCPU: resource.MustParse("200m")},
},
},
},
Expand Down Expand Up @@ -2609,12 +2609,12 @@ func TestMarkPodProposedForResize(t *testing.T) {
{
Name: "c1",
Image: "image",
ResourcesAllocated: api.ResourceList{api.ResourceCPU: resource.MustParse("100m")},
AllocatedResources: api.ResourceList{api.ResourceCPU: resource.MustParse("100m")},
},
{
Name: "c2",
Image: "image",
ResourcesAllocated: api.ResourceList{api.ResourceCPU: resource.MustParse("200m")},
AllocatedResources: api.ResourceList{api.ResourceCPU: resource.MustParse("200m")},
},
},
},
Expand Down Expand Up @@ -2646,12 +2646,12 @@ func TestMarkPodProposedForResize(t *testing.T) {
{
Name: "c1",
Image: "image",
ResourcesAllocated: api.ResourceList{api.ResourceCPU: resource.MustParse("100m")},
AllocatedResources: api.ResourceList{api.ResourceCPU: resource.MustParse("100m")},
},
{
Name: "c2",
Image: "image",
ResourcesAllocated: api.ResourceList{api.ResourceCPU: resource.MustParse("200m")},
AllocatedResources: api.ResourceList{api.ResourceCPU: resource.MustParse("200m")},
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/v1/resource/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func PodRequests(pod *v1.Pod, opts PodResourcesOptions) v1.ResourceList {
cs, found := containerStatuses[container.Name]
if found {
if pod.Status.Resize == v1.PodResizeStatusInfeasible {
containerReqs = cs.ResourcesAllocated
containerReqs = cs.AllocatedResources
} else {
containerReqs = max(container.Resources.Requests, cs.ResourcesAllocated)
containerReqs = max(container.Resources.Requests, cs.AllocatedResources)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/v1/resource/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ func TestPodResourceRequests(t *testing.T) {
containerStatus: []v1.ContainerStatus{
{
Name: "container-1",
ResourcesAllocated: v1.ResourceList{
AllocatedResources: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("2"),
},
},
Expand All @@ -762,7 +762,7 @@ func TestPodResourceRequests(t *testing.T) {
containerStatus: []v1.ContainerStatus{
{
Name: "container-1",
ResourcesAllocated: v1.ResourceList{
AllocatedResources: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("2"),
},
},
Expand All @@ -788,7 +788,7 @@ func TestPodResourceRequests(t *testing.T) {
containerStatus: []v1.ContainerStatus{
{
Name: "container-1",
ResourcesAllocated: v1.ResourceList{
AllocatedResources: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("2"),
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2492,12 +2492,12 @@ type ContainerStatus struct {
// same as false.
// +optional
Started *bool
// ResourcesAllocated represents the compute resources allocated for this container by the
// AllocatedResources represents the compute resources allocated for this container by the
// node. Kubelet sets this value to Container.Resources.Requests upon successful pod admission
// and after successfully admitting desired pod resize.
// +featureGate=InPlacePodVerticalScaling
// +optional
ResourcesAllocated ResourceList
AllocatedResources ResourceList
// Resources represents the compute resource requests and limits that have been successfully
// enacted on the running container after it has been started or has been successfully resized.
// +featureGate=InPlacePodVerticalScaling
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/core/v1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions pkg/apis/core/v1/zz_generated.defaults.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/apis/core/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/generated/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/kubelet/cm/cpumanager/policy_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,12 @@ func (p *staticPolicy) guaranteedCPUs(pod *v1.Pod, container *v1.Container) int
}
cpuQuantity := container.Resources.Requests[v1.ResourceCPU]
// In-place pod resize feature makes Container.Resources field mutable for CPU & memory.
// ResourcesAllocated holds the value of Container.Resources.Requests when the pod was admitted.
// AllocatedResources holds the value of Container.Resources.Requests when the pod was admitted.
// We should return this value because this is what kubelet agreed to allocate for the container
// and the value configured with runtime.
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) {
if cs, ok := podutil.GetContainerStatus(pod.Status.ContainerStatuses, container.Name); ok {
cpuQuantity = cs.ResourcesAllocated[v1.ResourceCPU]
cpuQuantity = cs.AllocatedResources[v1.ResourceCPU]
}
}
if cpuQuantity.Value()*1000 != cpuQuantity.MilliValue() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/cm/memorymanager/policy_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,12 @@ func getRequestedResources(pod *v1.Pod, container *v1.Container) (map[v1.Resourc
requestedResources := map[v1.ResourceName]uint64{}
resources := container.Resources.Requests
// In-place pod resize feature makes Container.Resources field mutable for CPU & memory.
// ResourcesAllocated holds the value of Container.Resources.Requests when the pod was admitted.
// AllocatedResources holds the value of Container.Resources.Requests when the pod was admitted.
// We should return this value because this is what kubelet agreed to allocate for the container
// and the value configured with runtime.
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) {
if cs, ok := podutil.GetContainerStatus(pod.Status.ContainerStatuses, container.Name); ok {
resources = cs.ResourcesAllocated
resources = cs.AllocatedResources
}
}
for resourceName, quantity := range resources {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/eviction/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ func evictionMessage(resourceToReclaim v1.ResourceName, pod *v1.Pod, stats stats
if utilfeature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling) &&
(resourceToReclaim == v1.ResourceMemory || resourceToReclaim == v1.ResourceCPU) {
if cs, ok := podutil.GetContainerStatus(pod.Status.ContainerStatuses, container.Name); ok {
requests = cs.ResourcesAllocated[resourceToReclaim]
requests = cs.AllocatedResources[resourceToReclaim]
}
}
var usage *resource.Quantity
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/eviction/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2134,7 +2134,7 @@ func TestEvictonMessageWithResourceResize(t *testing.T) {
ContainerStatuses: []v1.ContainerStatus{
{
Name: "testcontainer",
ResourcesAllocated: newResourceList("", "100Mi", ""),
AllocatedResources: newResourceList("", "100Mi", ""),
},
},
}
Expand Down
Loading

0 comments on commit 3c6e419

Please sign in to comment.