in pkg/controller/autoscaling/elasticsearch/status/actual.go [73:139]
func nodeSetsResourcesResourcesFromStatefulSets(
c k8s.Client,
es esv1.Elasticsearch,
autoscalingPolicySpec v1alpha1.AutoscalingPolicySpec,
nodeSets []string,
) (*v1alpha1.NodeSetsResources, error) {
nodeSetsResources := v1alpha1.NodeSetsResources{
Name: autoscalingPolicySpec.Name,
}
found := false
// For each nodeSet:
// 1. we try to get the corresponding StatefulSet
// 2. we build a NodeSetsResources from the max. resources of each StatefulSet
for _, nodeSetName := range nodeSets {
statefulSetName := esv1.StatefulSet(es.Name, nodeSetName)
statefulSet := appsv1.StatefulSet{}
err := c.Get(
context.Background(),
client.ObjectKey{
Namespace: es.Namespace,
Name: statefulSetName,
}, &statefulSet)
if errors.IsNotFound(err) {
continue
}
if err != nil {
return nil, err
}
found = true
nodeSetsResources.NodeSetNodeCount = append(nodeSetsResources.NodeSetNodeCount, v1alpha1.NodeSetNodeCount{
Name: nodeSetName,
NodeCount: getStatefulSetReplicas(statefulSet),
})
// Get data volume volume size
ssetStorageRequest, err := getElasticsearchDataVolumeQuantity(statefulSet)
if err != nil {
return nil, err
}
if ssetStorageRequest != nil && autoscalingPolicySpec.IsStorageDefined() {
if nodeSetsResources.HasRequest(corev1.ResourceStorage) {
if ssetStorageRequest.Cmp(nodeSetsResources.GetRequest(corev1.ResourceStorage)) > 0 {
nodeSetsResources.SetRequest(corev1.ResourceStorage, *ssetStorageRequest)
}
} else {
nodeSetsResources.SetRequest(corev1.ResourceStorage, *ssetStorageRequest)
}
}
// Get the memory and the CPU if any
container := getContainer(esv1.ElasticsearchContainerName, statefulSet.Spec.Template.Spec.Containers)
if container == nil {
continue
}
if autoscalingPolicySpec.IsMemoryDefined() {
nodeSetsResources.MaxMerge(container.Resources, corev1.ResourceMemory)
}
if autoscalingPolicySpec.IsCPUDefined() {
nodeSetsResources.MaxMerge(container.Resources, corev1.ResourceCPU)
}
}
if !found {
return nil, nil
}
return &nodeSetsResources, nil
}