44 "context"
55 "encoding/json"
66 "fmt"
7- "math"
87 "net/url"
98 "sync"
109 "time"
@@ -816,14 +815,18 @@ type ESResource struct {
816815 Pods []v1.Pod
817816}
818817
819- // Replicas returns the desired node replicas of an ElasticsearchDataSet
820- // In case it was not specified, it will return '1' .
818+ // Replicas returns the desired node replicas of an ElasticsearchDataSet.
819+ // For implementation details, see edsReplicas .
821820func (es * ESResource ) Replicas () int32 {
822821 return edsReplicas (es .ElasticsearchDataSet )
823822}
824823
825824// edsReplicas returns the desired node replicas of an ElasticsearchDataSet
826- // In case it was not specified, it will return '1'.
825+ // as determined through spec.Replicas and autoscaling settings.
826+ // If unset, and autoscaling is disabled, it will return 1 as the default value.
827+ // In case autoscaling is enabled and spec.Replicas is nil, it will return 0,
828+ // leaving the actual scaling target to be calculated by scaleEDS, which will
829+ // then set spec.Replicas accordingly.
827830func edsReplicas (eds * zv1.ElasticsearchDataSet ) int32 {
828831 scaling := eds .Spec .Scaling
829832 if scaling == nil || ! scaling .Enabled {
@@ -832,13 +835,11 @@ func edsReplicas(eds *zv1.ElasticsearchDataSet) int32 {
832835 }
833836 return * eds .Spec .Replicas
834837 }
835- // initialize with minReplicas
836- minReplicas := eds .Spec .Scaling .MinReplicas
838+ // initialize with 0
837839 if eds .Spec .Replicas == nil {
838- return minReplicas
840+ return 0
839841 }
840- currentReplicas := * eds .Spec .Replicas
841- return int32 (math .Max (float64 (currentReplicas ), float64 (scaling .MinReplicas )))
842+ return * eds .Spec .Replicas
842843}
843844
844845// collectResources collects all the ElasticsearchDataSet resources and there
0 commit comments