Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e5040f6

Browse files
committedJan 18, 2024
internal/manifests/collector: switch internally to v1alphav2
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
1 parent fbd27e5 commit e5040f6

25 files changed

+684
-334
lines changed
 

‎controllers/builder_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ service:
124124
"app.kubernetes.io/version": "latest",
125125
},
126126
Annotations: map[string]string{
127-
"opentelemetry-operator-config/sha256": "8188c85abd4aa5e9c798874b4f47d37f08d4778933154e3f7d60246510ed9dd2",
127+
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
128128
"prometheus.io/path": "/metrics",
129129
"prometheus.io/port": "8888",
130130
"prometheus.io/scrape": "true",
@@ -146,7 +146,7 @@ service:
146146
"app.kubernetes.io/version": "latest",
147147
},
148148
Annotations: map[string]string{
149-
"opentelemetry-operator-config/sha256": "8188c85abd4aa5e9c798874b4f47d37f08d4778933154e3f7d60246510ed9dd2",
149+
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
150150
"prometheus.io/path": "/metrics",
151151
"prometheus.io/port": "8888",
152152
"prometheus.io/scrape": "true",
@@ -367,7 +367,7 @@ service:
367367
"app.kubernetes.io/version": "latest",
368368
},
369369
Annotations: map[string]string{
370-
"opentelemetry-operator-config/sha256": "8188c85abd4aa5e9c798874b4f47d37f08d4778933154e3f7d60246510ed9dd2",
370+
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
371371
"prometheus.io/path": "/metrics",
372372
"prometheus.io/port": "8888",
373373
"prometheus.io/scrape": "true",
@@ -389,7 +389,7 @@ service:
389389
"app.kubernetes.io/version": "latest",
390390
},
391391
Annotations: map[string]string{
392-
"opentelemetry-operator-config/sha256": "8188c85abd4aa5e9c798874b4f47d37f08d4778933154e3f7d60246510ed9dd2",
392+
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
393393
"prometheus.io/path": "/metrics",
394394
"prometheus.io/port": "8888",
395395
"prometheus.io/scrape": "true",
@@ -643,7 +643,7 @@ service:
643643
"app.kubernetes.io/version": "latest",
644644
},
645645
Annotations: map[string]string{
646-
"opentelemetry-operator-config/sha256": "8188c85abd4aa5e9c798874b4f47d37f08d4778933154e3f7d60246510ed9dd2",
646+
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
647647
"prometheus.io/path": "/metrics",
648648
"prometheus.io/port": "8888",
649649
"prometheus.io/scrape": "true",
@@ -665,7 +665,7 @@ service:
665665
"app.kubernetes.io/version": "latest",
666666
},
667667
Annotations: map[string]string{
668-
"opentelemetry-operator-config/sha256": "8188c85abd4aa5e9c798874b4f47d37f08d4778933154e3f7d60246510ed9dd2",
668+
"opentelemetry-operator-config/sha256": "6f6f11da374b2c1e42fc78fbe55e2d9bcc2f5998ab63a631b49c478e8c0f6af8",
669669
"prometheus.io/path": "/metrics",
670670
"prometheus.io/port": "8888",
671671
"prometheus.io/scrape": "true",
@@ -1153,7 +1153,7 @@ service:
11531153
"app.kubernetes.io/version": "latest",
11541154
},
11551155
Annotations: map[string]string{
1156-
"opentelemetry-operator-config/sha256": "5fe4d7d7faf3247bd7ec88688c9f73618f9ab8e170362bd7203c54e7a2f5cec0",
1156+
"opentelemetry-operator-config/sha256": "39cae697770f9d7e183e8fa9ba56043315b62e19c7231537870acfaaabc30a43",
11571157
"prometheus.io/path": "/metrics",
11581158
"prometheus.io/port": "8888",
11591159
"prometheus.io/scrape": "true",
@@ -1176,7 +1176,7 @@ service:
11761176
"app.kubernetes.io/version": "latest",
11771177
},
11781178
Annotations: map[string]string{
1179-
"opentelemetry-operator-config/sha256": "5fe4d7d7faf3247bd7ec88688c9f73618f9ab8e170362bd7203c54e7a2f5cec0",
1179+
"opentelemetry-operator-config/sha256": "39cae697770f9d7e183e8fa9ba56043315b62e19c7231537870acfaaabc30a43",
11801180
"prometheus.io/path": "/metrics",
11811181
"prometheus.io/port": "8888",
11821182
"prometheus.io/scrape": "true",
@@ -1544,7 +1544,7 @@ label_selector:
15441544
"app.kubernetes.io/version": "latest",
15451545
},
15461546
Annotations: map[string]string{
1547-
"opentelemetry-operator-config/sha256": "5fe4d7d7faf3247bd7ec88688c9f73618f9ab8e170362bd7203c54e7a2f5cec0",
1547+
"opentelemetry-operator-config/sha256": "39cae697770f9d7e183e8fa9ba56043315b62e19c7231537870acfaaabc30a43",
15481548
"prometheus.io/path": "/metrics",
15491549
"prometheus.io/port": "8888",
15501550
"prometheus.io/scrape": "true",
@@ -1567,7 +1567,7 @@ label_selector:
15671567
"app.kubernetes.io/version": "latest",
15681568
},
15691569
Annotations: map[string]string{
1570-
"opentelemetry-operator-config/sha256": "5fe4d7d7faf3247bd7ec88688c9f73618f9ab8e170362bd7203c54e7a2f5cec0",
1570+
"opentelemetry-operator-config/sha256": "39cae697770f9d7e183e8fa9ba56043315b62e19c7231537870acfaaabc30a43",
15711571
"prometheus.io/path": "/metrics",
15721572
"prometheus.io/port": "8888",
15731573
"prometheus.io/scrape": "true",

‎internal/api/convert/v1alpha.go

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package convert
16+
17+
import (
18+
"encoding/json"
19+
"fmt"
20+
21+
appsv1 "k8s.io/api/apps/v1"
22+
"sigs.k8s.io/yaml"
23+
24+
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
25+
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha2"
26+
)
27+
28+
func V1Alpha1to2(in v1alpha1.OpenTelemetryCollector) v1alpha2.OpenTelemetryCollector {
29+
copy := in.DeepCopy()
30+
out := v1alpha2.OpenTelemetryCollector{
31+
TypeMeta: copy.TypeMeta,
32+
ObjectMeta: copy.ObjectMeta,
33+
}
34+
35+
collectorJson, err := yaml.YAMLToJSON([]byte(in.Spec.Config))
36+
if err != nil {
37+
panic(fmt.Sprintf("could not convert v1alpha1 yaml config to json, err: %s", err))
38+
}
39+
40+
cfg := &v1alpha2.Config{}
41+
if err := json.Unmarshal(collectorJson, cfg); err != nil {
42+
panic(fmt.Sprintf("could not convert v1alpha1 config to v1alpha2, err: %s", err))
43+
}
44+
out.Spec.Config = *cfg
45+
46+
out.Spec.OpenTelemetryCommonFields.ManagementState = v1alpha2.ManagementStateType(copy.Spec.ManagementState)
47+
out.Spec.OpenTelemetryCommonFields.Resources = copy.Spec.Resources
48+
out.Spec.OpenTelemetryCommonFields.NodeSelector = copy.Spec.NodeSelector
49+
out.Spec.OpenTelemetryCommonFields.Args = copy.Spec.NodeSelector
50+
out.Spec.OpenTelemetryCommonFields.Replicas = copy.Spec.Replicas
51+
52+
if copy.Spec.Autoscaler != nil {
53+
metrics := make([]v1alpha2.MetricSpec, len(copy.Spec.Autoscaler.Metrics))
54+
for i, m := range copy.Spec.Autoscaler.Metrics {
55+
metrics[i] = v1alpha2.MetricSpec{
56+
Type: m.Type,
57+
Pods: m.Pods,
58+
}
59+
}
60+
out.Spec.OpenTelemetryCommonFields.Autoscaler = &v1alpha2.AutoscalerSpec{
61+
MinReplicas: copy.Spec.Autoscaler.MinReplicas,
62+
MaxReplicas: copy.Spec.Autoscaler.MaxReplicas,
63+
Behavior: copy.Spec.Autoscaler.Behavior,
64+
Metrics: metrics,
65+
TargetCPUUtilization: copy.Spec.Autoscaler.TargetCPUUtilization,
66+
TargetMemoryUtilization: copy.Spec.Autoscaler.TargetMemoryUtilization,
67+
}
68+
}
69+
70+
if copy.Spec.PodDisruptionBudget != nil {
71+
out.Spec.OpenTelemetryCommonFields.PodDisruptionBudget = &v1alpha2.PodDisruptionBudgetSpec{
72+
MinAvailable: copy.Spec.PodDisruptionBudget.MinAvailable,
73+
MaxUnavailable: copy.Spec.PodDisruptionBudget.MaxUnavailable,
74+
}
75+
}
76+
if copy.Spec.SecurityContext != nil {
77+
out.Spec.OpenTelemetryCommonFields.SecurityContext = copy.Spec.SecurityContext
78+
}
79+
if copy.Spec.PodSecurityContext != nil {
80+
out.Spec.OpenTelemetryCommonFields.PodSecurityContext = copy.Spec.PodSecurityContext
81+
}
82+
out.Spec.OpenTelemetryCommonFields.PodAnnotations = copy.Spec.PodAnnotations
83+
out.Spec.OpenTelemetryCommonFields.ServiceAccount = copy.Spec.ServiceAccount
84+
out.Spec.OpenTelemetryCommonFields.Image = copy.Spec.Image
85+
out.Spec.OpenTelemetryCommonFields.ImagePullPolicy = copy.Spec.ImagePullPolicy
86+
out.Spec.OpenTelemetryCommonFields.VolumeMounts = copy.Spec.VolumeMounts
87+
out.Spec.OpenTelemetryCommonFields.Ports = copy.Spec.Ports
88+
out.Spec.OpenTelemetryCommonFields.Env = copy.Spec.Env
89+
out.Spec.OpenTelemetryCommonFields.EnvFrom = copy.Spec.EnvFrom
90+
out.Spec.OpenTelemetryCommonFields.VolumeClaimTemplates = copy.Spec.VolumeClaimTemplates
91+
out.Spec.OpenTelemetryCommonFields.Tolerations = copy.Spec.Tolerations
92+
out.Spec.OpenTelemetryCommonFields.Volumes = copy.Spec.Volumes
93+
out.Spec.OpenTelemetryCommonFields.Affinity = copy.Spec.Affinity
94+
out.Spec.OpenTelemetryCommonFields.Lifecycle = copy.Spec.Lifecycle
95+
out.Spec.OpenTelemetryCommonFields.TerminationGracePeriodSeconds = copy.Spec.TerminationGracePeriodSeconds
96+
out.Spec.OpenTelemetryCommonFields.TopologySpreadConstraints = copy.Spec.TopologySpreadConstraints
97+
out.Spec.OpenTelemetryCommonFields.HostNetwork = copy.Spec.HostNetwork
98+
out.Spec.OpenTelemetryCommonFields.PriorityClassName = copy.Spec.PriorityClassName
99+
out.Spec.OpenTelemetryCommonFields.InitContainers = copy.Spec.InitContainers
100+
out.Spec.OpenTelemetryCommonFields.AdditionalContainers = copy.Spec.AdditionalContainers
101+
102+
out.Spec.TargetAllocator.Replicas = copy.Spec.TargetAllocator.Replicas
103+
out.Spec.TargetAllocator.NodeSelector = copy.Spec.TargetAllocator.NodeSelector
104+
out.Spec.TargetAllocator.Resources = copy.Spec.TargetAllocator.Resources
105+
out.Spec.TargetAllocator.AllocationStrategy = copy.Spec.TargetAllocator.AllocationStrategy
106+
out.Spec.TargetAllocator.FilterStrategy = copy.Spec.TargetAllocator.FilterStrategy
107+
out.Spec.TargetAllocator.ServiceAccount = copy.Spec.TargetAllocator.ServiceAccount
108+
out.Spec.TargetAllocator.Image = copy.Spec.TargetAllocator.Image
109+
out.Spec.TargetAllocator.Enabled = copy.Spec.TargetAllocator.Enabled
110+
out.Spec.TargetAllocator.Affinity = copy.Spec.TargetAllocator.Affinity
111+
out.Spec.TargetAllocator.PrometheusCR.Enabled = copy.Spec.TargetAllocator.PrometheusCR.Enabled
112+
out.Spec.TargetAllocator.PrometheusCR.ScrapeInterval = copy.Spec.TargetAllocator.PrometheusCR.ScrapeInterval
113+
out.Spec.TargetAllocator.PrometheusCR.PodMonitorSelector = copy.Spec.TargetAllocator.PrometheusCR.PodMonitorSelector
114+
out.Spec.TargetAllocator.PrometheusCR.ServiceMonitorSelector = copy.Spec.TargetAllocator.PrometheusCR.ServiceMonitorSelector
115+
out.Spec.TargetAllocator.SecurityContext = copy.Spec.TargetAllocator.SecurityContext
116+
out.Spec.TargetAllocator.PodSecurityContext = copy.Spec.TargetAllocator.PodSecurityContext
117+
out.Spec.TargetAllocator.TopologySpreadConstraints = copy.Spec.TargetAllocator.TopologySpreadConstraints
118+
out.Spec.TargetAllocator.Tolerations = copy.Spec.TargetAllocator.Tolerations
119+
out.Spec.TargetAllocator.Env = copy.Spec.TargetAllocator.Env
120+
out.Spec.TargetAllocator.Observability = v1alpha1.ObservabilitySpec{
121+
Metrics: v1alpha1.MetricsConfigSpec{
122+
EnableMetrics: copy.Spec.TargetAllocator.Observability.Metrics.EnableMetrics,
123+
},
124+
}
125+
out.Spec.TargetAllocator.PodDisruptionBudget = copy.Spec.TargetAllocator.PodDisruptionBudget
126+
127+
out.Spec.Mode = v1alpha2.Mode(copy.Spec.Mode)
128+
out.Spec.UpgradeStrategy = v1alpha2.UpgradeStrategy(copy.Spec.UpgradeStrategy)
129+
out.Spec.Ingress.Type = v1alpha2.IngressType(copy.Spec.Ingress.Type)
130+
out.Spec.Ingress.Annotations = copy.Spec.Ingress.Annotations
131+
out.Spec.Ingress.TLS = copy.Spec.Ingress.TLS
132+
out.Spec.Ingress.IngressClassName = copy.Spec.Ingress.IngressClassName
133+
out.Spec.Ingress.Route.Termination = v1alpha2.TLSRouteTerminationType(copy.Spec.Ingress.Route.Termination)
134+
135+
if copy.Spec.LivenessProbe != nil {
136+
out.Spec.LivenessProbe = &v1alpha2.Probe{
137+
InitialDelaySeconds: copy.Spec.LivenessProbe.InitialDelaySeconds,
138+
TimeoutSeconds: copy.Spec.LivenessProbe.TimeoutSeconds,
139+
PeriodSeconds: copy.Spec.LivenessProbe.PeriodSeconds,
140+
SuccessThreshold: copy.Spec.LivenessProbe.SuccessThreshold,
141+
FailureThreshold: copy.Spec.LivenessProbe.FailureThreshold,
142+
TerminationGracePeriodSeconds: copy.Spec.LivenessProbe.TerminationGracePeriodSeconds,
143+
}
144+
}
145+
146+
out.Spec.Observability.Metrics.EnableMetrics = copy.Spec.Observability.Metrics.EnableMetrics
147+
148+
out.Spec.ConfigMaps = copy.Spec.ConfigMaps
149+
out.Spec.DaemonSetUpdateStrategy = appsv1.DaemonSetUpdateStrategy{} // NOTE: N/A in v1alpha1
150+
out.Spec.DeploymentUpdateStrategy.Type = copy.Spec.DeploymentUpdateStrategy.Type
151+
out.Spec.DeploymentUpdateStrategy.RollingUpdate = copy.Spec.DeploymentUpdateStrategy.RollingUpdate
152+
153+
return out
154+
}

‎internal/api/convert/v1alpha_test.go

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package convert
16+
17+
import (
18+
"encoding/json"
19+
"testing"
20+
21+
"github.com/stretchr/testify/assert"
22+
"sigs.k8s.io/yaml"
23+
24+
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
25+
)
26+
27+
func Test_V1Alpha1to2_Config(t *testing.T) {
28+
config := `---
29+
receivers:
30+
otlp:
31+
protocols:
32+
grpc:
33+
processors:
34+
resourcedetection:
35+
detectors: [kubernetes]
36+
exporters:
37+
otlp:
38+
endpoint: "otlp:4317"
39+
service:
40+
pipelines:
41+
traces:
42+
receivers: [otlp]
43+
processors: [resourcedetection]
44+
exporters: [otlp]
45+
`
46+
cfgV1 := v1alpha1.OpenTelemetryCollector{
47+
Spec: v1alpha1.OpenTelemetryCollectorSpec{
48+
Config: config,
49+
},
50+
}
51+
52+
cfgV2 := V1Alpha1to2(cfgV1)
53+
assert.NotNil(t, cfgV2)
54+
55+
jsonCfg, err := json.Marshal(&cfgV2.Spec.Config)
56+
assert.Nil(t, err)
57+
yamlCfg, err := yaml.JSONToYAML(jsonCfg)
58+
assert.Nil(t, err)
59+
assert.YAMLEq(t, config, string(yamlCfg))
60+
}

‎internal/manifests/collector/annotations.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ package collector
1616

1717
import (
1818
"crypto/sha256"
19+
"encoding/json"
1920
"fmt"
2021

21-
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
22+
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha2"
2223
)
2324

2425
// Annotations return the annotations for OpenTelemetryCollector pod.
25-
func Annotations(instance v1alpha1.OpenTelemetryCollector) map[string]string {
26+
func Annotations(instance v1alpha2.OpenTelemetryCollector) map[string]string {
2627
// new map every time, so that we don't touch the instance's annotations
2728
annotations := map[string]string{}
2829

@@ -37,14 +38,15 @@ func Annotations(instance v1alpha1.OpenTelemetryCollector) map[string]string {
3738
annotations[k] = v
3839
}
3940
}
41+
4042
// make sure sha256 for configMap is always calculated
4143
annotations["opentelemetry-operator-config/sha256"] = getConfigMapSHA(instance.Spec.Config)
4244

4345
return annotations
4446
}
4547

4648
// PodAnnotations return the spec annotations for OpenTelemetryCollector pod.
47-
func PodAnnotations(instance v1alpha1.OpenTelemetryCollector) map[string]string {
49+
func PodAnnotations(instance v1alpha2.OpenTelemetryCollector) map[string]string {
4850
// new map every time, so that we don't touch the instance's annotations
4951
podAnnotations := map[string]string{}
5052

@@ -66,7 +68,11 @@ func PodAnnotations(instance v1alpha1.OpenTelemetryCollector) map[string]string
6668
return podAnnotations
6769
}
6870

69-
func getConfigMapSHA(config string) string {
70-
h := sha256.Sum256([]byte(config))
71+
func getConfigMapSHA(config v1alpha2.Config) string {
72+
b, err := json.Marshal(&config)
73+
if err != nil {
74+
return "invalid"
75+
}
76+
h := sha256.Sum256(b)
7177
return fmt.Sprintf("%x", h)
7278
}

‎internal/manifests/collector/annotations_test.go

+30-14
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,25 @@ import (
2020
"github.com/stretchr/testify/assert"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222

23-
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
23+
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha2"
2424
)
2525

2626
func TestDefaultAnnotations(t *testing.T) {
2727
// prepare
28-
otelcol := v1alpha1.OpenTelemetryCollector{
28+
otelcol := v1alpha2.OpenTelemetryCollector{
2929
ObjectMeta: metav1.ObjectMeta{
3030
Name: "my-instance",
3131
Namespace: "my-ns",
3232
},
33-
Spec: v1alpha1.OpenTelemetryCollectorSpec{
34-
Config: "test",
33+
Spec: v1alpha2.OpenTelemetryCollectorSpec{
34+
Config: v1alpha2.Config{
35+
Service: v1alpha2.Service{
36+
Extensions: func() *[]string {
37+
res := []string{"test"}
38+
return &res
39+
}(),
40+
},
41+
},
3542
},
3643
}
3744

@@ -43,17 +50,17 @@ func TestDefaultAnnotations(t *testing.T) {
4350
assert.Equal(t, "true", annotations["prometheus.io/scrape"])
4451
assert.Equal(t, "8888", annotations["prometheus.io/port"])
4552
assert.Equal(t, "/metrics", annotations["prometheus.io/path"])
46-
assert.Equal(t, "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", annotations["opentelemetry-operator-config/sha256"])
53+
assert.Equal(t, "5b3b62aa5e0a3c7250084c2b49190e30b72fc2ad352ffbaa699224e1aa900834", annotations["opentelemetry-operator-config/sha256"])
4754
//verify propagation from metadata.annotations to spec.template.spec.metadata.annotations
4855
assert.Equal(t, "true", podAnnotations["prometheus.io/scrape"])
4956
assert.Equal(t, "8888", podAnnotations["prometheus.io/port"])
5057
assert.Equal(t, "/metrics", podAnnotations["prometheus.io/path"])
51-
assert.Equal(t, "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", podAnnotations["opentelemetry-operator-config/sha256"])
58+
assert.Equal(t, "5b3b62aa5e0a3c7250084c2b49190e30b72fc2ad352ffbaa699224e1aa900834", podAnnotations["opentelemetry-operator-config/sha256"])
5259
}
5360

5461
func TestUserAnnotations(t *testing.T) {
5562
// prepare
56-
otelcol := v1alpha1.OpenTelemetryCollector{
63+
otelcol := v1alpha2.OpenTelemetryCollector{
5764
ObjectMeta: metav1.ObjectMeta{
5865
Name: "my-instance",
5966
Namespace: "my-ns",
@@ -63,8 +70,15 @@ func TestUserAnnotations(t *testing.T) {
6370
"opentelemetry-operator-config/sha256": "shouldBeOverwritten",
6471
},
6572
},
66-
Spec: v1alpha1.OpenTelemetryCollectorSpec{
67-
Config: "test",
73+
Spec: v1alpha2.OpenTelemetryCollectorSpec{
74+
Config: v1alpha2.Config{
75+
Service: v1alpha2.Service{
76+
Extensions: func() *[]string {
77+
res := []string{"test2"}
78+
return &res
79+
}(),
80+
},
81+
},
6882
},
6983
}
7084

@@ -76,18 +90,20 @@ func TestUserAnnotations(t *testing.T) {
7690
assert.Equal(t, "false", annotations["prometheus.io/scrape"])
7791
assert.Equal(t, "1234", annotations["prometheus.io/port"])
7892
assert.Equal(t, "/test", annotations["prometheus.io/path"])
79-
assert.Equal(t, "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", annotations["opentelemetry-operator-config/sha256"])
80-
assert.Equal(t, "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08", podAnnotations["opentelemetry-operator-config/sha256"])
93+
assert.Equal(t, "29cb15a4b87f8c6284e7c3377f6b6c5c74519f5aee8ca39a90b3cf3ca2043c4d", annotations["opentelemetry-operator-config/sha256"])
94+
assert.Equal(t, "29cb15a4b87f8c6284e7c3377f6b6c5c74519f5aee8ca39a90b3cf3ca2043c4d", podAnnotations["opentelemetry-operator-config/sha256"])
8195
}
8296

8397
func TestAnnotationsPropagateDown(t *testing.T) {
8498
// prepare
85-
otelcol := v1alpha1.OpenTelemetryCollector{
99+
otelcol := v1alpha2.OpenTelemetryCollector{
86100
ObjectMeta: metav1.ObjectMeta{
87101
Annotations: map[string]string{"myapp": "mycomponent"},
88102
},
89-
Spec: v1alpha1.OpenTelemetryCollectorSpec{
90-
PodAnnotations: map[string]string{"pod_annotation": "pod_annotation_value"},
103+
Spec: v1alpha2.OpenTelemetryCollectorSpec{
104+
OpenTelemetryCommonFields: v1alpha2.OpenTelemetryCommonFields{
105+
PodAnnotations: map[string]string{"pod_annotation": "pod_annotation_value"},
106+
},
91107
},
92108
}
93109

‎internal/manifests/collector/container.go

+19-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package collector
1616

1717
import (
18+
"encoding/json"
1819
"errors"
1920
"fmt"
2021
"path"
@@ -24,8 +25,9 @@ import (
2425
"github.com/operator-framework/operator-lib/proxy"
2526
corev1 "k8s.io/api/core/v1"
2627
"k8s.io/apimachinery/pkg/util/validation"
28+
"sigs.k8s.io/yaml"
2729

28-
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
30+
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha2"
2931
"github.com/open-telemetry/opentelemetry-operator/internal/config"
3032
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/adapters"
3133
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
@@ -36,14 +38,26 @@ import (
3638
const maxPortLen = 15
3739

3840
// Container builds a container for the given collector.
39-
func Container(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelemetryCollector, addConfig bool) corev1.Container {
41+
func Container(cfg config.Config, logger logr.Logger, otelcol v1alpha2.OpenTelemetryCollector, addConfig bool) corev1.Container {
4042
image := otelcol.Spec.Image
4143
if len(image) == 0 {
4244
image = cfg.CollectorImage()
4345
}
4446

47+
configJson, err := json.Marshal(&otelcol.Spec.Config)
48+
if err != nil {
49+
logger.Error(err, "could not marshal config to json")
50+
return corev1.Container{}
51+
}
52+
53+
configYaml, err := yaml.JSONToYAML(configJson)
54+
if err != nil {
55+
logger.Error(err, "could not convert json to yaml")
56+
return corev1.Container{}
57+
}
58+
4559
// build container ports from service ports
46-
ports, err := getConfigContainerPorts(logger, otelcol.Spec.Config)
60+
ports, err := getConfigContainerPorts(logger, string(configYaml))
4761
if err != nil {
4862
logger.Error(err, "container ports config")
4963
}
@@ -133,7 +147,7 @@ func Container(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelem
133147
}
134148

135149
var livenessProbe *corev1.Probe
136-
if configFromString, err := adapters.ConfigFromString(otelcol.Spec.Config); err == nil {
150+
if configFromString, err := adapters.ConfigFromString(string(configYaml)); err == nil {
137151
if probe, err := getLivenessProbe(configFromString, otelcol.Spec.LivenessProbe); err == nil {
138152
livenessProbe = probe
139153
} else if errors.Is(err, adapters.ErrNoServiceExtensions) {
@@ -220,7 +234,7 @@ func portMapToList(portMap map[string]corev1.ContainerPort) []corev1.ContainerPo
220234
return ports
221235
}
222236

223-
func getLivenessProbe(config map[interface{}]interface{}, probeConfig *v1alpha1.Probe) (*corev1.Probe, error) {
237+
func getLivenessProbe(config map[interface{}]interface{}, probeConfig *v1alpha2.Probe) (*corev1.Probe, error) {
224238
probe, err := adapters.ConfigToContainerProbe(config)
225239
if err != nil {
226240
return nil, err

‎internal/manifests/collector/container_test.go

+164-128
Large diffs are not rendered by default.

‎internal/manifests/collector/daemonset.go

+20-18
Original file line numberDiff line numberDiff line change
@@ -19,46 +19,48 @@ import (
1919
corev1 "k8s.io/api/core/v1"
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121

22+
"github.com/open-telemetry/opentelemetry-operator/internal/api/convert"
2223
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2324
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
2425
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
2526
)
2627

2728
// DaemonSet builds the deployment for the given instance.
2829
func DaemonSet(params manifests.Params) *appsv1.DaemonSet {
29-
name := naming.Collector(params.OtelCol.Name)
30-
labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter())
30+
otelCol := convert.V1Alpha1to2(params.OtelCol)
31+
name := naming.Collector(otelCol.Name)
32+
labels := manifestutils.Labels(otelCol.ObjectMeta, name, otelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter())
3133

32-
annotations := Annotations(params.OtelCol)
33-
podAnnotations := PodAnnotations(params.OtelCol)
34+
annotations := Annotations(otelCol)
35+
podAnnotations := PodAnnotations(otelCol)
3436
return &appsv1.DaemonSet{
3537
ObjectMeta: metav1.ObjectMeta{
36-
Name: naming.Collector(params.OtelCol.Name),
37-
Namespace: params.OtelCol.Namespace,
38+
Name: naming.Collector(otelCol.Name),
39+
Namespace: otelCol.Namespace,
3840
Labels: labels,
3941
Annotations: annotations,
4042
},
4143
Spec: appsv1.DaemonSetSpec{
4244
Selector: &metav1.LabelSelector{
43-
MatchLabels: manifestutils.SelectorLabels(params.OtelCol.ObjectMeta, ComponentOpenTelemetryCollector),
45+
MatchLabels: manifestutils.SelectorLabels(otelCol.ObjectMeta, ComponentOpenTelemetryCollector),
4446
},
4547
Template: corev1.PodTemplateSpec{
4648
ObjectMeta: metav1.ObjectMeta{
4749
Labels: labels,
4850
Annotations: podAnnotations,
4951
},
5052
Spec: corev1.PodSpec{
51-
ServiceAccountName: ServiceAccountName(params.OtelCol),
52-
InitContainers: params.OtelCol.Spec.InitContainers,
53-
Containers: append(params.OtelCol.Spec.AdditionalContainers, Container(params.Config, params.Log, params.OtelCol, true)),
54-
Volumes: Volumes(params.Config, params.OtelCol),
55-
Tolerations: params.OtelCol.Spec.Tolerations,
56-
NodeSelector: params.OtelCol.Spec.NodeSelector,
57-
HostNetwork: params.OtelCol.Spec.HostNetwork,
58-
DNSPolicy: getDNSPolicy(params.OtelCol),
59-
SecurityContext: params.OtelCol.Spec.PodSecurityContext,
60-
PriorityClassName: params.OtelCol.Spec.PriorityClassName,
61-
Affinity: params.OtelCol.Spec.Affinity,
53+
ServiceAccountName: ServiceAccountName(otelCol),
54+
InitContainers: otelCol.Spec.InitContainers,
55+
Containers: append(otelCol.Spec.AdditionalContainers, Container(params.Config, params.Log, otelCol, true)),
56+
Volumes: Volumes(params.Config, otelCol),
57+
Tolerations: otelCol.Spec.Tolerations,
58+
NodeSelector: otelCol.Spec.NodeSelector,
59+
HostNetwork: otelCol.Spec.HostNetwork,
60+
DNSPolicy: getDNSPolicy(otelCol),
61+
SecurityContext: otelCol.Spec.PodSecurityContext,
62+
PriorityClassName: otelCol.Spec.PriorityClassName,
63+
Affinity: otelCol.Spec.Affinity,
6264
},
6365
},
6466
UpdateStrategy: params.OtelCol.Spec.UpdateStrategy,

‎internal/manifests/collector/daemonset_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestDaemonSetNewDefault(t *testing.T) {
6060

6161
// verify sha256 podAnnotation
6262
expectedAnnotations := map[string]string{
63-
"opentelemetry-operator-config/sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
63+
"opentelemetry-operator-config/sha256": "fbcdae6a02b2115cd5ca4f34298202ab041d1dfe62edebfaadb48b1ee178231d",
6464
"prometheus.io/path": "/metrics",
6565
"prometheus.io/port": "8888",
6666
"prometheus.io/scrape": "true",
@@ -150,11 +150,11 @@ func TestDaemonsetPodAnnotations(t *testing.T) {
150150
ds := DaemonSet(params)
151151

152152
// Add sha256 podAnnotation
153-
testPodAnnotationValues["opentelemetry-operator-config/sha256"] = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
153+
testPodAnnotationValues["opentelemetry-operator-config/sha256"] = "fbcdae6a02b2115cd5ca4f34298202ab041d1dfe62edebfaadb48b1ee178231d"
154154

155155
expectedAnnotations := map[string]string{
156156
"annotation-key": "annotation-value",
157-
"opentelemetry-operator-config/sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
157+
"opentelemetry-operator-config/sha256": "fbcdae6a02b2115cd5ca4f34298202ab041d1dfe62edebfaadb48b1ee178231d",
158158
"prometheus.io/path": "/metrics",
159159
"prometheus.io/port": "8888",
160160
"prometheus.io/scrape": "true",

‎internal/manifests/collector/deployment.go

+23-21
Original file line numberDiff line numberDiff line change
@@ -19,51 +19,53 @@ import (
1919
corev1 "k8s.io/api/core/v1"
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121

22+
"github.com/open-telemetry/opentelemetry-operator/internal/api/convert"
2223
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2324
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
2425
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
2526
)
2627

2728
// Deployment builds the deployment for the given instance.
2829
func Deployment(params manifests.Params) *appsv1.Deployment {
29-
name := naming.Collector(params.OtelCol.Name)
30-
labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter())
30+
otelCol := convert.V1Alpha1to2(params.OtelCol)
31+
name := naming.Collector(otelCol.Name)
32+
labels := manifestutils.Labels(otelCol.ObjectMeta, name, otelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter())
3133

32-
annotations := Annotations(params.OtelCol)
33-
podAnnotations := PodAnnotations(params.OtelCol)
34+
annotations := Annotations(otelCol)
35+
podAnnotations := PodAnnotations(otelCol)
3436

3537
return &appsv1.Deployment{
3638
ObjectMeta: metav1.ObjectMeta{
3739
Name: name,
38-
Namespace: params.OtelCol.Namespace,
40+
Namespace: otelCol.Namespace,
3941
Labels: labels,
4042
Annotations: annotations,
4143
},
4244
Spec: appsv1.DeploymentSpec{
43-
Replicas: params.OtelCol.Spec.Replicas,
45+
Replicas: otelCol.Spec.Replicas,
4446
Selector: &metav1.LabelSelector{
45-
MatchLabels: manifestutils.SelectorLabels(params.OtelCol.ObjectMeta, ComponentOpenTelemetryCollector),
47+
MatchLabels: manifestutils.SelectorLabels(otelCol.ObjectMeta, ComponentOpenTelemetryCollector),
4648
},
47-
Strategy: params.OtelCol.Spec.DeploymentUpdateStrategy,
49+
Strategy: otelCol.Spec.DeploymentUpdateStrategy,
4850
Template: corev1.PodTemplateSpec{
4951
ObjectMeta: metav1.ObjectMeta{
5052
Labels: labels,
5153
Annotations: podAnnotations,
5254
},
5355
Spec: corev1.PodSpec{
54-
ServiceAccountName: ServiceAccountName(params.OtelCol),
55-
InitContainers: params.OtelCol.Spec.InitContainers,
56-
Containers: append(params.OtelCol.Spec.AdditionalContainers, Container(params.Config, params.Log, params.OtelCol, true)),
57-
Volumes: Volumes(params.Config, params.OtelCol),
58-
DNSPolicy: getDNSPolicy(params.OtelCol),
59-
HostNetwork: params.OtelCol.Spec.HostNetwork,
60-
Tolerations: params.OtelCol.Spec.Tolerations,
61-
NodeSelector: params.OtelCol.Spec.NodeSelector,
62-
SecurityContext: params.OtelCol.Spec.PodSecurityContext,
63-
PriorityClassName: params.OtelCol.Spec.PriorityClassName,
64-
Affinity: params.OtelCol.Spec.Affinity,
65-
TerminationGracePeriodSeconds: params.OtelCol.Spec.TerminationGracePeriodSeconds,
66-
TopologySpreadConstraints: params.OtelCol.Spec.TopologySpreadConstraints,
56+
ServiceAccountName: ServiceAccountName(otelCol),
57+
InitContainers: otelCol.Spec.InitContainers,
58+
Containers: append(otelCol.Spec.AdditionalContainers, Container(params.Config, params.Log, otelCol, true)),
59+
Volumes: Volumes(params.Config, otelCol),
60+
DNSPolicy: getDNSPolicy(otelCol),
61+
HostNetwork: otelCol.Spec.HostNetwork,
62+
Tolerations: otelCol.Spec.Tolerations,
63+
NodeSelector: otelCol.Spec.NodeSelector,
64+
SecurityContext: otelCol.Spec.PodSecurityContext,
65+
PriorityClassName: otelCol.Spec.PriorityClassName,
66+
Affinity: otelCol.Spec.Affinity,
67+
TerminationGracePeriodSeconds: otelCol.Spec.TerminationGracePeriodSeconds,
68+
TopologySpreadConstraints: otelCol.Spec.TopologySpreadConstraints,
6769
},
6870
},
6971
},

‎internal/manifests/collector/deployment_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestDeploymentNewDefault(t *testing.T) {
102102

103103
// verify sha256 podAnnotation
104104
expectedAnnotations := map[string]string{
105-
"opentelemetry-operator-config/sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
105+
"opentelemetry-operator-config/sha256": "fbcdae6a02b2115cd5ca4f34298202ab041d1dfe62edebfaadb48b1ee178231d",
106106
"prometheus.io/path": "/metrics",
107107
"prometheus.io/port": "8888",
108108
"prometheus.io/scrape": "true",
@@ -156,11 +156,11 @@ func TestDeploymentPodAnnotations(t *testing.T) {
156156
d := Deployment(params)
157157

158158
// Add sha256 podAnnotation
159-
testPodAnnotationValues["opentelemetry-operator-config/sha256"] = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
159+
testPodAnnotationValues["opentelemetry-operator-config/sha256"] = "fbcdae6a02b2115cd5ca4f34298202ab041d1dfe62edebfaadb48b1ee178231d"
160160

161161
expectedPodAnnotationValues := map[string]string{
162162
"annotation-key": "annotation-value",
163-
"opentelemetry-operator-config/sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
163+
"opentelemetry-operator-config/sha256": "fbcdae6a02b2115cd5ca4f34298202ab041d1dfe62edebfaadb48b1ee178231d",
164164
"prometheus.io/path": "/metrics",
165165
"prometheus.io/port": "8888",
166166
"prometheus.io/scrape": "true",

‎internal/manifests/collector/horizontalpodautoscaler.go

+29-22
Original file line numberDiff line numberDiff line change
@@ -21,66 +21,68 @@ import (
2121
"sigs.k8s.io/controller-runtime/pkg/client"
2222

2323
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
24+
"github.com/open-telemetry/opentelemetry-operator/internal/api/convert"
2425
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2526
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
2627
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
2728
)
2829

2930
func HorizontalPodAutoscaler(params manifests.Params) client.Object {
30-
name := naming.Collector(params.OtelCol.Name)
31-
labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter())
32-
annotations := Annotations(params.OtelCol)
31+
otelCol := convert.V1Alpha1to2(params.OtelCol)
32+
name := naming.Collector(otelCol.Name)
33+
labels := manifestutils.Labels(otelCol.ObjectMeta, name, otelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter())
34+
annotations := Annotations(otelCol)
3335
var result client.Object
3436

3537
objectMeta := metav1.ObjectMeta{
36-
Name: naming.HorizontalPodAutoscaler(params.OtelCol.Name),
37-
Namespace: params.OtelCol.Namespace,
38+
Name: naming.HorizontalPodAutoscaler(otelCol.Name),
39+
Namespace: otelCol.Namespace,
3840
Labels: labels,
3941
Annotations: annotations,
4042
}
4143

4244
// defaulting webhook should always set this, but if unset then return nil.
43-
if params.OtelCol.Spec.Autoscaler == nil {
45+
if otelCol.Spec.Autoscaler == nil {
4446
params.Log.Info("hpa field is unset in Spec, skipping autoscaler creation")
4547
return nil
4648
}
4749

48-
if params.OtelCol.Spec.Autoscaler.MaxReplicas == nil {
49-
params.OtelCol.Spec.Autoscaler.MaxReplicas = params.OtelCol.Spec.MaxReplicas
50+
if otelCol.Spec.OpenTelemetryCommonFields.Autoscaler.MaxReplicas == nil {
51+
otelCol.Spec.OpenTelemetryCommonFields.Autoscaler.MaxReplicas = params.OtelCol.Spec.MaxReplicas
5052
}
5153

52-
if params.OtelCol.Spec.Autoscaler.MinReplicas == nil {
54+
if otelCol.Spec.OpenTelemetryCommonFields.Autoscaler.MinReplicas == nil {
5355
if params.OtelCol.Spec.MinReplicas != nil {
54-
params.OtelCol.Spec.Autoscaler.MinReplicas = params.OtelCol.Spec.MinReplicas
56+
otelCol.Spec.OpenTelemetryCommonFields.Autoscaler.MinReplicas = params.OtelCol.Spec.MinReplicas
5557
} else {
56-
params.OtelCol.Spec.Autoscaler.MinReplicas = params.OtelCol.Spec.Replicas
58+
otelCol.Spec.OpenTelemetryCommonFields.Autoscaler.MinReplicas = params.OtelCol.Spec.Replicas
5759
}
5860
}
5961

6062
metrics := []autoscalingv2.MetricSpec{}
6163

62-
if params.OtelCol.Spec.Autoscaler.TargetMemoryUtilization != nil {
64+
if otelCol.Spec.Autoscaler.TargetMemoryUtilization != nil {
6365
memoryTarget := autoscalingv2.MetricSpec{
6466
Type: autoscalingv2.ResourceMetricSourceType,
6567
Resource: &autoscalingv2.ResourceMetricSource{
6668
Name: corev1.ResourceMemory,
6769
Target: autoscalingv2.MetricTarget{
6870
Type: autoscalingv2.UtilizationMetricType,
69-
AverageUtilization: params.OtelCol.Spec.Autoscaler.TargetMemoryUtilization,
71+
AverageUtilization: otelCol.Spec.Autoscaler.TargetMemoryUtilization,
7072
},
7173
},
7274
}
7375
metrics = append(metrics, memoryTarget)
7476
}
7577

76-
if params.OtelCol.Spec.Autoscaler.TargetCPUUtilization != nil {
78+
if otelCol.Spec.Autoscaler.TargetCPUUtilization != nil {
7779
cpuTarget := autoscalingv2.MetricSpec{
7880
Type: autoscalingv2.ResourceMetricSourceType,
7981
Resource: &autoscalingv2.ResourceMetricSource{
8082
Name: corev1.ResourceCPU,
8183
Target: autoscalingv2.MetricTarget{
8284
Type: autoscalingv2.UtilizationMetricType,
83-
AverageUtilization: params.OtelCol.Spec.Autoscaler.TargetCPUUtilization,
85+
AverageUtilization: otelCol.Spec.Autoscaler.TargetCPUUtilization,
8486
},
8587
},
8688
}
@@ -93,19 +95,24 @@ func HorizontalPodAutoscaler(params manifests.Params) client.Object {
9395
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
9496
APIVersion: v1alpha1.GroupVersion.String(),
9597
Kind: "OpenTelemetryCollector",
96-
Name: naming.OpenTelemetryCollector(params.OtelCol.Name),
98+
Name: naming.OpenTelemetryCollector(otelCol.Name),
9799
},
98-
MinReplicas: params.OtelCol.Spec.Autoscaler.MinReplicas,
99-
MaxReplicas: *params.OtelCol.Spec.Autoscaler.MaxReplicas,
100-
Metrics: metrics,
100+
MinReplicas: otelCol.Spec.OpenTelemetryCommonFields.Autoscaler.MinReplicas,
101+
MaxReplicas: func(max *int32) int32 {
102+
if max == nil {
103+
return 0
104+
}
105+
return *max
106+
}(otelCol.Spec.OpenTelemetryCommonFields.Autoscaler.MaxReplicas),
107+
Metrics: metrics,
101108
},
102109
}
103-
if params.OtelCol.Spec.Autoscaler.Behavior != nil {
104-
autoscaler.Spec.Behavior = params.OtelCol.Spec.Autoscaler.Behavior
110+
if otelCol.Spec.Autoscaler.Behavior != nil {
111+
autoscaler.Spec.Behavior = otelCol.Spec.Autoscaler.Behavior
105112
}
106113

107114
// convert from v1alpha1.MetricSpec into a autoscalingv2.MetricSpec.
108-
for _, metric := range params.OtelCol.Spec.Autoscaler.Metrics {
115+
for _, metric := range otelCol.Spec.Autoscaler.Metrics {
109116
if metric.Type == autoscalingv2.PodsMetricSourceType {
110117
v2metric := autoscalingv2.MetricSpec{
111118
Type: metric.Type,

‎internal/manifests/collector/horizontalpodautoscaler_test.go

+34-18
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424

2525
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
26+
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha2"
2627
"github.com/open-telemetry/opentelemetry-operator/internal/config"
2728
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2829
. "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector"
@@ -40,30 +41,34 @@ func TestHPA(t *testing.T) {
4041
var cpuUtilization int32 = 66
4142
var memoryUtilization int32 = 77
4243

43-
otelcols := []v1alpha1.OpenTelemetryCollector{
44+
otelcols := []v1alpha2.OpenTelemetryCollector{
4445
{
4546
ObjectMeta: metav1.ObjectMeta{
4647
Name: "my-instance",
4748
},
48-
Spec: v1alpha1.OpenTelemetryCollectorSpec{
49-
Autoscaler: &v1alpha1.AutoscalerSpec{
50-
MinReplicas: &minReplicas,
51-
MaxReplicas: &maxReplicas,
52-
TargetCPUUtilization: &cpuUtilization,
53-
TargetMemoryUtilization: &memoryUtilization,
49+
Spec: v1alpha2.OpenTelemetryCollectorSpec{
50+
OpenTelemetryCommonFields: v1alpha2.OpenTelemetryCommonFields{
51+
Autoscaler: &v1alpha2.AutoscalerSpec{
52+
MinReplicas: &minReplicas,
53+
MaxReplicas: &maxReplicas,
54+
TargetCPUUtilization: &cpuUtilization,
55+
TargetMemoryUtilization: &memoryUtilization,
56+
},
5457
},
5558
},
5659
},
5760
{
5861
ObjectMeta: metav1.ObjectMeta{
5962
Name: "my-instance",
6063
},
61-
Spec: v1alpha1.OpenTelemetryCollectorSpec{
62-
MinReplicas: &minReplicas,
63-
MaxReplicas: &maxReplicas,
64-
Autoscaler: &v1alpha1.AutoscalerSpec{
65-
TargetCPUUtilization: &cpuUtilization,
66-
TargetMemoryUtilization: &memoryUtilization,
64+
Spec: v1alpha2.OpenTelemetryCollectorSpec{
65+
OpenTelemetryCommonFields: v1alpha2.OpenTelemetryCommonFields{
66+
Autoscaler: &v1alpha2.AutoscalerSpec{
67+
MinReplicas: &minReplicas,
68+
MaxReplicas: &maxReplicas,
69+
TargetCPUUtilization: &cpuUtilization,
70+
TargetMemoryUtilization: &memoryUtilization,
71+
},
6772
},
6873
},
6974
},
@@ -74,9 +79,19 @@ func TestHPA(t *testing.T) {
7479
t.Run(test.name, func(t *testing.T) {
7580
configuration := config.New()
7681
params := manifests.Params{
77-
Config: configuration,
78-
OtelCol: otelcol,
79-
Log: logger,
82+
Config: configuration,
83+
OtelCol: v1alpha1.OpenTelemetryCollector{
84+
ObjectMeta: otelcol.ObjectMeta,
85+
Spec: v1alpha1.OpenTelemetryCollectorSpec{
86+
MinReplicas: otelcol.Spec.OpenTelemetryCommonFields.Autoscaler.MinReplicas,
87+
MaxReplicas: otelcol.Spec.OpenTelemetryCommonFields.Autoscaler.MaxReplicas,
88+
Autoscaler: &v1alpha1.AutoscalerSpec{
89+
TargetCPUUtilization: otelcol.Spec.OpenTelemetryCommonFields.Autoscaler.TargetCPUUtilization,
90+
TargetMemoryUtilization: otelcol.Spec.OpenTelemetryCommonFields.Autoscaler.TargetMemoryUtilization,
91+
},
92+
},
93+
},
94+
Log: logger,
8095
}
8196
raw := HorizontalPodAutoscaler(params)
8297

@@ -85,8 +100,9 @@ func TestHPA(t *testing.T) {
85100
// verify
86101
assert.Equal(t, "my-instance-collector", hpa.Name)
87102
assert.Equal(t, "my-instance-collector", hpa.Labels["app.kubernetes.io/name"])
88-
assert.Equal(t, int32(3), *hpa.Spec.MinReplicas)
89-
assert.Equal(t, int32(5), hpa.Spec.MaxReplicas)
103+
// require.NotNil(t, hpa.Spec.MinReplicas)
104+
assert.Equal(t, &minReplicas, hpa.Spec.MinReplicas)
105+
assert.Equal(t, maxReplicas, hpa.Spec.MaxReplicas)
90106
assert.Equal(t, 2, len(hpa.Spec.Metrics))
91107

92108
for _, metric := range hpa.Spec.Metrics {

‎internal/manifests/collector/poddisruptionbudget.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,36 @@ import (
1818
policyV1 "k8s.io/api/policy/v1"
1919
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2020

21+
"github.com/open-telemetry/opentelemetry-operator/internal/api/convert"
2122
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2223
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
2324
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
2425
)
2526

2627
func PodDisruptionBudget(params manifests.Params) *policyV1.PodDisruptionBudget {
28+
otelCol := convert.V1Alpha1to2(params.OtelCol)
2729
// defaulting webhook should always set this, but if unset then return nil.
28-
if params.OtelCol.Spec.PodDisruptionBudget == nil {
30+
if otelCol.Spec.PodDisruptionBudget == nil {
2931
params.Log.Info("pdb field is unset in Spec, skipping podDisruptionBudget creation")
3032
return nil
3133
}
3234

33-
name := naming.Collector(params.OtelCol.Name)
34-
labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter())
35-
annotations := Annotations(params.OtelCol)
35+
name := naming.Collector(otelCol.Name)
36+
labels := manifestutils.Labels(otelCol.ObjectMeta, name, otelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter())
37+
annotations := Annotations(otelCol)
3638

3739
objectMeta := metav1.ObjectMeta{
38-
Name: naming.PodDisruptionBudget(params.OtelCol.Name),
39-
Namespace: params.OtelCol.Namespace,
40+
Name: naming.PodDisruptionBudget(otelCol.Name),
41+
Namespace: otelCol.Namespace,
4042
Labels: labels,
4143
Annotations: annotations,
4244
}
4345

4446
return &policyV1.PodDisruptionBudget{
4547
ObjectMeta: objectMeta,
4648
Spec: policyV1.PodDisruptionBudgetSpec{
47-
MinAvailable: params.OtelCol.Spec.PodDisruptionBudget.MinAvailable,
48-
MaxUnavailable: params.OtelCol.Spec.PodDisruptionBudget.MaxUnavailable,
49+
MinAvailable: otelCol.Spec.PodDisruptionBudget.MinAvailable,
50+
MaxUnavailable: otelCol.Spec.PodDisruptionBudget.MaxUnavailable,
4951
Selector: &metav1.LabelSelector{
5052
MatchLabels: objectMeta.Labels,
5153
},

‎internal/manifests/collector/rbac.go

+31-8
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,31 @@
1515
package collector
1616

1717
import (
18+
"encoding/json"
19+
1820
rbacv1 "k8s.io/api/rbac/v1"
1921
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
"sigs.k8s.io/yaml"
2023

24+
"github.com/open-telemetry/opentelemetry-operator/internal/api/convert"
2125
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2226
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/adapters"
2327
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
2428
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
2529
)
2630

2731
func ClusterRole(params manifests.Params) *rbacv1.ClusterRole {
28-
configFromString, err := adapters.ConfigFromString(params.OtelCol.Spec.Config)
32+
otelCol := convert.V1Alpha1to2(params.OtelCol)
33+
confJson, err := json.Marshal(&otelCol.Spec.Config)
34+
if err != nil {
35+
return nil
36+
}
37+
confStr, err := yaml.JSONToYAML(confJson)
38+
if err != nil {
39+
return nil
40+
}
41+
42+
configFromString, err := adapters.ConfigFromString(string(confStr))
2943
if err != nil {
3044
params.Log.Error(err, "couldn't extract the configuration from the context")
3145
return nil
@@ -50,7 +64,16 @@ func ClusterRole(params manifests.Params) *rbacv1.ClusterRole {
5064
}
5165

5266
func ClusterRoleBinding(params manifests.Params) *rbacv1.ClusterRoleBinding {
53-
configFromString, err := adapters.ConfigFromString(params.OtelCol.Spec.Config)
67+
otelCol := convert.V1Alpha1to2(params.OtelCol)
68+
confJson, err := json.Marshal(&otelCol.Spec.Config)
69+
if err != nil {
70+
return nil
71+
}
72+
confStr, err := yaml.JSONToYAML(confJson)
73+
if err != nil {
74+
return nil
75+
}
76+
configFromString, err := adapters.ConfigFromString(string(confStr))
5477
if err != nil {
5578
params.Log.Error(err, "couldn't extract the configuration from the context")
5679
return nil
@@ -61,25 +84,25 @@ func ClusterRoleBinding(params manifests.Params) *rbacv1.ClusterRoleBinding {
6184
return nil
6285
}
6386

64-
name := naming.ClusterRoleBinding(params.OtelCol.Name)
65-
labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter())
87+
name := naming.ClusterRoleBinding(otelCol.Name)
88+
labels := manifestutils.Labels(otelCol.ObjectMeta, name, otelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter())
6689

6790
return &rbacv1.ClusterRoleBinding{
6891
ObjectMeta: metav1.ObjectMeta{
6992
Name: name,
70-
Annotations: params.OtelCol.Annotations,
93+
Annotations: otelCol.Annotations,
7194
Labels: labels,
7295
},
7396
Subjects: []rbacv1.Subject{
7497
{
7598
Kind: "ServiceAccount",
76-
Name: ServiceAccountName(params.OtelCol),
77-
Namespace: params.OtelCol.Namespace,
99+
Name: ServiceAccountName(otelCol),
100+
Namespace: otelCol.Namespace,
78101
},
79102
},
80103
RoleRef: rbacv1.RoleRef{
81104
Kind: "ClusterRole",
82-
Name: naming.ClusterRole(params.OtelCol.Name, params.OtelCol.Namespace),
105+
Name: naming.ClusterRole(otelCol.Name, otelCol.Namespace),
83106
APIGroup: "rbac.authorization.k8s.io",
84107
},
85108
}

‎internal/manifests/collector/serviceaccount.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ import (
1818
corev1 "k8s.io/api/core/v1"
1919
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2020

21-
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
21+
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha2"
2222
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2323
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
2424
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
2525
)
2626

2727
// ServiceAccountName returns the name of the existing or self-provisioned service account to use for the given instance.
28-
func ServiceAccountName(instance v1alpha1.OpenTelemetryCollector) string {
28+
func ServiceAccountName(instance v1alpha2.OpenTelemetryCollector) string {
2929
if len(instance.Spec.ServiceAccount) == 0 {
3030
return naming.ServiceAccount(instance.Name)
3131
}

‎internal/manifests/collector/serviceaccount_test.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import (
2020
"github.com/stretchr/testify/assert"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222

23-
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
23+
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha2"
2424
. "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector"
2525
)
2626

2727
func TestServiceAccountNewDefault(t *testing.T) {
2828
// prepare
29-
otelcol := v1alpha1.OpenTelemetryCollector{
29+
otelcol := v1alpha2.OpenTelemetryCollector{
3030
ObjectMeta: metav1.ObjectMeta{
3131
Name: "my-instance",
3232
},
@@ -41,12 +41,14 @@ func TestServiceAccountNewDefault(t *testing.T) {
4141

4242
func TestServiceAccountOverride(t *testing.T) {
4343
// prepare
44-
otelcol := v1alpha1.OpenTelemetryCollector{
44+
otelcol := v1alpha2.OpenTelemetryCollector{
4545
ObjectMeta: metav1.ObjectMeta{
4646
Name: "my-instance",
4747
},
48-
Spec: v1alpha1.OpenTelemetryCollectorSpec{
49-
ServiceAccount: "my-special-sa",
48+
Spec: v1alpha2.OpenTelemetryCollectorSpec{
49+
OpenTelemetryCommonFields: v1alpha2.OpenTelemetryCommonFields{
50+
ServiceAccount: "my-special-sa",
51+
},
5052
},
5153
}
5254

‎internal/manifests/collector/statefulset.go

+23-21
Original file line numberDiff line numberDiff line change
@@ -19,54 +19,56 @@ import (
1919
corev1 "k8s.io/api/core/v1"
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121

22+
"github.com/open-telemetry/opentelemetry-operator/internal/api/convert"
2223
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2324
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
2425
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
2526
)
2627

2728
// StatefulSet builds the statefulset for the given instance.
2829
func StatefulSet(params manifests.Params) *appsv1.StatefulSet {
29-
name := naming.Collector(params.OtelCol.Name)
30-
labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter())
30+
otelCol := convert.V1Alpha1to2(params.OtelCol)
31+
name := naming.Collector(otelCol.Name)
32+
labels := manifestutils.Labels(otelCol.ObjectMeta, name, otelCol.Spec.Image, ComponentOpenTelemetryCollector, params.Config.LabelsFilter())
3133

32-
annotations := Annotations(params.OtelCol)
33-
podAnnotations := PodAnnotations(params.OtelCol)
34+
annotations := Annotations(otelCol)
35+
podAnnotations := PodAnnotations(otelCol)
3436

3537
return &appsv1.StatefulSet{
3638
ObjectMeta: metav1.ObjectMeta{
3739
Name: name,
38-
Namespace: params.OtelCol.Namespace,
40+
Namespace: otelCol.Namespace,
3941
Labels: labels,
4042
Annotations: annotations,
4143
},
4244
Spec: appsv1.StatefulSetSpec{
43-
ServiceName: naming.Service(params.OtelCol.Name),
45+
ServiceName: naming.Service(otelCol.Name),
4446
Selector: &metav1.LabelSelector{
45-
MatchLabels: manifestutils.SelectorLabels(params.OtelCol.ObjectMeta, ComponentOpenTelemetryCollector),
47+
MatchLabels: manifestutils.SelectorLabels(otelCol.ObjectMeta, ComponentOpenTelemetryCollector),
4648
},
4749
Template: corev1.PodTemplateSpec{
4850
ObjectMeta: metav1.ObjectMeta{
4951
Labels: labels,
5052
Annotations: podAnnotations,
5153
},
5254
Spec: corev1.PodSpec{
53-
ServiceAccountName: ServiceAccountName(params.OtelCol),
54-
InitContainers: params.OtelCol.Spec.InitContainers,
55-
Containers: append(params.OtelCol.Spec.AdditionalContainers, Container(params.Config, params.Log, params.OtelCol, true)),
56-
Volumes: Volumes(params.Config, params.OtelCol),
57-
DNSPolicy: getDNSPolicy(params.OtelCol),
58-
HostNetwork: params.OtelCol.Spec.HostNetwork,
59-
Tolerations: params.OtelCol.Spec.Tolerations,
60-
NodeSelector: params.OtelCol.Spec.NodeSelector,
61-
SecurityContext: params.OtelCol.Spec.PodSecurityContext,
62-
PriorityClassName: params.OtelCol.Spec.PriorityClassName,
63-
Affinity: params.OtelCol.Spec.Affinity,
64-
TopologySpreadConstraints: params.OtelCol.Spec.TopologySpreadConstraints,
55+
ServiceAccountName: ServiceAccountName(otelCol),
56+
InitContainers: otelCol.Spec.InitContainers,
57+
Containers: append(otelCol.Spec.AdditionalContainers, Container(params.Config, params.Log, otelCol, true)),
58+
Volumes: Volumes(params.Config, otelCol),
59+
DNSPolicy: getDNSPolicy(otelCol),
60+
HostNetwork: otelCol.Spec.HostNetwork,
61+
Tolerations: otelCol.Spec.Tolerations,
62+
NodeSelector: otelCol.Spec.NodeSelector,
63+
SecurityContext: otelCol.Spec.PodSecurityContext,
64+
PriorityClassName: otelCol.Spec.PriorityClassName,
65+
Affinity: otelCol.Spec.Affinity,
66+
TopologySpreadConstraints: otelCol.Spec.TopologySpreadConstraints,
6567
},
6668
},
67-
Replicas: params.OtelCol.Spec.Replicas,
69+
Replicas: otelCol.Spec.Replicas,
6870
PodManagementPolicy: "Parallel",
69-
VolumeClaimTemplates: VolumeClaimTemplates(params.OtelCol),
71+
VolumeClaimTemplates: VolumeClaimTemplates(otelCol),
7072
},
7173
}
7274
}

‎internal/manifests/collector/statefulset_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestStatefulSetNewDefault(t *testing.T) {
6565

6666
// verify sha256 podAnnotation
6767
expectedAnnotations := map[string]string{
68-
"opentelemetry-operator-config/sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
68+
"opentelemetry-operator-config/sha256": "fbcdae6a02b2115cd5ca4f34298202ab041d1dfe62edebfaadb48b1ee178231d",
6969
"prometheus.io/path": "/metrics",
7070
"prometheus.io/port": "8888",
7171
"prometheus.io/scrape": "true",
@@ -194,11 +194,11 @@ func TestStatefulSetPodAnnotations(t *testing.T) {
194194
ss := StatefulSet(params)
195195

196196
// Add sha256 podAnnotation
197-
testPodAnnotationValues["opentelemetry-operator-config/sha256"] = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
197+
testPodAnnotationValues["opentelemetry-operator-config/sha256"] = "fbcdae6a02b2115cd5ca4f34298202ab041d1dfe62edebfaadb48b1ee178231d"
198198

199199
expectedAnnotations := map[string]string{
200200
"annotation-key": "annotation-value",
201-
"opentelemetry-operator-config/sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
201+
"opentelemetry-operator-config/sha256": "fbcdae6a02b2115cd5ca4f34298202ab041d1dfe62edebfaadb48b1ee178231d",
202202
"prometheus.io/path": "/metrics",
203203
"prometheus.io/port": "8888",
204204
"prometheus.io/scrape": "true",

‎internal/manifests/collector/utils.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ package collector
1717
import (
1818
corev1 "k8s.io/api/core/v1"
1919

20-
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
20+
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha2"
2121
)
2222

23-
func getDNSPolicy(otelcol v1alpha1.OpenTelemetryCollector) corev1.DNSPolicy {
23+
func getDNSPolicy(otelcol v1alpha2.OpenTelemetryCollector) corev1.DNSPolicy {
2424
dnsPolicy := corev1.DNSClusterFirst
2525
if otelcol.Spec.HostNetwork {
2626
dnsPolicy = corev1.DNSClusterFirstWithHostNet

‎internal/manifests/collector/volume.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ package collector
1818
import (
1919
corev1 "k8s.io/api/core/v1"
2020

21-
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
21+
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha2"
2222
"github.com/open-telemetry/opentelemetry-operator/internal/config"
2323
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
2424
)
2525

2626
// Volumes builds the volumes for the given instance, including the config map volume.
27-
func Volumes(cfg config.Config, otelcol v1alpha1.OpenTelemetryCollector) []corev1.Volume {
27+
func Volumes(cfg config.Config, otelcol v1alpha2.OpenTelemetryCollector) []corev1.Volume {
2828
volumes := []corev1.Volume{{
2929
Name: naming.ConfigMapVolume(),
3030
VolumeSource: corev1.VolumeSource{

‎internal/manifests/collector/volume_test.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ import (
2121
corev1 "k8s.io/api/core/v1"
2222

2323
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
24+
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha2"
2425
"github.com/open-telemetry/opentelemetry-operator/internal/config"
2526
. "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector"
2627
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
2728
)
2829

2930
func TestVolumeNewDefault(t *testing.T) {
3031
// prepare
31-
otelcol := v1alpha1.OpenTelemetryCollector{}
32+
otelcol := v1alpha2.OpenTelemetryCollector{}
3233
cfg := config.New()
3334

3435
// test
@@ -43,11 +44,13 @@ func TestVolumeNewDefault(t *testing.T) {
4344

4445
func TestVolumeAllowsMoreToBeAdded(t *testing.T) {
4546
// prepare
46-
otelcol := v1alpha1.OpenTelemetryCollector{
47-
Spec: v1alpha1.OpenTelemetryCollectorSpec{
48-
Volumes: []corev1.Volume{{
49-
Name: "my-volume",
50-
}},
47+
otelcol := v1alpha2.OpenTelemetryCollector{
48+
Spec: v1alpha2.OpenTelemetryCollectorSpec{
49+
OpenTelemetryCommonFields: v1alpha2.OpenTelemetryCommonFields{
50+
Volumes: []corev1.Volume{{
51+
Name: "my-volume",
52+
}},
53+
},
5154
},
5255
}
5356
cfg := config.New()
@@ -64,8 +67,8 @@ func TestVolumeAllowsMoreToBeAdded(t *testing.T) {
6467

6568
func TestVolumeWithMoreConfigMaps(t *testing.T) {
6669
// prepare
67-
otelcol := v1alpha1.OpenTelemetryCollector{
68-
Spec: v1alpha1.OpenTelemetryCollectorSpec{
70+
otelcol := v1alpha2.OpenTelemetryCollector{
71+
Spec: v1alpha2.OpenTelemetryCollectorSpec{
6972
ConfigMaps: []v1alpha1.ConfigMapsSpec{{
7073
Name: "configmap-test",
7174
MountPath: "/",

‎internal/manifests/collector/volumeclaim.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ package collector
1818
import (
1919
corev1 "k8s.io/api/core/v1"
2020

21-
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
21+
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha2"
2222
)
2323

2424
// VolumeClaimTemplates builds the volumeClaimTemplates for the given instance,
2525
// including the config map volume mount.
26-
func VolumeClaimTemplates(otelcol v1alpha1.OpenTelemetryCollector) []corev1.PersistentVolumeClaim {
26+
func VolumeClaimTemplates(otelcol v1alpha2.OpenTelemetryCollector) []corev1.PersistentVolumeClaim {
2727
if otelcol.Spec.Mode != "statefulset" {
2828
return []corev1.PersistentVolumeClaim{}
2929
}

‎internal/manifests/collector/volumeclaim_test.go

+29-25
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,28 @@ import (
2222
"k8s.io/apimachinery/pkg/api/resource"
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424

25-
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
25+
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha2"
2626
. "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector"
2727
)
2828

2929
func TestVolumeClaimAllowsUserToAdd(t *testing.T) {
3030
// prepare
31-
otelcol := v1alpha1.OpenTelemetryCollector{
32-
Spec: v1alpha1.OpenTelemetryCollectorSpec{
31+
otelcol := v1alpha2.OpenTelemetryCollector{
32+
Spec: v1alpha2.OpenTelemetryCollectorSpec{
3333
Mode: "statefulset",
34-
VolumeClaimTemplates: []corev1.PersistentVolumeClaim{{
35-
ObjectMeta: metav1.ObjectMeta{
36-
Name: "added-volume",
37-
},
38-
Spec: corev1.PersistentVolumeClaimSpec{
39-
AccessModes: []corev1.PersistentVolumeAccessMode{"ReadWriteOnce"},
40-
Resources: corev1.VolumeResourceRequirements{
41-
Requests: corev1.ResourceList{"storage": resource.MustParse("1Gi")},
34+
OpenTelemetryCommonFields: v1alpha2.OpenTelemetryCommonFields{
35+
VolumeClaimTemplates: []corev1.PersistentVolumeClaim{{
36+
ObjectMeta: metav1.ObjectMeta{
37+
Name: "added-volume",
4238
},
43-
},
44-
}},
39+
Spec: corev1.PersistentVolumeClaimSpec{
40+
AccessModes: []corev1.PersistentVolumeAccessMode{"ReadWriteOnce"},
41+
Resources: corev1.VolumeResourceRequirements{
42+
Requests: corev1.ResourceList{"storage": resource.MustParse("1Gi")},
43+
},
44+
},
45+
}},
46+
},
4547
},
4648
}
4749

@@ -63,20 +65,22 @@ func TestVolumeClaimAllowsUserToAdd(t *testing.T) {
6365

6466
func TestVolumeClaimChecksForStatefulset(t *testing.T) {
6567
// prepare
66-
otelcol := v1alpha1.OpenTelemetryCollector{
67-
Spec: v1alpha1.OpenTelemetryCollectorSpec{
68+
otelcol := v1alpha2.OpenTelemetryCollector{
69+
Spec: v1alpha2.OpenTelemetryCollectorSpec{
6870
Mode: "daemonset",
69-
VolumeClaimTemplates: []corev1.PersistentVolumeClaim{{
70-
ObjectMeta: metav1.ObjectMeta{
71-
Name: "added-volume",
72-
},
73-
Spec: corev1.PersistentVolumeClaimSpec{
74-
AccessModes: []corev1.PersistentVolumeAccessMode{"ReadWriteOnce"},
75-
Resources: corev1.VolumeResourceRequirements{
76-
Requests: corev1.ResourceList{"storage": resource.MustParse("1Gi")},
71+
OpenTelemetryCommonFields: v1alpha2.OpenTelemetryCommonFields{
72+
VolumeClaimTemplates: []corev1.PersistentVolumeClaim{{
73+
ObjectMeta: metav1.ObjectMeta{
74+
Name: "added-volume",
75+
},
76+
Spec: corev1.PersistentVolumeClaimSpec{
77+
AccessModes: []corev1.PersistentVolumeAccessMode{"ReadWriteOnce"},
78+
Resources: corev1.VolumeResourceRequirements{
79+
Requests: corev1.ResourceList{"storage": resource.MustParse("1Gi")},
80+
},
7781
},
78-
},
79-
}},
82+
}},
83+
},
8084
},
8185
}
8286

‎pkg/sidecar/pod.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
corev1 "k8s.io/api/core/v1"
2323

2424
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
25+
"github.com/open-telemetry/opentelemetry-operator/internal/api/convert"
2526
"github.com/open-telemetry/opentelemetry-operator/internal/config"
2627
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector"
2728
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
@@ -39,7 +40,7 @@ func add(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelemetryCo
3940
return pod, err
4041
}
4142

42-
container := collector.Container(cfg, logger, otelcol, false)
43+
container := collector.Container(cfg, logger, convert.V1Alpha1to2(otelcol), false)
4344
container.Args = append(container.Args, fmt.Sprintf("--config=env:%s", confEnvVar))
4445

4546
container.Env = append(container.Env, corev1.EnvVar{Name: confEnvVar, Value: otelColCfg})

0 commit comments

Comments
 (0)
Please sign in to comment.