Skip to content

Commit

Permalink
[Autoscaling] Do not delete existing resources (#7678)
Browse files Browse the repository at this point in the history
* [Autoscaling] Do not delete resources when no recommendations

* Update documentation
  • Loading branch information
barkbay authored Mar 29, 2024
1 parent 4a53631 commit a2f9065
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
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

0 comments on commit a2f9065

Please sign in to comment.