Skip to content

Commit 2a70ce7

Browse files
authoredJun 19, 2024··
Add a separate Params struct for Target Allocator (#3043)
* Make the builder types more generic * Add a separate Params struct for Target Allocator
1 parent b98d5a4 commit 2a70ce7

18 files changed

+107
-75
lines changed
 

‎controllers/common.go

+34-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ func isNamespaceScoped(obj client.Object) bool {
4848

4949
// BuildCollector returns the generation and collected errors of all manifests for a given instance.
5050
func BuildCollector(params manifests.Params) ([]client.Object, error) {
51-
builders := []manifests.Builder{
51+
builders := []manifests.Builder[manifests.Params]{
5252
collector.Build,
53-
targetallocator.Build,
5453
}
5554
var resources []client.Object
5655
for _, builder := range builders {
@@ -60,12 +59,28 @@ func BuildCollector(params manifests.Params) ([]client.Object, error) {
6059
}
6160
resources = append(resources, objs...)
6261
}
62+
if params.OtelCol.Spec.TargetAllocator.Enabled {
63+
taParams := targetallocator.Params{
64+
Client: params.Client,
65+
Scheme: params.Scheme,
66+
Recorder: params.Recorder,
67+
Log: params.Log,
68+
Config: params.Config,
69+
Collector: params.OtelCol,
70+
TargetAllocator: params.TargetAllocator,
71+
}
72+
taResources, err := BuildTargetAllocator(taParams)
73+
if err != nil {
74+
return nil, err
75+
}
76+
resources = append(resources, taResources...)
77+
}
6378
return resources, nil
6479
}
6580

6681
// BuildOpAMPBridge returns the generation and collected errors of all manifests for a given instance.
6782
func BuildOpAMPBridge(params manifests.Params) ([]client.Object, error) {
68-
builders := []manifests.Builder{
83+
builders := []manifests.Builder[manifests.Params]{
6984
opampbridge.Build,
7085
}
7186
var resources []client.Object
@@ -79,6 +94,22 @@ func BuildOpAMPBridge(params manifests.Params) ([]client.Object, error) {
7994
return resources, nil
8095
}
8196

97+
// BuildTargetAllocator returns the generation and collected errors of all manifests for a given instance.
98+
func BuildTargetAllocator(params targetallocator.Params) ([]client.Object, error) {
99+
builders := []manifests.Builder[targetallocator.Params]{
100+
targetallocator.Build,
101+
}
102+
var resources []client.Object
103+
for _, builder := range builders {
104+
objs, err := builder(params)
105+
if err != nil {
106+
return nil, err
107+
}
108+
resources = append(resources, objs...)
109+
}
110+
return resources, nil
111+
}
112+
82113
// getList queries the Kubernetes API to list the requested resource, setting the list l of type T.
83114
func getList[T client.Object](ctx context.Context, cl client.Client, l T, options ...client.ListOption) (map[types.UID]client.Object, error) {
84115
ownedObjects := map[types.UID]client.Object{}

‎internal/manifests/builder.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ import (
2020
"sigs.k8s.io/controller-runtime/pkg/client"
2121
)
2222

23-
type Builder func(params Params) ([]client.Object, error)
23+
type Builder[Params any] func(params Params) ([]client.Object, error)
2424

25-
type ManifestFactory[T client.Object] func(params Params) (T, error)
26-
type SimpleManifestFactory[T client.Object] func(params Params) T
27-
type K8sManifestFactory ManifestFactory[client.Object]
25+
type ManifestFactory[T client.Object, Params any] func(params Params) (T, error)
26+
type SimpleManifestFactory[T client.Object, Params any] func(params Params) T
27+
type K8sManifestFactory[Params any] ManifestFactory[client.Object, Params]
2828

29-
func FactoryWithoutError[T client.Object](f SimpleManifestFactory[T]) K8sManifestFactory {
29+
func FactoryWithoutError[T client.Object, Params any](f SimpleManifestFactory[T, Params]) K8sManifestFactory[Params] {
3030
return func(params Params) (client.Object, error) {
3131
return f(params), nil
3232
}
3333
}
3434

35-
func Factory[T client.Object](f ManifestFactory[T]) K8sManifestFactory {
35+
func Factory[T client.Object, Params any](f ManifestFactory[T, Params]) K8sManifestFactory[Params] {
3636
return func(params Params) (client.Object, error) {
3737
return f(params)
3838
}

‎internal/manifests/collector/collector.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const (
3030
// Build creates the manifest for the collector resource.
3131
func Build(params manifests.Params) ([]client.Object, error) {
3232
var resourceManifests []client.Object
33-
var manifestFactories []manifests.K8sManifestFactory
33+
var manifestFactories []manifests.K8sManifestFactory[manifests.Params]
3434
switch params.OtelCol.Spec.Mode {
3535
case v1beta1.ModeDeployment:
3636
manifestFactories = append(manifestFactories, manifests.Factory(Deployment))
@@ -43,7 +43,7 @@ func Build(params manifests.Params) ([]client.Object, error) {
4343
case v1beta1.ModeSidecar:
4444
params.Log.V(5).Info("not building sidecar...")
4545
}
46-
manifestFactories = append(manifestFactories, []manifests.K8sManifestFactory{
46+
manifestFactories = append(manifestFactories, []manifests.K8sManifestFactory[manifests.Params]{
4747
manifests.Factory(ConfigMap),
4848
manifests.Factory(HorizontalPodAutoscaler),
4949
manifests.Factory(ServiceAccount),

‎internal/manifests/opampbridge/opampbridge.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const (
2727
// Build creates the manifest for the OpAMPBridge resource.
2828
func Build(params manifests.Params) ([]client.Object, error) {
2929
var resourceManifests []client.Object
30-
resourceFactories := []manifests.K8sManifestFactory{
30+
resourceFactories := []manifests.K8sManifestFactory[manifests.Params]{
3131
manifests.FactoryWithoutError(Deployment),
3232
manifests.Factory(ConfigMap),
3333
manifests.FactoryWithoutError(ServiceAccount),

‎internal/manifests/targetallocator/annotations_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/stretchr/testify/require"
2525

2626
"github.com/open-telemetry/opentelemetry-operator/internal/config"
27-
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2827
)
2928

3029
func TestPodAnnotations(t *testing.T) {
@@ -40,8 +39,8 @@ func TestConfigMapHash(t *testing.T) {
4039
cfg := config.New()
4140
collector := collectorInstance()
4241
targetAllocator := targetAllocatorInstance()
43-
params := manifests.Params{
44-
OtelCol: collector,
42+
params := Params{
43+
Collector: collector,
4544
TargetAllocator: targetAllocator,
4645
Config: cfg,
4746
Log: logr.Discard(),

‎internal/manifests/targetallocator/configmap.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121

2222
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
23-
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2423
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector"
2524
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
2625
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
@@ -30,7 +29,7 @@ const (
3029
targetAllocatorFilename = "targetallocator.yaml"
3130
)
3231

33-
func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) {
32+
func ConfigMap(params Params) (*corev1.ConfigMap, error) {
3433
instance := params.TargetAllocator
3534
name := naming.TAConfigMap(instance.Name)
3635
labels := manifestutils.Labels(instance.ObjectMeta, name, params.TargetAllocator.Spec.Image, ComponentOpenTelemetryTargetAllocator, nil)
@@ -39,7 +38,7 @@ func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) {
3938
taConfig := make(map[interface{}]interface{})
4039

4140
taConfig["collector_selector"] = metav1.LabelSelector{
42-
MatchLabels: manifestutils.SelectorLabels(params.OtelCol.ObjectMeta, collector.ComponentOpenTelemetryCollector),
41+
MatchLabels: manifestutils.SelectorLabels(params.Collector.ObjectMeta, collector.ComponentOpenTelemetryCollector),
4342
}
4443

4544
// Add scrape configs if present

‎internal/manifests/targetallocator/configmap_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525

2626
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
2727
"github.com/open-telemetry/opentelemetry-operator/internal/config"
28-
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2928
)
3029

3130
func TestDesiredConfigMap(t *testing.T) {
@@ -38,8 +37,8 @@ func TestDesiredConfigMap(t *testing.T) {
3837
collector := collectorInstance()
3938
targetAllocator := targetAllocatorInstance()
4039
cfg := config.New()
41-
params := manifests.Params{
42-
OtelCol: collector,
40+
params := Params{
41+
Collector: collector,
4342
TargetAllocator: targetAllocator,
4443
Config: cfg,
4544
Log: logr.Discard(),

‎internal/manifests/targetallocator/deployment.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ 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/manifests"
2322
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
2423
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
2524
)
2625

2726
// Deployment builds the deployment for the given instance.
28-
func Deployment(params manifests.Params) (*appsv1.Deployment, error) {
27+
func Deployment(params Params) (*appsv1.Deployment, error) {
2928
name := naming.TargetAllocator(params.TargetAllocator.Name)
3029
labels := manifestutils.Labels(params.TargetAllocator.ObjectMeta, name, params.TargetAllocator.Spec.Image, ComponentOpenTelemetryTargetAllocator, nil)
3130

‎internal/manifests/targetallocator/deployment_test.go

+26-26
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func TestDeploymentSecurityContext(t *testing.T) {
8989

9090
cfg := config.New()
9191

92-
params1 := manifests.Params{
92+
params1 := Params{
9393
TargetAllocator: targetallocator11,
9494
Config: cfg,
9595
Log: logger,
@@ -114,7 +114,7 @@ func TestDeploymentSecurityContext(t *testing.T) {
114114

115115
cfg = config.New()
116116

117-
params2 := manifests.Params{
117+
params2 := Params{
118118
TargetAllocator: targetAllocator2,
119119
Config: cfg,
120120
Log: logger,
@@ -133,8 +133,8 @@ func TestDeploymentNewDefault(t *testing.T) {
133133
targetAllocator := targetAllocatorInstance()
134134
cfg := config.New()
135135

136-
params := manifests.Params{
137-
OtelCol: otelcol,
136+
params := Params{
137+
Collector: otelcol,
138138
TargetAllocator: targetAllocator,
139139
Config: cfg,
140140
Log: logger,
@@ -167,8 +167,8 @@ func TestDeploymentPodAnnotations(t *testing.T) {
167167
targetAllocator.Spec.PodAnnotations = testPodAnnotationValues
168168
cfg := config.New()
169169

170-
params := manifests.Params{
171-
OtelCol: otelcol,
170+
params := Params{
171+
Collector: otelcol,
172172
TargetAllocator: targetAllocator,
173173
Config: cfg,
174174
Log: logger,
@@ -225,7 +225,7 @@ func TestDeploymentNodeSelector(t *testing.T) {
225225

226226
cfg := config.New()
227227

228-
params1 := manifests.Params{
228+
params1 := Params{
229229
TargetAllocator: targetAllocator1,
230230
Config: cfg,
231231
Log: logger,
@@ -250,7 +250,7 @@ func TestDeploymentNodeSelector(t *testing.T) {
250250

251251
cfg = config.New()
252252

253-
params2 := manifests.Params{
253+
params2 := Params{
254254
TargetAllocator: targetAllocator2,
255255
Config: cfg,
256256
Log: logger,
@@ -267,7 +267,7 @@ func TestDeploymentAffinity(t *testing.T) {
267267

268268
cfg := config.New()
269269

270-
params1 := manifests.Params{
270+
params1 := Params{
271271
TargetAllocator: targetAllocator1,
272272
Config: cfg,
273273
Log: logger,
@@ -290,7 +290,7 @@ func TestDeploymentAffinity(t *testing.T) {
290290

291291
cfg = config.New()
292292

293-
params2 := manifests.Params{
293+
params2 := Params{
294294
TargetAllocator: targetAllocator2,
295295
Config: cfg,
296296
Log: logger,
@@ -310,7 +310,7 @@ func TestDeploymentTolerations(t *testing.T) {
310310
}
311311

312312
cfg := config.New()
313-
params1 := manifests.Params{
313+
params1 := Params{
314314
TargetAllocator: targetAllocator1,
315315
Config: cfg,
316316
Log: logger,
@@ -332,7 +332,7 @@ func TestDeploymentTolerations(t *testing.T) {
332332
},
333333
}
334334

335-
params2 := manifests.Params{
335+
params2 := Params{
336336
TargetAllocator: targetAllocator2,
337337
Config: cfg,
338338
Log: logger,
@@ -355,7 +355,7 @@ func TestDeploymentTopologySpreadConstraints(t *testing.T) {
355355

356356
cfg := config.New()
357357

358-
params1 := manifests.Params{
358+
params1 := Params{
359359
TargetAllocator: targetAllocator1,
360360
Config: cfg,
361361
Log: logger,
@@ -378,7 +378,7 @@ func TestDeploymentTopologySpreadConstraints(t *testing.T) {
378378
}
379379

380380
cfg = config.New()
381-
params2 := manifests.Params{
381+
params2 := Params{
382382
TargetAllocator: targetAllocator2,
383383
Config: cfg,
384384
Log: logger,
@@ -401,8 +401,8 @@ func TestDeploymentSetInitContainer(t *testing.T) {
401401
},
402402
}
403403
otelcol := collectorInstance()
404-
params := manifests.Params{
405-
OtelCol: otelcol,
404+
params := Params{
405+
Collector: otelcol,
406406
TargetAllocator: targetAllocator,
407407
Config: config.New(),
408408
Log: logger,
@@ -423,8 +423,8 @@ func TestDeploymentAdditionalContainers(t *testing.T) {
423423
},
424424
}
425425
otelcol := collectorInstance()
426-
params := manifests.Params{
427-
OtelCol: otelcol,
426+
params := Params{
427+
Collector: otelcol,
428428
TargetAllocator: targetAllocator,
429429
Config: config.New(),
430430
Log: logger,
@@ -441,8 +441,8 @@ func TestDeploymentHostNetwork(t *testing.T) {
441441
// Test default
442442
targetAllocator := targetAllocatorInstance()
443443
otelcol := collectorInstance()
444-
params := manifests.Params{
445-
OtelCol: otelcol,
444+
params := Params{
445+
Collector: otelcol,
446446
TargetAllocator: targetAllocator,
447447
Config: config.New(),
448448
Log: logger,
@@ -467,8 +467,8 @@ func TestDeploymentShareProcessNamespace(t *testing.T) {
467467
// Test default
468468
targetAllocator := targetAllocatorInstance()
469469
otelcol := collectorInstance()
470-
params := manifests.Params{
471-
OtelCol: otelcol,
470+
params := Params{
471+
Collector: otelcol,
472472
TargetAllocator: targetAllocator,
473473
Config: config.New(),
474474
Log: logger,
@@ -490,8 +490,8 @@ func TestDeploymentPriorityClassName(t *testing.T) {
490490
// Test default
491491
targetAllocator := targetAllocatorInstance()
492492
otelcol := collectorInstance()
493-
params := manifests.Params{
494-
OtelCol: otelcol,
493+
params := Params{
494+
Collector: otelcol,
495495
TargetAllocator: targetAllocator,
496496
Config: config.New(),
497497
Log: logger,
@@ -513,8 +513,8 @@ func TestDeploymentTerminationGracePeriodSeconds(t *testing.T) {
513513
// Test default
514514
targetAllocator := targetAllocatorInstance()
515515
otelcol := collectorInstance()
516-
params := manifests.Params{
517-
OtelCol: otelcol,
516+
params := Params{
517+
Collector: otelcol,
518518
TargetAllocator: targetAllocator,
519519
Config: config.New(),
520520
Log: logger,

‎internal/manifests/targetallocator/poddisruptionbudget.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ import (
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222

2323
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
24-
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2524
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
2625
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
2726
)
2827

29-
func PodDisruptionBudget(params manifests.Params) (*policyV1.PodDisruptionBudget, error) {
28+
func PodDisruptionBudget(params Params) (*policyV1.PodDisruptionBudget, error) {
3029
// defaulting webhook should set this if the strategy is compatible, but if unset then return nil.
3130
if params.TargetAllocator.Spec.PodDisruptionBudget == nil {
3231
params.Log.Info("pdb field is unset in Spec, skipping podDisruptionBudget creation")

‎internal/manifests/targetallocator/poddisruptionbudget_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
2626
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
2727
"github.com/open-telemetry/opentelemetry-operator/internal/config"
28-
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2928
)
3029

3130
type test struct {
@@ -84,7 +83,7 @@ func TestPDBWithValidStrategy(t *testing.T) {
8483
},
8584
}
8685
configuration := config.New()
87-
pdb, err := PodDisruptionBudget(manifests.Params{
86+
pdb, err := PodDisruptionBudget(Params{
8887
Log: logger,
8988
Config: configuration,
9089
TargetAllocator: targetAllocator,
@@ -119,7 +118,7 @@ func TestPDBWithNotValidStrategy(t *testing.T) {
119118
},
120119
}
121120
configuration := config.New()
122-
pdb, err := PodDisruptionBudget(manifests.Params{
121+
pdb, err := PodDisruptionBudget(Params{
123122
Log: logger,
124123
Config: configuration,
125124
TargetAllocator: targetAllocator,
@@ -139,7 +138,7 @@ func TestNoPDB(t *testing.T) {
139138
},
140139
}
141140
configuration := config.New()
142-
pdb, err := PodDisruptionBudget(manifests.Params{
141+
pdb, err := PodDisruptionBudget(Params{
143142
Log: logger,
144143
Config: configuration,
145144
TargetAllocator: targetAllocator,

‎internal/manifests/targetallocator/service.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ import (
1919
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2020
"k8s.io/apimachinery/pkg/util/intstr"
2121

22-
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2322
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
2423
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
2524
)
2625

27-
func Service(params manifests.Params) *corev1.Service {
26+
func Service(params Params) *corev1.Service {
2827
name := naming.TAService(params.TargetAllocator.Name)
2928
labels := manifestutils.Labels(params.TargetAllocator.ObjectMeta, name, params.TargetAllocator.Spec.Image, ComponentOpenTelemetryTargetAllocator, nil)
3029
selector := manifestutils.TASelectorLabels(params.TargetAllocator, ComponentOpenTelemetryTargetAllocator)

‎internal/manifests/targetallocator/service_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ import (
2222
"k8s.io/apimachinery/pkg/util/intstr"
2323

2424
"github.com/open-telemetry/opentelemetry-operator/internal/config"
25-
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2625
)
2726

2827
func TestServicePorts(t *testing.T) {
2928
targetAllocator := targetAllocatorInstance()
3029
cfg := config.New()
3130

32-
params := manifests.Params{
31+
params := Params{
3332
TargetAllocator: targetAllocator,
3433
Config: cfg,
3534
Log: logger,

‎internal/manifests/targetallocator/serviceaccount.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2020

2121
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
22-
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2322
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
2423
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
2524
)
@@ -34,7 +33,7 @@ func ServiceAccountName(instance v1alpha1.TargetAllocator) string {
3433
}
3534

3635
// ServiceAccount returns the service account for the given instance.
37-
func ServiceAccount(params manifests.Params) *corev1.ServiceAccount {
36+
func ServiceAccount(params Params) *corev1.ServiceAccount {
3837
if len(params.TargetAllocator.Spec.ServiceAccount) > 0 {
3938
return nil
4039
}

‎internal/manifests/targetallocator/serviceaccount_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
2525
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
26-
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2726
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
2827
)
2928

@@ -63,7 +62,7 @@ func TestServiceAccountOverrideName(t *testing.T) {
6362
}
6463

6564
func TestServiceAccountDefault(t *testing.T) {
66-
params := manifests.Params{
65+
params := Params{
6766
TargetAllocator: v1alpha1.TargetAllocator{
6867
ObjectMeta: metav1.ObjectMeta{
6968
Name: "my-instance",
@@ -73,9 +72,9 @@ func TestServiceAccountDefault(t *testing.T) {
7372
expected := &corev1.ServiceAccount{
7473
ObjectMeta: metav1.ObjectMeta{
7574
Name: "my-instance-targetallocator",
76-
Namespace: params.OtelCol.Namespace,
75+
Namespace: params.Collector.Namespace,
7776
Labels: manifestutils.Labels(params.TargetAllocator.ObjectMeta, "my-instance-targetallocator", params.TargetAllocator.Spec.Image, ComponentOpenTelemetryTargetAllocator, nil),
78-
Annotations: params.OtelCol.Annotations,
77+
Annotations: params.Collector.Annotations,
7978
},
8079
}
8180

@@ -87,7 +86,7 @@ func TestServiceAccountDefault(t *testing.T) {
8786
}
8887

8988
func TestServiceAccountOverride(t *testing.T) {
90-
params := manifests.Params{
89+
params := Params{
9190
TargetAllocator: v1alpha1.TargetAllocator{
9291
ObjectMeta: metav1.ObjectMeta{
9392
Name: "my-instance",

‎internal/manifests/targetallocator/servicemonitor.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ import (
1818
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
1919
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2020

21-
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2221
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils"
2322
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
2423
)
2524

2625
// ServiceMonitor returns the service monitor for the given instance.
27-
func ServiceMonitor(params manifests.Params) *monitoringv1.ServiceMonitor {
26+
func ServiceMonitor(params Params) *monitoringv1.ServiceMonitor {
2827
name := naming.TargetAllocator(params.TargetAllocator.Name)
2928
labels := manifestutils.Labels(params.TargetAllocator.ObjectMeta, name, params.TargetAllocator.Spec.Image, ComponentOpenTelemetryTargetAllocator, nil)
3029

‎internal/manifests/targetallocator/servicemonitor_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
2525
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
2626
"github.com/open-telemetry/opentelemetry-operator/internal/config"
27-
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2827
)
2928

3029
func TestDesiredServiceMonitors(t *testing.T) {
@@ -41,7 +40,7 @@ func TestDesiredServiceMonitors(t *testing.T) {
4140
}
4241
cfg := config.New()
4342

44-
params := manifests.Params{
43+
params := Params{
4544
TargetAllocator: ta,
4645
Config: cfg,
4746
Log: logger,

‎internal/manifests/targetallocator/targetallocator.go

+18-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@
1515
package targetallocator
1616

1717
import (
18+
"github.com/go-logr/logr"
19+
"k8s.io/apimachinery/pkg/runtime"
20+
"k8s.io/client-go/tools/record"
1821
"sigs.k8s.io/controller-runtime/pkg/client"
1922

23+
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
24+
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
25+
"github.com/open-telemetry/opentelemetry-operator/internal/config"
2026
"github.com/open-telemetry/opentelemetry-operator/internal/manifests"
2127
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
2228
)
@@ -26,12 +32,9 @@ const (
2632
)
2733

2834
// Build creates the manifest for the TargetAllocator resource.
29-
func Build(params manifests.Params) ([]client.Object, error) {
35+
func Build(params Params) ([]client.Object, error) {
3036
var resourceManifests []client.Object
31-
if !params.OtelCol.Spec.TargetAllocator.Enabled {
32-
return resourceManifests, nil
33-
}
34-
resourceFactories := []manifests.K8sManifestFactory{
37+
resourceFactories := []manifests.K8sManifestFactory[Params]{
3538
manifests.Factory(ConfigMap),
3639
manifests.Factory(Deployment),
3740
manifests.FactoryWithoutError(ServiceAccount),
@@ -53,3 +56,13 @@ func Build(params manifests.Params) ([]client.Object, error) {
5356
}
5457
return resourceManifests, nil
5558
}
59+
60+
type Params struct {
61+
Client client.Client
62+
Recorder record.EventRecorder
63+
Scheme *runtime.Scheme
64+
Log logr.Logger
65+
Collector v1beta1.OpenTelemetryCollector
66+
TargetAllocator v1alpha1.TargetAllocator
67+
Config config.Config
68+
}

0 commit comments

Comments
 (0)
Please sign in to comment.