Skip to content
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

[Autoscaling] Do not delete existing resources #7678

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Autoscaling policies can be defined in an `ElasticsearchAutoscaler` resource. Ea
** `cpu` and `memory` enforce minimum and maximum compute resources usage for the Elasticsearch container.
** `storage` enforces minimum and maximum storage request per PersistentVolumeClaim.

If there is no recommendation from the Autoscaling API for a given resource, and if this resource is not set in the policy, then the resource is not managed by the operator and existing requirements in the NodeSets remain unchanged.

[source,yaml]
----
apiVersion: autoscaling.k8s.elastic.co/v1alpha1
Expand Down
6 changes: 1 addition & 5 deletions pkg/apis/common/v1alpha1/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func newNodeSetNodeCountList(nodeSetNames []string) NodeSetNodeCountList {

// ToContainerResourcesWith builds new ResourceRequirements for Memory and CPU, overriding existing values from the provided
// ResourceRequirements with the values from the NodeResources.
// If a value in the NodeResources is not present then the value in the result is removed.
// If there is no recommendations for a given resource, then its current value remains unchanged.
// Values for extended resources (e.g. GPU), are left untouched.
// This function has no side effect and does not modify the original ResourceRequirements.
func (nr *NodeResources) ToContainerResourcesWith(sourceRequirements corev1.ResourceRequirements) corev1.ResourceRequirements {
Expand All @@ -101,8 +101,6 @@ func (nr *NodeResources) ToContainerResourcesWith(sourceRequirements corev1.Reso
for _, resourceName := range []corev1.ResourceName{corev1.ResourceCPU, corev1.ResourceMemory} {
if nr.HasRequest(resourceName) {
mergedResources.Requests[resourceName] = nr.GetRequest(resourceName)
} else {
delete(mergedResources.Requests, resourceName)
}
}

Expand All @@ -113,8 +111,6 @@ func (nr *NodeResources) ToContainerResourcesWith(sourceRequirements corev1.Reso
for _, resourceName := range []corev1.ResourceName{corev1.ResourceCPU, corev1.ResourceMemory} {
if nr.HasLimit(resourceName) {
mergedResources.Limits[resourceName] = nr.GetLimit(resourceName)
} else {
delete(mergedResources.Limits, resourceName)
}
}
return *mergedResources
Expand Down
14 changes: 7 additions & 7 deletions pkg/apis/common/v1alpha1/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,34 @@ func TestNodeResources_ToContainerResourcesWith(t *testing.T) {
},
},
{
name: "Remove a requirements if not present",
name: "Preserve original requirements if not present",
fields: fields{
Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceCPU: resource.MustParse("2"),
// no recommendation for corev1.ResourceCPU
corev1.ResourceMemory: resource.MustParse("8Gi"),
},
Limits: map[corev1.ResourceName]resource.Quantity{
// corev1.ResourceCPU is not expected
// no recommendation for corev1.ResourceCPU
corev1.ResourceMemory: resource.MustParse("8Gi"),
},
},
args: args{into: corev1.ResourceRequirements{
Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceCPU: resource.MustParse("1"), // should be preserved in the result
corev1.ResourceMemory: resource.MustParse("4Gi"),
},
Limits: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceCPU: resource.MustParse("2"), // should be removed in the result
corev1.ResourceCPU: resource.MustParse("2"), // should be preserved in the result
corev1.ResourceMemory: resource.MustParse("4Gi"),
},
}},
want: corev1.ResourceRequirements{
Requests: map[corev1.ResourceName]resource.Quantity{
corev1.ResourceCPU: resource.MustParse("2"),
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("8Gi"),
},
Limits: map[corev1.ResourceName]resource.Quantity{
// corev1.ResourceCPU is not expected
corev1.ResourceCPU: resource.MustParse("2"),
corev1.ResourceMemory: resource.MustParse("8Gi"),
},
},
Expand Down