Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle deprecated replicas in conversion #2723

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading