Skip to content

Commit

Permalink
Handle deprecated replicas in conversion (#2723)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
  • Loading branch information
pavolloffay authored Mar 6, 2024
1 parent 2e5339c commit 3c85a52
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion apis/v1alpha1/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,14 @@ func tov1beta1TA(in OpenTelemetryTargetAllocator) v1beta1.TargetAllocatorEmbedde
}
}

// The conversion takes into account deprecated v1alpha1 spec.minReplicas and spec.maxReplicas.
func tov1beta1Autoscaler(in *AutoscalerSpec, minReplicas, maxReplicas *int32) *v1beta1.AutoscalerSpec {
if in == nil {
if in == nil && minReplicas == nil && maxReplicas == nil {
return nil
}
if in == nil {
in = &AutoscalerSpec{}
}

var metrics []v1beta1.MetricSpec
for _, m := range in.Metrics {
Expand Down
25 changes: 25 additions & 0 deletions apis/v1alpha1/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,31 @@ func Test_tov1beta1AndBack_prometheus_selectors(t *testing.T) {
})
}

func Test_tov1beta1AndBack_deprecated_replicas(t *testing.T) {
one := int32(1)
two := int32(2)
colalpha1 := OpenTelemetryCollector{
Spec: OpenTelemetryCollectorSpec{
MinReplicas: &one,
MaxReplicas: &two,
},
}

colbeta1 := v1beta1.OpenTelemetryCollector{}
err := colalpha1.ConvertTo(&colbeta1)
require.NoError(t, err)

assert.Equal(t, one, *colbeta1.Spec.Autoscaler.MinReplicas)
assert.Equal(t, two, *colbeta1.Spec.Autoscaler.MaxReplicas)

err = colalpha1.ConvertFrom(&colbeta1)
require.NoError(t, err)
assert.Nil(t, colalpha1.Spec.MinReplicas)
assert.Nil(t, colalpha1.Spec.MaxReplicas)
assert.Equal(t, one, *colalpha1.Spec.Autoscaler.MinReplicas)
assert.Equal(t, two, *colalpha1.Spec.Autoscaler.MaxReplicas)
}

func createTA() OpenTelemetryTargetAllocator {
replicas := int32(2)
runAsNonRoot := true
Expand Down

0 comments on commit 3c85a52

Please sign in to comment.