Skip to content

Commit 3fbba09

Browse files
authored
bugfix: validate maxReplica when minReplica is set for autoscaler (#4215)
* added check for maxReplica when minReplica is set for autoscaler Signed-off-by: carsontham <carsontham@outlook.com> * fix lint --------- Signed-off-by: carsontham <carsontham@outlook.com>
1 parent 30c2c04 commit 3fbba09

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: bug_fix
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: collector
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: added check for maxReplica when minReplica is set in autoscaler
9+
10+
# One or more tracking issues related to the change
11+
issues: [4160]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext: When using the AutoScaler, maxReplica must be set when minReplica is set.
17+
18+

apis/v1beta1/collector_webhook.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ func (c CollectorWebhook) Validate(ctx context.Context, r *OpenTelemetryCollecto
230230
if r.Spec.Autoscaler != nil && r.Spec.Autoscaler.MinReplicas != nil {
231231
minReplicas = r.Spec.Autoscaler.MinReplicas
232232
}
233+
234+
if r.Spec.Autoscaler != nil && r.Spec.Autoscaler.MinReplicas != nil && r.Spec.Autoscaler.MaxReplicas == nil {
235+
return warnings, fmt.Errorf("spec.maxReplica must be set when spec.minReplica is set")
236+
}
237+
233238
// check deprecated .Spec.MinReplicas if minReplicas is not set
234239
if minReplicas == nil {
235240
minReplicas = r.Spec.Replicas

apis/v1beta1/collector_webhook_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,17 @@ func TestOTELColValidatingWebhook(t *testing.T) {
919919
},
920920
expectedErr: "maxReplicas should be defined and one or more",
921921
},
922+
{
923+
name: "it should return error when minReplica is set but maxReplica is not set",
924+
otelcol: v1beta1.OpenTelemetryCollector{
925+
Spec: v1beta1.OpenTelemetryCollectorSpec{
926+
Autoscaler: &v1beta1.AutoscalerSpec{
927+
MinReplicas: &three,
928+
},
929+
},
930+
},
931+
expectedErr: "spec.maxReplica must be set when spec.minReplica is set",
932+
},
922933
{
923934
name: "invalid replicas, greater than max",
924935
otelcol: v1beta1.OpenTelemetryCollector{

0 commit comments

Comments
 (0)