You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Verify that the autoscaler correctly identifies scaling is needed
797
+
require.NotNil(t, scalingOperation.NodeReplicas, "NodeReplicas should not be nil when scaling is needed")
798
+
require.Equal(t, int32(4), *scalingOperation.NodeReplicas, "Should scale to minReplicas (4)")
799
+
require.Equal(t, UP, scalingOperation.ScalingDirection, "Should indicate scale up direction")
800
+
801
+
// The key assertion: with the fix, edsReplicas() still returns 3 (not 4)
802
+
// This allows the comparison at operator/elasticsearch.go:945 to work correctly:
803
+
// if *scalingOperation.NodeReplicas != currentReplicas (4 != 3 = true)
804
+
currentReplicasAfter:=edsReplicas(eds)
805
+
require.Equal(t, int32(3), currentReplicasAfter, "edsReplicas should still return actual spec.replicas (3), allowing autoscaler to detect change")
806
+
require.NotEqual(t, *scalingOperation.NodeReplicas, currentReplicasAfter, "Target replicas (4) should differ from current replicas (3), triggering spec update")
807
+
}
808
+
809
+
// TestScalingBoundaryChangeScaleDown verifies the same behavior for scale-down scenarios.
810
+
// When maxReplicas is decreased below current replicas, the autoscaler should detect
811
+
// the need to scale down based on shard distribution and boundary constraints.
// Verify that the autoscaler correctly identifies scaling down is needed
872
+
require.NotNil(t, scalingOperation.NodeReplicas, "NodeReplicas should not be nil when scaling is needed")
873
+
// The autoscaler will want to scale down index replicas from 2 to 1
874
+
// and adjust node count accordingly, bounded by maxReplicas=3
875
+
require.LessOrEqual(t, *scalingOperation.NodeReplicas, int32(3), "Should not exceed maxReplicas (3)")
876
+
require.Equal(t, DOWN, scalingOperation.ScalingDirection, "Should indicate scale down direction")
877
+
878
+
// Verify edsReplicas() still returns the actual value, not the bounded value
879
+
currentReplicasAfter:=edsReplicas(eds)
880
+
require.Equal(t, int32(6), currentReplicasAfter, "edsReplicas should still return actual spec.replicas (6)")
881
+
require.NotEqual(t, *scalingOperation.NodeReplicas, currentReplicasAfter, "Target replicas should differ from current replicas (6), triggering spec update")
882
+
}
883
+
884
+
// TestInitialScalingWithNilReplicas verifies that when spec.replicas is nil
885
+
// and autoscaling is enabled, edsReplicas() returns 0, allowing the autoscaler
0 commit comments