Skip to content

Commit 8c6000c

Browse files
committed
Fix condition where due to patching spec.replicas became smaller than spec.scaling.minReplicas
Signed-off-by: Oliver Trosien <oliver.trosien@zalando.de>
1 parent 3ec2486 commit 8c6000c

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

operator/elasticsearch.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"math"
87
"net/url"
98
"sync"
109
"time"
@@ -816,14 +815,16 @@ 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.
821820
func (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+
// Initially, in case autoscaling is enabled and spec.Replicas is nil, it will return 0,
827+
// leaving the actual scaling target to be calculated by scaleEDS.
827828
func edsReplicas(eds *zv1.ElasticsearchDataSet) int32 {
828829
scaling := eds.Spec.Scaling
829830
if scaling == nil || !scaling.Enabled {
@@ -832,13 +833,11 @@ func edsReplicas(eds *zv1.ElasticsearchDataSet) int32 {
832833
}
833834
return *eds.Spec.Replicas
834835
}
835-
// initialize with minReplicas
836-
minReplicas := eds.Spec.Scaling.MinReplicas
836+
// initialize with 0
837837
if eds.Spec.Replicas == nil {
838-
return minReplicas
838+
return 0
839839
}
840-
currentReplicas := *eds.Spec.Replicas
841-
return int32(math.Max(float64(currentReplicas), float64(scaling.MinReplicas)))
840+
return *eds.Spec.Replicas
842841
}
843842

844843
// collectResources collects all the ElasticsearchDataSet resources and there

0 commit comments

Comments
 (0)