Skip to content

Commit f10ed8f

Browse files
committed
replace instrumentationupgrade initialization
1 parent 4fd738e commit f10ed8f

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

main.go

+6-12
Original file line numberDiff line numberDiff line change
@@ -346,18 +346,12 @@ func addDependencies(_ context.Context, mgr ctrl.Manager, cfg config.Config, v v
346346

347347
// adds the upgrade mechanism to be executed once the manager is ready
348348
err = mgr.Add(manager.RunnableFunc(func(c context.Context) error {
349-
u := &instrumentationupgrade.InstrumentationUpgrade{
350-
Logger: ctrl.Log.WithName("instrumentation-upgrade"),
351-
DefaultAutoInstJava: cfg.AutoInstrumentationJavaImage(),
352-
DefaultAutoInstNodeJS: cfg.AutoInstrumentationNodeJSImage(),
353-
DefaultAutoInstPython: cfg.AutoInstrumentationPythonImage(),
354-
DefaultAutoInstDotNet: cfg.AutoInstrumentationDotNetImage(),
355-
DefaultAutoInstGo: cfg.AutoInstrumentationDotNetImage(),
356-
DefaultAutoInstApacheHttpd: cfg.AutoInstrumentationApacheHttpdImage(),
357-
DefaultAutoInstNginx: cfg.AutoInstrumentationNginxImage(),
358-
Client: mgr.GetClient(),
359-
Recorder: mgr.GetEventRecorderFor("opentelemetry-operator"),
360-
}
349+
u := instrumentationupgrade.NewInstrumentationUpgrade(
350+
mgr.GetClient(),
351+
ctrl.Log.WithName("instrumentation-upgrade"),
352+
mgr.GetEventRecorderFor("opentelemetry-operator"),
353+
cfg,
354+
)
361355
return u.ManagedInstances(c)
362356
}))
363357
if err != nil {

pkg/instrumentation/upgrade/upgrade.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/go-logr/logr"
2323
featuregate2 "go.opentelemetry.io/collector/featuregate"
2424
"k8s.io/client-go/tools/record"
25-
ctrl "sigs.k8s.io/controller-runtime"
2625
"sigs.k8s.io/controller-runtime/pkg/client"
2726

2827
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
@@ -61,14 +60,14 @@ type InstrumentationUpgrade struct {
6160
defaultAnnotationToConfig map[string]autoInstConfig
6261
}
6362

64-
func NewInstrumentationUpgrade(client client.Client, recorder record.EventRecorder, cfg config.Config) *InstrumentationUpgrade {
63+
func NewInstrumentationUpgrade(client client.Client, logger logr.Logger, recorder record.EventRecorder, cfg config.Config) *InstrumentationUpgrade {
6564
defaultAnnotationToConfig := map[string]autoInstConfig{
6665
constants.AnnotationDefaultAutoInstrumentationApacheHttpd: autoInstConfig{constants.ApacheHttpd, cfg.EnableApacheHTTPAutoInstrumentation()},
6766
}
6867

6968
return &InstrumentationUpgrade{
7069
Client: client,
71-
Logger: ctrl.Log.WithName("instrumentation-upgrade"),
70+
Logger: logger,
7271
DefaultAutoInstJava: cfg.AutoInstrumentationJavaImage(),
7372
DefaultAutoInstNodeJS: cfg.AutoInstrumentationNodeJSImage(),
7473
DefaultAutoInstPython: cfg.AutoInstrumentationPythonImage(),

pkg/instrumentation/upgrade/upgrade_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
"k8s.io/apimachinery/pkg/types"
2929
"k8s.io/client-go/tools/record"
30+
ctrl "sigs.k8s.io/controller-runtime"
3031

3132
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
3233
"github.com/open-telemetry/opentelemetry-operator/internal/config"
@@ -101,7 +102,7 @@ func TestUpgrade(t *testing.T) {
101102
config.WithAutoInstrumentationNginxImage("nginx:2"),
102103
config.WithEnableApacheHTTPInstrumentation(true),
103104
)
104-
up := NewInstrumentationUpgrade(k8sClient, &record.FakeRecorder{}, cfg)
105+
up := NewInstrumentationUpgrade(k8sClient, ctrl.Log.WithName("instrumentation-upgrade"), &record.FakeRecorder{}, cfg)
105106

106107
err = up.ManagedInstances(context.Background())
107108
require.NoError(t, err)

0 commit comments

Comments
 (0)