mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 02:41:25 +00:00
Restructure naming of resource resize restart policy
This commit is contained in:
parent
3c6e419cc3
commit
8b23497ae7
@ -2290,8 +2290,8 @@ func TestDropInPlacePodVerticalScaling(t *testing.T) {
|
|||||||
Limits: api.ResourceList{api.ResourceCPU: resource.MustParse("200m")},
|
Limits: api.ResourceList{api.ResourceCPU: resource.MustParse("200m")},
|
||||||
},
|
},
|
||||||
ResizePolicy: []api.ContainerResizePolicy{
|
ResizePolicy: []api.ContainerResizePolicy{
|
||||||
{ResourceName: api.ResourceCPU, Policy: api.RestartNotRequired},
|
{ResourceName: api.ResourceCPU, RestartPolicy: api.RestartNotRequired},
|
||||||
{ResourceName: api.ResourceMemory, Policy: api.RestartRequired},
|
{ResourceName: api.ResourceMemory, RestartPolicy: api.RestartContainer},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -2138,31 +2138,31 @@ const (
|
|||||||
PullIfNotPresent PullPolicy = "IfNotPresent"
|
PullIfNotPresent PullPolicy = "IfNotPresent"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ResourceResizePolicy specifies how Kubernetes should handle resource resize.
|
// ResourceResizeRestartPolicy specifies how to handle container resource resize.
|
||||||
type ResourceResizePolicy string
|
type ResourceResizeRestartPolicy string
|
||||||
|
|
||||||
// These are the valid resource resize policy values:
|
// These are the valid resource resize restart policy values:
|
||||||
const (
|
const (
|
||||||
// RestartNotRequired tells Kubernetes to resize the container in-place
|
// 'RestartNotRequired' means Kubernetes will try to resize the container
|
||||||
// without restarting it, if possible. Kubernetes may however choose to
|
// without restarting it, if possible. Kubernetes may however choose to
|
||||||
// restart the container if it is unable to actuate resize without a
|
// restart the container if it is unable to actuate resize without a
|
||||||
// restart. For e.g. the runtime doesn't support restart-free resizing.
|
// restart. For e.g. the runtime doesn't support restart-free resizing.
|
||||||
RestartNotRequired ResourceResizePolicy = "RestartNotRequired"
|
RestartNotRequired ResourceResizeRestartPolicy = "RestartNotRequired"
|
||||||
// 'RestartRequired' tells Kubernetes to resize the container in-place
|
// 'RestartContainer' means Kubernetes will resize the container in-place
|
||||||
// by stopping and starting the container when new resources are applied.
|
// by stopping and starting the container when new resources are applied.
|
||||||
// This is needed for legacy applications. For e.g. java apps using the
|
// This is needed for legacy applications. For e.g. java apps using the
|
||||||
// -xmxN flag which are unable to use resized memory without restarting.
|
// -xmxN flag which are unable to use resized memory without restarting.
|
||||||
RestartRequired ResourceResizePolicy = "RestartRequired"
|
RestartContainer ResourceResizeRestartPolicy = "RestartContainer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerResizePolicy represents resource resize policy for a single container.
|
// ContainerResizePolicy represents resource resize policy for the container.
|
||||||
type ContainerResizePolicy struct {
|
type ContainerResizePolicy struct {
|
||||||
// Name of the resource type to which this resource resize policy applies.
|
// Name of the resource to which this resource resize policy applies.
|
||||||
// Supported values: cpu, memory.
|
// Supported values: cpu, memory.
|
||||||
ResourceName ResourceName
|
ResourceName ResourceName
|
||||||
// Resource resize policy applicable to the specified resource name.
|
// Restart policy to apply when specified resource is resized.
|
||||||
// If not specified, it defaults to RestartNotRequired.
|
// If not specified, it defaults to RestartNotRequired.
|
||||||
Policy ResourceResizePolicy
|
RestartPolicy ResourceResizeRestartPolicy
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreemptionPolicy describes a policy for if/when to preempt a pod.
|
// PreemptionPolicy describes a policy for if/when to preempt a pod.
|
||||||
|
@ -3016,7 +3016,7 @@ func validatePullPolicy(policy core.PullPolicy, fldPath *field.Path) field.Error
|
|||||||
}
|
}
|
||||||
|
|
||||||
var supportedResizeResources = sets.NewString(string(core.ResourceCPU), string(core.ResourceMemory))
|
var supportedResizeResources = sets.NewString(string(core.ResourceCPU), string(core.ResourceMemory))
|
||||||
var supportedResizePolicies = sets.NewString(string(core.RestartNotRequired), string(core.RestartRequired))
|
var supportedResizePolicies = sets.NewString(string(core.RestartNotRequired), string(core.RestartContainer))
|
||||||
|
|
||||||
func validateResizePolicy(policyList []core.ContainerResizePolicy, fldPath *field.Path) field.ErrorList {
|
func validateResizePolicy(policyList []core.ContainerResizePolicy, fldPath *field.Path) field.ErrorList {
|
||||||
allErrors := field.ErrorList{}
|
allErrors := field.ErrorList{}
|
||||||
@ -3035,12 +3035,12 @@ func validateResizePolicy(policyList []core.ContainerResizePolicy, fldPath *fiel
|
|||||||
default:
|
default:
|
||||||
allErrors = append(allErrors, field.NotSupported(fldPath, p.ResourceName, supportedResizeResources.List()))
|
allErrors = append(allErrors, field.NotSupported(fldPath, p.ResourceName, supportedResizeResources.List()))
|
||||||
}
|
}
|
||||||
switch p.Policy {
|
switch p.RestartPolicy {
|
||||||
case core.RestartNotRequired, core.RestartRequired:
|
case core.RestartNotRequired, core.RestartContainer:
|
||||||
case "":
|
case "":
|
||||||
allErrors = append(allErrors, field.Required(fldPath, ""))
|
allErrors = append(allErrors, field.Required(fldPath, ""))
|
||||||
default:
|
default:
|
||||||
allErrors = append(allErrors, field.NotSupported(fldPath, p.Policy, supportedResizePolicies.List()))
|
allErrors = append(allErrors, field.NotSupported(fldPath, p.RestartPolicy, supportedResizePolicies.List()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return allErrors
|
return allErrors
|
||||||
|
@ -7009,7 +7009,7 @@ func TestValidatePullPolicy(t *testing.T) {
|
|||||||
func TestValidateResizePolicy(t *testing.T) {
|
func TestValidateResizePolicy(t *testing.T) {
|
||||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.InPlacePodVerticalScaling, true)()
|
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.InPlacePodVerticalScaling, true)()
|
||||||
tSupportedResizeResources := sets.NewString(string(core.ResourceCPU), string(core.ResourceMemory))
|
tSupportedResizeResources := sets.NewString(string(core.ResourceCPU), string(core.ResourceMemory))
|
||||||
tSupportedResizePolicies := sets.NewString(string(core.RestartNotRequired), string(core.RestartRequired))
|
tSupportedResizePolicies := sets.NewString(string(core.RestartNotRequired), string(core.RestartContainer))
|
||||||
type T struct {
|
type T struct {
|
||||||
PolicyList []core.ContainerResizePolicy
|
PolicyList []core.ContainerResizePolicy
|
||||||
ExpectError bool
|
ExpectError bool
|
||||||
@ -7018,22 +7018,22 @@ func TestValidateResizePolicy(t *testing.T) {
|
|||||||
testCases := map[string]T{
|
testCases := map[string]T{
|
||||||
"ValidCPUandMemoryPolicies": {
|
"ValidCPUandMemoryPolicies": {
|
||||||
[]core.ContainerResizePolicy{
|
[]core.ContainerResizePolicy{
|
||||||
{ResourceName: "cpu", Policy: "RestartNotRequired"},
|
{ResourceName: "cpu", RestartPolicy: "RestartNotRequired"},
|
||||||
{ResourceName: "memory", Policy: "RestartRequired"},
|
{ResourceName: "memory", RestartPolicy: "RestartContainer"},
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
nil,
|
nil,
|
||||||
},
|
},
|
||||||
"ValidCPUPolicy": {
|
"ValidCPUPolicy": {
|
||||||
[]core.ContainerResizePolicy{
|
[]core.ContainerResizePolicy{
|
||||||
{ResourceName: "cpu", Policy: "RestartRequired"},
|
{ResourceName: "cpu", RestartPolicy: "RestartContainer"},
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
nil,
|
nil,
|
||||||
},
|
},
|
||||||
"ValidMemoryPolicy": {
|
"ValidMemoryPolicy": {
|
||||||
[]core.ContainerResizePolicy{
|
[]core.ContainerResizePolicy{
|
||||||
{ResourceName: "memory", Policy: "RestartNotRequired"},
|
{ResourceName: "memory", RestartPolicy: "RestartNotRequired"},
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
nil,
|
nil,
|
||||||
@ -7045,39 +7045,39 @@ func TestValidateResizePolicy(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"ValidCPUandInvalidMemoryPolicy": {
|
"ValidCPUandInvalidMemoryPolicy": {
|
||||||
[]core.ContainerResizePolicy{
|
[]core.ContainerResizePolicy{
|
||||||
{ResourceName: "cpu", Policy: "RestartNotRequired"},
|
{ResourceName: "cpu", RestartPolicy: "RestartNotRequired"},
|
||||||
{ResourceName: "memory", Policy: "Restarrrt"},
|
{ResourceName: "memory", RestartPolicy: "Restarrrt"},
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
field.ErrorList{field.NotSupported(field.NewPath("field"), core.ResourceResizePolicy("Restarrrt"), tSupportedResizePolicies.List())},
|
field.ErrorList{field.NotSupported(field.NewPath("field"), core.ResourceResizeRestartPolicy("Restarrrt"), tSupportedResizePolicies.List())},
|
||||||
},
|
},
|
||||||
"ValidMemoryandInvalidCPUPolicy": {
|
"ValidMemoryandInvalidCPUPolicy": {
|
||||||
[]core.ContainerResizePolicy{
|
[]core.ContainerResizePolicy{
|
||||||
{ResourceName: "cpu", Policy: "RestartNotRequirrred"},
|
{ResourceName: "cpu", RestartPolicy: "RestartNotRequirrred"},
|
||||||
{ResourceName: "memory", Policy: "RestartRequired"},
|
{ResourceName: "memory", RestartPolicy: "RestartContainer"},
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
field.ErrorList{field.NotSupported(field.NewPath("field"), core.ResourceResizePolicy("RestartNotRequirrred"), tSupportedResizePolicies.List())},
|
field.ErrorList{field.NotSupported(field.NewPath("field"), core.ResourceResizeRestartPolicy("RestartNotRequirrred"), tSupportedResizePolicies.List())},
|
||||||
},
|
},
|
||||||
"InvalidResourceNameValidPolicy": {
|
"InvalidResourceNameValidPolicy": {
|
||||||
[]core.ContainerResizePolicy{
|
[]core.ContainerResizePolicy{
|
||||||
{ResourceName: "cpuuu", Policy: "RestartNotRequired"},
|
{ResourceName: "cpuuu", RestartPolicy: "RestartNotRequired"},
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
field.ErrorList{field.NotSupported(field.NewPath("field"), core.ResourceName("cpuuu"), tSupportedResizeResources.List())},
|
field.ErrorList{field.NotSupported(field.NewPath("field"), core.ResourceName("cpuuu"), tSupportedResizeResources.List())},
|
||||||
},
|
},
|
||||||
"ValidResourceNameMissingPolicy": {
|
"ValidResourceNameMissingPolicy": {
|
||||||
[]core.ContainerResizePolicy{
|
[]core.ContainerResizePolicy{
|
||||||
{ResourceName: "memory", Policy: ""},
|
{ResourceName: "memory", RestartPolicy: ""},
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
field.ErrorList{field.Required(field.NewPath("field"), "")},
|
field.ErrorList{field.Required(field.NewPath("field"), "")},
|
||||||
},
|
},
|
||||||
"RepeatedPolicies": {
|
"RepeatedPolicies": {
|
||||||
[]core.ContainerResizePolicy{
|
[]core.ContainerResizePolicy{
|
||||||
{ResourceName: "cpu", Policy: "RestartNotRequired"},
|
{ResourceName: "cpu", RestartPolicy: "RestartNotRequired"},
|
||||||
{ResourceName: "memory", Policy: "RestartRequired"},
|
{ResourceName: "memory", RestartPolicy: "RestartContainer"},
|
||||||
{ResourceName: "cpu", Policy: "RestartRequired"},
|
{ResourceName: "cpu", RestartPolicy: "RestartContainer"},
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
field.ErrorList{field.Duplicate(field.NewPath("field").Index(2), core.ResourceCPU)},
|
field.ErrorList{field.Duplicate(field.NewPath("field").Index(2), core.ResourceCPU)},
|
||||||
@ -7475,7 +7475,7 @@ func TestValidateEphemeralContainers(t *testing.T) {
|
|||||||
ImagePullPolicy: "IfNotPresent",
|
ImagePullPolicy: "IfNotPresent",
|
||||||
TerminationMessagePolicy: "File",
|
TerminationMessagePolicy: "File",
|
||||||
ResizePolicy: []core.ContainerResizePolicy{
|
ResizePolicy: []core.ContainerResizePolicy{
|
||||||
{ResourceName: "cpu", Policy: "RestartNotRequired"},
|
{ResourceName: "cpu", RestartPolicy: "RestartNotRequired"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -7702,8 +7702,8 @@ func TestValidateContainers(t *testing.T) {
|
|||||||
Name: "resources-resize-policy",
|
Name: "resources-resize-policy",
|
||||||
Image: "image",
|
Image: "image",
|
||||||
ResizePolicy: []core.ContainerResizePolicy{
|
ResizePolicy: []core.ContainerResizePolicy{
|
||||||
{ResourceName: "cpu", Policy: "RestartNotRequired"},
|
{ResourceName: "cpu", RestartPolicy: "RestartNotRequired"},
|
||||||
{ResourceName: "memory", Policy: "RestartRequired"},
|
{ResourceName: "memory", RestartPolicy: "RestartContainer"},
|
||||||
},
|
},
|
||||||
ImagePullPolicy: "IfNotPresent",
|
ImagePullPolicy: "IfNotPresent",
|
||||||
TerminationMessagePolicy: "File",
|
TerminationMessagePolicy: "File",
|
||||||
@ -9477,7 +9477,7 @@ func TestValidatePodSpec(t *testing.T) {
|
|||||||
Name: "initctr",
|
Name: "initctr",
|
||||||
Image: "initimage",
|
Image: "initimage",
|
||||||
ResizePolicy: []core.ContainerResizePolicy{
|
ResizePolicy: []core.ContainerResizePolicy{
|
||||||
{ResourceName: "cpu", Policy: "RestartNotRequired"},
|
{ResourceName: "cpu", RestartPolicy: "RestartNotRequired"},
|
||||||
},
|
},
|
||||||
ImagePullPolicy: "IfNotPresent",
|
ImagePullPolicy: "IfNotPresent",
|
||||||
TerminationMessagePolicy: "File",
|
TerminationMessagePolicy: "File",
|
||||||
@ -9488,7 +9488,7 @@ func TestValidatePodSpec(t *testing.T) {
|
|||||||
Name: "ctr",
|
Name: "ctr",
|
||||||
Image: "image",
|
Image: "image",
|
||||||
ResizePolicy: []core.ContainerResizePolicy{
|
ResizePolicy: []core.ContainerResizePolicy{
|
||||||
{ResourceName: "cpu", Policy: "RestartNotRequired"},
|
{ResourceName: "cpu", RestartPolicy: "RestartNotRequired"},
|
||||||
},
|
},
|
||||||
ImagePullPolicy: "IfNotPresent",
|
ImagePullPolicy: "IfNotPresent",
|
||||||
TerminationMessagePolicy: "File",
|
TerminationMessagePolicy: "File",
|
||||||
@ -20473,7 +20473,7 @@ func TestValidateOSFields(t *testing.T) {
|
|||||||
"Containers[*].Ports",
|
"Containers[*].Ports",
|
||||||
"Containers[*].ReadinessProbe",
|
"Containers[*].ReadinessProbe",
|
||||||
"Containers[*].Resources",
|
"Containers[*].Resources",
|
||||||
"Containers[*].ResizePolicy[*].Policy",
|
"Containers[*].ResizePolicy[*].RestartPolicy",
|
||||||
"Containers[*].ResizePolicy[*].ResourceName",
|
"Containers[*].ResizePolicy[*].ResourceName",
|
||||||
"Containers[*].SecurityContext.RunAsNonRoot",
|
"Containers[*].SecurityContext.RunAsNonRoot",
|
||||||
"Containers[*].Stdin",
|
"Containers[*].Stdin",
|
||||||
@ -20499,7 +20499,7 @@ func TestValidateOSFields(t *testing.T) {
|
|||||||
"EphemeralContainers[*].EphemeralContainerCommon.Ports",
|
"EphemeralContainers[*].EphemeralContainerCommon.Ports",
|
||||||
"EphemeralContainers[*].EphemeralContainerCommon.ReadinessProbe",
|
"EphemeralContainers[*].EphemeralContainerCommon.ReadinessProbe",
|
||||||
"EphemeralContainers[*].EphemeralContainerCommon.Resources",
|
"EphemeralContainers[*].EphemeralContainerCommon.Resources",
|
||||||
"EphemeralContainers[*].EphemeralContainerCommon.ResizePolicy[*].Policy",
|
"EphemeralContainers[*].EphemeralContainerCommon.ResizePolicy[*].RestartPolicy",
|
||||||
"EphemeralContainers[*].EphemeralContainerCommon.ResizePolicy[*].ResourceName",
|
"EphemeralContainers[*].EphemeralContainerCommon.ResizePolicy[*].ResourceName",
|
||||||
"EphemeralContainers[*].EphemeralContainerCommon.Stdin",
|
"EphemeralContainers[*].EphemeralContainerCommon.Stdin",
|
||||||
"EphemeralContainers[*].EphemeralContainerCommon.StdinOnce",
|
"EphemeralContainers[*].EphemeralContainerCommon.StdinOnce",
|
||||||
@ -20527,7 +20527,7 @@ func TestValidateOSFields(t *testing.T) {
|
|||||||
"InitContainers[*].Ports",
|
"InitContainers[*].Ports",
|
||||||
"InitContainers[*].ReadinessProbe",
|
"InitContainers[*].ReadinessProbe",
|
||||||
"InitContainers[*].Resources",
|
"InitContainers[*].Resources",
|
||||||
"InitContainers[*].ResizePolicy[*].Policy",
|
"InitContainers[*].ResizePolicy[*].RestartPolicy",
|
||||||
"InitContainers[*].ResizePolicy[*].ResourceName",
|
"InitContainers[*].ResizePolicy[*].ResourceName",
|
||||||
"InitContainers[*].Stdin",
|
"InitContainers[*].Stdin",
|
||||||
"InitContainers[*].StdinOnce",
|
"InitContainers[*].StdinOnce",
|
||||||
|
@ -915,10 +915,10 @@ func TestHashContainerWithoutResources(t *testing.T) {
|
|||||||
cpu200m := resource.MustParse("200m")
|
cpu200m := resource.MustParse("200m")
|
||||||
mem100M := resource.MustParse("100Mi")
|
mem100M := resource.MustParse("100Mi")
|
||||||
mem200M := resource.MustParse("200Mi")
|
mem200M := resource.MustParse("200Mi")
|
||||||
cpuPolicyRestartNotRequired := v1.ContainerResizePolicy{ResourceName: v1.ResourceCPU, Policy: v1.RestartNotRequired}
|
cpuPolicyRestartNotRequired := v1.ContainerResizePolicy{ResourceName: v1.ResourceCPU, RestartPolicy: v1.RestartNotRequired}
|
||||||
memPolicyRestartNotRequired := v1.ContainerResizePolicy{ResourceName: v1.ResourceMemory, Policy: v1.RestartNotRequired}
|
memPolicyRestartNotRequired := v1.ContainerResizePolicy{ResourceName: v1.ResourceMemory, RestartPolicy: v1.RestartNotRequired}
|
||||||
cpuPolicyRestartRequired := v1.ContainerResizePolicy{ResourceName: v1.ResourceCPU, Policy: v1.RestartRequired}
|
cpuPolicyRestartRequired := v1.ContainerResizePolicy{ResourceName: v1.ResourceCPU, RestartPolicy: v1.RestartContainer}
|
||||||
memPolicyRestartRequired := v1.ContainerResizePolicy{ResourceName: v1.ResourceMemory, Policy: v1.RestartRequired}
|
memPolicyRestartRequired := v1.ContainerResizePolicy{ResourceName: v1.ResourceMemory, RestartPolicy: v1.RestartContainer}
|
||||||
|
|
||||||
type testCase struct {
|
type testCase struct {
|
||||||
name string
|
name string
|
||||||
@ -938,7 +938,7 @@ func TestHashContainerWithoutResources(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ResizePolicy: []v1.ContainerResizePolicy{cpuPolicyRestartRequired, memPolicyRestartNotRequired},
|
ResizePolicy: []v1.ContainerResizePolicy{cpuPolicyRestartRequired, memPolicyRestartNotRequired},
|
||||||
},
|
},
|
||||||
0x86a4393c,
|
0xbf0fc03d,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Burstable pod with memory policy restart required",
|
"Burstable pod with memory policy restart required",
|
||||||
@ -951,7 +951,7 @@ func TestHashContainerWithoutResources(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ResizePolicy: []v1.ContainerResizePolicy{cpuPolicyRestartNotRequired, memPolicyRestartRequired},
|
ResizePolicy: []v1.ContainerResizePolicy{cpuPolicyRestartNotRequired, memPolicyRestartRequired},
|
||||||
},
|
},
|
||||||
0x73a18cce,
|
0x97dd7301,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Guaranteed pod with CPU policy restart required",
|
"Guaranteed pod with CPU policy restart required",
|
||||||
@ -964,7 +964,7 @@ func TestHashContainerWithoutResources(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ResizePolicy: []v1.ContainerResizePolicy{cpuPolicyRestartRequired, memPolicyRestartNotRequired},
|
ResizePolicy: []v1.ContainerResizePolicy{cpuPolicyRestartRequired, memPolicyRestartNotRequired},
|
||||||
},
|
},
|
||||||
0x86a4393c,
|
0xbf0fc03d,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Guaranteed pod with memory policy restart required",
|
"Guaranteed pod with memory policy restart required",
|
||||||
@ -977,7 +977,7 @@ func TestHashContainerWithoutResources(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ResizePolicy: []v1.ContainerResizePolicy{cpuPolicyRestartNotRequired, memPolicyRestartRequired},
|
ResizePolicy: []v1.ContainerResizePolicy{cpuPolicyRestartNotRequired, memPolicyRestartRequired},
|
||||||
},
|
},
|
||||||
0x73a18cce,
|
0x97dd7301,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
|
@ -580,15 +580,15 @@ func (m *kubeGenericRuntimeManager) computePodResizeAction(pod *v1.Pod, containe
|
|||||||
cpuRequest: currentCPURequest,
|
cpuRequest: currentCPURequest,
|
||||||
}
|
}
|
||||||
|
|
||||||
resizePolicy := make(map[v1.ResourceName]v1.ResourceResizePolicy)
|
resizePolicy := make(map[v1.ResourceName]v1.ResourceResizeRestartPolicy)
|
||||||
for _, pol := range container.ResizePolicy {
|
for _, pol := range container.ResizePolicy {
|
||||||
resizePolicy[pol.ResourceName] = pol.Policy
|
resizePolicy[pol.ResourceName] = pol.RestartPolicy
|
||||||
}
|
}
|
||||||
determineContainerResize := func(rName v1.ResourceName, specValue, statusValue int64) (resize, restart bool) {
|
determineContainerResize := func(rName v1.ResourceName, specValue, statusValue int64) (resize, restart bool) {
|
||||||
if specValue == statusValue {
|
if specValue == statusValue {
|
||||||
return false, false
|
return false, false
|
||||||
}
|
}
|
||||||
if resizePolicy[rName] == v1.RestartRequired {
|
if resizePolicy[rName] == v1.RestartContainer {
|
||||||
return true, true
|
return true, true
|
||||||
}
|
}
|
||||||
return true, false
|
return true, false
|
||||||
|
@ -1654,10 +1654,10 @@ func TestComputePodActionsForPodResize(t *testing.T) {
|
|||||||
cpu200m := resource.MustParse("200m")
|
cpu200m := resource.MustParse("200m")
|
||||||
mem100M := resource.MustParse("100Mi")
|
mem100M := resource.MustParse("100Mi")
|
||||||
mem200M := resource.MustParse("200Mi")
|
mem200M := resource.MustParse("200Mi")
|
||||||
cpuPolicyRestartNotRequired := v1.ContainerResizePolicy{ResourceName: v1.ResourceCPU, Policy: v1.RestartNotRequired}
|
cpuPolicyRestartNotRequired := v1.ContainerResizePolicy{ResourceName: v1.ResourceCPU, RestartPolicy: v1.RestartNotRequired}
|
||||||
memPolicyRestartNotRequired := v1.ContainerResizePolicy{ResourceName: v1.ResourceMemory, Policy: v1.RestartNotRequired}
|
memPolicyRestartNotRequired := v1.ContainerResizePolicy{ResourceName: v1.ResourceMemory, RestartPolicy: v1.RestartNotRequired}
|
||||||
cpuPolicyRestartRequired := v1.ContainerResizePolicy{ResourceName: v1.ResourceCPU, Policy: v1.RestartRequired}
|
cpuPolicyRestartRequired := v1.ContainerResizePolicy{ResourceName: v1.ResourceCPU, RestartPolicy: v1.RestartContainer}
|
||||||
memPolicyRestartRequired := v1.ContainerResizePolicy{ResourceName: v1.ResourceMemory, Policy: v1.RestartRequired}
|
memPolicyRestartRequired := v1.ContainerResizePolicy{ResourceName: v1.ResourceMemory, RestartPolicy: v1.RestartContainer}
|
||||||
|
|
||||||
for desc, test := range map[string]struct {
|
for desc, test := range map[string]struct {
|
||||||
podResizePolicyFn func(*v1.Pod)
|
podResizePolicyFn func(*v1.Pod)
|
||||||
|
@ -2263,31 +2263,31 @@ const (
|
|||||||
PullIfNotPresent PullPolicy = "IfNotPresent"
|
PullIfNotPresent PullPolicy = "IfNotPresent"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ResourceResizePolicy specifies how Kubernetes should handle resource resize.
|
// ResourceResizeRestartPolicy specifies how to handle container resource resize.
|
||||||
type ResourceResizePolicy string
|
type ResourceResizeRestartPolicy string
|
||||||
|
|
||||||
// These are the valid resource resize policy values:
|
// These are the valid resource resize restart policy values:
|
||||||
const (
|
const (
|
||||||
// RestartNotRequired tells Kubernetes to resize the container in-place
|
// 'RestartNotRequired' means Kubernetes will try to resize the container
|
||||||
// without restarting it, if possible. Kubernetes may however choose to
|
// without restarting it, if possible. Kubernetes may however choose to
|
||||||
// restart the container if it is unable to actuate resize without a
|
// restart the container if it is unable to actuate resize without a
|
||||||
// restart. For e.g. the runtime doesn't support restart-free resizing.
|
// restart. For e.g. the runtime doesn't support restart-free resizing.
|
||||||
RestartNotRequired ResourceResizePolicy = "RestartNotRequired"
|
RestartNotRequired ResourceResizeRestartPolicy = "RestartNotRequired"
|
||||||
// 'RestartRequired' tells Kubernetes to resize the container in-place
|
// 'RestartContainer' means Kubernetes will resize the container in-place
|
||||||
// by stopping and starting the container when new resources are applied.
|
// by stopping and starting the container when new resources are applied.
|
||||||
// This is needed for legacy applications. For e.g. java apps using the
|
// This is needed for legacy applications. For e.g. java apps using the
|
||||||
// -xmxN flag which are unable to use resized memory without restarting.
|
// -xmxN flag which are unable to use resized memory without restarting.
|
||||||
RestartRequired ResourceResizePolicy = "RestartRequired"
|
RestartContainer ResourceResizeRestartPolicy = "RestartContainer"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerResizePolicy represents resource resize policy for a single container.
|
// ContainerResizePolicy represents resource resize policy for the container.
|
||||||
type ContainerResizePolicy struct {
|
type ContainerResizePolicy struct {
|
||||||
// Name of the resource type to which this resource resize policy applies.
|
// Name of the resource to which this resource resize policy applies.
|
||||||
// Supported values: cpu, memory.
|
// Supported values: cpu, memory.
|
||||||
ResourceName ResourceName `json:"resourceName" protobuf:"bytes,1,opt,name=resourceName,casttype=ResourceName"`
|
ResourceName ResourceName `json:"resourceName" protobuf:"bytes,1,opt,name=resourceName,casttype=ResourceName"`
|
||||||
// Resource resize policy applicable to the specified resource name.
|
// Restart policy to apply when specified resource is resized.
|
||||||
// If not specified, it defaults to RestartNotRequired.
|
// If not specified, it defaults to RestartNotRequired.
|
||||||
Policy ResourceResizePolicy `json:"policy" protobuf:"bytes,2,opt,name=policy,casttype=ResourceResizePolicy"`
|
RestartPolicy ResourceResizeRestartPolicy `json:"restartPolicy" protobuf:"bytes,2,opt,name=restartPolicy,casttype=ResourceResizeRestartPolicy"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreemptionPolicy describes a policy for if/when to preempt a pod.
|
// PreemptionPolicy describes a policy for if/when to preempt a pod.
|
||||||
|
@ -74,8 +74,8 @@ type TestContainerInfo struct {
|
|||||||
Name string
|
Name string
|
||||||
Resources *ContainerResources
|
Resources *ContainerResources
|
||||||
Allocations *ContainerAllocations
|
Allocations *ContainerAllocations
|
||||||
CPUPolicy *v1.ResourceResizePolicy
|
CPUPolicy *v1.ResourceResizeRestartPolicy
|
||||||
MemPolicy *v1.ResourceResizePolicy
|
MemPolicy *v1.ResourceResizeRestartPolicy
|
||||||
RestartCount int32
|
RestartCount int32
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,11 +146,11 @@ func getTestResourceInfo(tcInfo TestContainerInfo) (v1.ResourceRequirements, v1.
|
|||||||
|
|
||||||
}
|
}
|
||||||
if tcInfo.CPUPolicy != nil {
|
if tcInfo.CPUPolicy != nil {
|
||||||
cpuPol := v1.ContainerResizePolicy{ResourceName: v1.ResourceCPU, Policy: *tcInfo.CPUPolicy}
|
cpuPol := v1.ContainerResizePolicy{ResourceName: v1.ResourceCPU, RestartPolicy: *tcInfo.CPUPolicy}
|
||||||
resizePol = append(resizePol, cpuPol)
|
resizePol = append(resizePol, cpuPol)
|
||||||
}
|
}
|
||||||
if tcInfo.MemPolicy != nil {
|
if tcInfo.MemPolicy != nil {
|
||||||
memPol := v1.ContainerResizePolicy{ResourceName: v1.ResourceMemory, Policy: *tcInfo.MemPolicy}
|
memPol := v1.ContainerResizePolicy{ResourceName: v1.ResourceMemory, RestartPolicy: *tcInfo.MemPolicy}
|
||||||
resizePol = append(resizePol, memPol)
|
resizePol = append(resizePol, memPol)
|
||||||
}
|
}
|
||||||
return res, alloc, resizePol
|
return res, alloc, resizePol
|
||||||
@ -501,7 +501,7 @@ func doPodResizeTests() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
noRestart := v1.RestartNotRequired
|
noRestart := v1.RestartNotRequired
|
||||||
doRestart := v1.RestartRequired
|
doRestart := v1.RestartContainer
|
||||||
tests := []testCase{
|
tests := []testCase{
|
||||||
{
|
{
|
||||||
name: "Guaranteed QoS pod, one container - increase CPU & memory",
|
name: "Guaranteed QoS pod, one container - increase CPU & memory",
|
||||||
@ -1010,7 +1010,7 @@ func doPodResizeTests() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Guaranteed QoS pod, one container - increase CPU (RestartNotRequired) & memory (RestartRequired)",
|
name: "Guaranteed QoS pod, one container - increase CPU (RestartNotRequired) & memory (RestartContainer)",
|
||||||
containers: []TestContainerInfo{
|
containers: []TestContainerInfo{
|
||||||
{
|
{
|
||||||
Name: "c1",
|
Name: "c1",
|
||||||
@ -1033,7 +1033,7 @@ func doPodResizeTests() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Burstable QoS pod, one container - decrease CPU (RestartRequired) & memory (RestartNotRequired)",
|
name: "Burstable QoS pod, one container - decrease CPU (RestartContainer) & memory (RestartNotRequired)",
|
||||||
containers: []TestContainerInfo{
|
containers: []TestContainerInfo{
|
||||||
{
|
{
|
||||||
Name: "c1",
|
Name: "c1",
|
||||||
|
Loading…
Reference in New Issue
Block a user