From cca245125f0cda23a8c4bd8ebca5ea8b634341f0 Mon Sep 17 00:00:00 2001 From: Pavol Loffay Date: Wed, 15 Dec 2021 11:33:26 +0100 Subject: [PATCH] Add support for nodejs and python image defaulting and upgrade (#607) * Add support nodejs and python image defaulting and upgrade Signed-off-by: Pavol Loffay * Fix Signed-off-by: Pavol Loffay * Fix Signed-off-by: Pavol Loffay * Fix Signed-off-by: Pavol Loffay * Fix Signed-off-by: Pavol Loffay * Fix typo Signed-off-by: Pavol Loffay --- Dockerfile | 4 +- Makefile | 6 +- README.md | 6 -- apis/v1alpha1/instrumentation_webhook.go | 14 ++++- apis/v1alpha1/instrumentation_webhook_test.go | 10 ++- internal/config/main.go | 48 +++++++++------ internal/config/options.go | 38 ++++++++---- internal/version/main.go | 61 +++++++++++++------ internal/version/main_test.go | 10 ++- main.go | 35 +++++++---- pkg/instrumentation/upgrade/upgrade.go | 28 +++++++-- pkg/instrumentation/upgrade/upgrade_test.go | 18 ++++-- .../00-install-instrumentation.yaml | 2 - .../00-install-instrumentation.yaml | 2 - 14 files changed, 197 insertions(+), 85 deletions(-) diff --git a/Dockerfile b/Dockerfile index 98b250aee6..ddfa75f241 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,9 +23,11 @@ ARG VERSION_DATE ARG OTELCOL_VERSION ARG TARGETALLOCATOR_VERSION ARG AUTO_INSTRUMENTATION_JAVA_VERSION +ARG AUTO_INSTRUMENTATION_NODEJS_VERSION +ARG AUTO_INSTRUMENTATION_PYTHON_VERSION # Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.otelCol=${OTELCOL_VERSION} -X ${VERSION_PKG}.targetAllocator=${TARGETALLOCATOR_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION}" -a -o manager main.go +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.otelCol=${OTELCOL_VERSION} -X ${VERSION_PKG}.targetAllocator=${TARGETALLOCATOR_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${AUTO_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${AUTO_INSTRUMENTATION_PYTHON_VERSION}" -a -o manager main.go # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details diff --git a/Makefile b/Makefile index 386bc02cfb..5886482833 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,9 @@ OTELCOL_VERSION ?= "$(shell grep -v '\#' versions.txt | grep opentelemetry-colle OPERATOR_VERSION ?= "$(shell grep -v '\#' versions.txt | grep operator | awk -F= '{print $$2}')" TARGETALLOCATOR_VERSION ?= "$(shell grep -v '\#' versions.txt | grep targetallocator | awk -F= '{print $$2}')" AUTO_INSTRUMENTATION_JAVA_VERSION ?= "$(shell grep -v '\#' versions.txt | grep autoinstrumentation-java | awk -F= '{print $$2}')" -LD_FLAGS ?= "-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.otelCol=${OTELCOL_VERSION} -X ${VERSION_PKG}.targetAllocator=${TARGETALLOCATOR_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION}" +AUTO_INSTRUMENTATION_NODEJS_VERSION ?= "$(shell grep -v '\#' versions.txt | grep autoinstrumentation-nodejs | awk -F= '{print $$2}')" +AUTO_INSTRUMENTATION_PYTHON_VERSION ?= "$(shell grep -v '\#' versions.txt | grep autoinstrumentation-python | awk -F= '{print $$2}')" +LD_FLAGS ?= "-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.otelCol=${OTELCOL_VERSION} -X ${VERSION_PKG}.targetAllocator=${TARGETALLOCATOR_VERSION} -X ${VERSION_PKG}.autoInstrumentationJava=${AUTO_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${AUTO_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${AUTO_INSTRUMENTATION_PYTHON_VERSION}" # Image URL to use all building/pushing image targets IMG_PREFIX ?= ghcr.io/${USER}/opentelemetry-operator @@ -134,7 +136,7 @@ set-test-image-vars: # Build the container image, used only for local dev purposes container: - docker build -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg OTELCOL_VERSION=${OTELCOL_VERSION} --build-arg TARGETALLOCATOR_VERSION=${TARGETALLOCATOR_VERSION} --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION=${AUTO_INSTRUMENTATION_JAVA_VERSION} . + docker build -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg OTELCOL_VERSION=${OTELCOL_VERSION} --build-arg TARGETALLOCATOR_VERSION=${TARGETALLOCATOR_VERSION} --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION=${AUTO_INSTRUMENTATION_JAVA_VERSION} --build-arg AUTO_INSTRUMENTATION_NODEJS_VERSION=${AUTO_INSTRUMENTATION_NODEJS_VERSION} --build-arg AUTO_INSTRUMENTATION_PYTHON_VERSION=${AUTO_INSTRUMENTATION_PYTHON_VERSION} . # Push the container image, used only for local dev purposes container-push: diff --git a/README.md b/README.md index 2e2e23287f..44a695fcb0 100644 --- a/README.md +++ b/README.md @@ -186,12 +186,6 @@ spec: sampler: type: parentbased_traceidratio argument: "0.25" - java: - image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:latest - nodejs: - image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-nodejs:latest - python: - image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-python:latest EOF ``` diff --git a/apis/v1alpha1/instrumentation_webhook.go b/apis/v1alpha1/instrumentation_webhook.go index b1a8267d58..fd71daada2 100644 --- a/apis/v1alpha1/instrumentation_webhook.go +++ b/apis/v1alpha1/instrumentation_webhook.go @@ -25,7 +25,9 @@ import ( ) const ( - AnnotationDefaultAutoInstrumentationJava = "instrumentation.opentelemetry.io/default-auto-instrumentation-java-image" + AnnotationDefaultAutoInstrumentationJava = "instrumentation.opentelemetry.io/default-auto-instrumentation-java-image" + AnnotationDefaultAutoInstrumentationNodeJS = "instrumentation.opentelemetry.io/default-auto-instrumentation-nodejs-image" + AnnotationDefaultAutoInstrumentationPython = "instrumentation.opentelemetry.io/default-auto-instrumentation-python-image" ) // log is for logging in this package. @@ -56,6 +58,16 @@ func (r *Instrumentation) Default() { r.Spec.Java.Image = val } } + if r.Spec.NodeJS.Image == "" { + if val, ok := r.Annotations[AnnotationDefaultAutoInstrumentationNodeJS]; ok { + r.Spec.NodeJS.Image = val + } + } + if r.Spec.Python.Image == "" { + if val, ok := r.Annotations[AnnotationDefaultAutoInstrumentationPython]; ok { + r.Spec.Python.Image = val + } + } } // +kubebuilder:webhook:verbs=create;update,path=/validate-opentelemetry-io-v1alpha1-instrumentation,mutating=false,failurePolicy=fail,groups=opentelemetry.io,resources=instrumentations,versions=v1alpha1,name=vinstrumentationcreateupdate.kb.io,sideEffects=none,admissionReviewVersions={v1,v1beta1} diff --git a/apis/v1alpha1/instrumentation_webhook_test.go b/apis/v1alpha1/instrumentation_webhook_test.go index 1f60652a7d..622e3ce8e6 100644 --- a/apis/v1alpha1/instrumentation_webhook_test.go +++ b/apis/v1alpha1/instrumentation_webhook_test.go @@ -24,11 +24,17 @@ import ( func TestInstrumentationDefaultingWebhook(t *testing.T) { inst := &Instrumentation{ ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{AnnotationDefaultAutoInstrumentationJava: "img:1"}, + Annotations: map[string]string{ + AnnotationDefaultAutoInstrumentationJava: "java-img:1", + AnnotationDefaultAutoInstrumentationNodeJS: "nodejs-img:1", + AnnotationDefaultAutoInstrumentationPython: "python-img:1", + }, }, } inst.Default() - assert.Equal(t, "img:1", inst.Spec.Java.Image) + assert.Equal(t, "java-img:1", inst.Spec.Java.Image) + assert.Equal(t, "nodejs-img:1", inst.Spec.NodeJS.Image) + assert.Equal(t, "python-img:1", inst.Spec.Python.Image) } func TestInstrumentationValidatingWebhook(t *testing.T) { diff --git a/internal/config/main.go b/internal/config/main.go index e54b1f2bc6..359d583dfa 100644 --- a/internal/config/main.go +++ b/internal/config/main.go @@ -44,12 +44,14 @@ type Config struct { onChange []func() error // config state - collectorImage string - collectorConfigMapEntry string - targetAllocatorImage string - targetAllocatorConfigMapEntry string - platform platform.Platform - autoInstrumentationJavaImage string + collectorImage string + collectorConfigMapEntry string + targetAllocatorImage string + targetAllocatorConfigMapEntry string + platform platform.Platform + autoInstrumentationJavaImage string + autoInstrumentationNodeJSImage string + autoInstrumentationPythonImage string } // New constructs a new configuration based on the given options. @@ -68,16 +70,18 @@ func New(opts ...Option) Config { } return Config{ - autoDetect: o.autoDetect, - autoDetectFrequency: o.autoDetectFrequency, - collectorImage: o.collectorImage, - collectorConfigMapEntry: o.collectorConfigMapEntry, - targetAllocatorImage: o.targetAllocatorImage, - targetAllocatorConfigMapEntry: o.targetAllocatorConfigMapEntry, - logger: o.logger, - onChange: o.onChange, - platform: o.platform, - autoInstrumentationJavaImage: o.autoInstrumentationjavaImage, + autoDetect: o.autoDetect, + autoDetectFrequency: o.autoDetectFrequency, + collectorImage: o.collectorImage, + collectorConfigMapEntry: o.collectorConfigMapEntry, + targetAllocatorImage: o.targetAllocatorImage, + targetAllocatorConfigMapEntry: o.targetAllocatorConfigMapEntry, + logger: o.logger, + onChange: o.onChange, + platform: o.platform, + autoInstrumentationJavaImage: o.autoInstrumentationJavaImage, + autoInstrumentationNodeJSImage: o.autoInstrumentationNodeJSImage, + autoInstrumentationPythonImage: o.autoInstrumentationPythonImage, } } @@ -169,7 +173,17 @@ func (c *Config) Platform() platform.Platform { return c.platform } -// AutoInstrumentationJavaImage returns OpenTelemetry auto-instrumentation container image. +// AutoInstrumentationJavaImage returns OpenTelemetry Java auto-instrumentation container image. func (c *Config) AutoInstrumentationJavaImage() string { return c.autoInstrumentationJavaImage } + +// AutoInstrumentationNodeJSImage returns OpenTelemetry NodeJS auto-instrumentation container image. +func (c *Config) AutoInstrumentationNodeJSImage() string { + return c.autoInstrumentationNodeJSImage +} + +// AutoInstrumentationPythonImage returns OpenTelemetry Python auto-instrumentation container image. +func (c *Config) AutoInstrumentationPythonImage() string { + return c.autoInstrumentationPythonImage +} diff --git a/internal/config/options.go b/internal/config/options.go index 997c12775f..727c880948 100644 --- a/internal/config/options.go +++ b/internal/config/options.go @@ -28,17 +28,19 @@ import ( type Option func(c *options) type options struct { - autoDetect autodetect.AutoDetect - autoDetectFrequency time.Duration - targetAllocatorImage string - collectorImage string - autoInstrumentationjavaImage string - collectorConfigMapEntry string - targetAllocatorConfigMapEntry string - logger logr.Logger - onChange []func() error - platform platform.Platform - version version.Version + autoDetect autodetect.AutoDetect + autoDetectFrequency time.Duration + targetAllocatorImage string + collectorImage string + autoInstrumentationJavaImage string + autoInstrumentationNodeJSImage string + autoInstrumentationPythonImage string + collectorConfigMapEntry string + targetAllocatorConfigMapEntry string + logger logr.Logger + onChange []func() error + platform platform.Platform + version version.Version } func WithAutoDetect(a autodetect.AutoDetect) Option { @@ -98,6 +100,18 @@ func WithVersion(v version.Version) Option { func WithAutoInstrumentationJavaImage(s string) Option { return func(o *options) { - o.autoInstrumentationjavaImage = s + o.autoInstrumentationJavaImage = s + } +} + +func WithAutoInstrumentationNodeJSImage(s string) Option { + return func(o *options) { + o.autoInstrumentationNodeJSImage = s + } +} + +func WithAutoInstrumentationPythonImage(s string) Option { + return func(o *options) { + o.autoInstrumentationPythonImage = s } } diff --git a/internal/version/main.go b/internal/version/main.go index d16ea683c3..5b2dcc5397 100644 --- a/internal/version/main.go +++ b/internal/version/main.go @@ -21,43 +21,52 @@ import ( ) var ( - version string - buildDate string - otelCol string - targetAllocator string - autoInstrumentationJava string + version string + buildDate string + otelCol string + targetAllocator string + autoInstrumentationJava string + autoInstrumentationNodeJS string + autoInstrumentationPython string ) // Version holds this Operator's version as well as the version of some of the components it uses. type Version struct { - Operator string `json:"opentelemetry-operator"` - BuildDate string `json:"build-date"` - OpenTelemetryCollector string `json:"opentelemetry-collector-version"` - Go string `json:"go-version"` - TargetAllocator string `json:"target-allocator-version"` - JavaAutoInstrumentation string `json:"auto-instrumentation-java"` + Operator string `json:"opentelemetry-operator"` + BuildDate string `json:"build-date"` + OpenTelemetryCollector string `json:"opentelemetry-collector-version"` + Go string `json:"go-version"` + TargetAllocator string `json:"target-allocator-version"` + AutoInstrumentationJava string `json:"auto-instrumentation-java"` + AutoInstrumentationNodeJS string `json:"auto-instrumentation-nodejs"` + AutoInstrumentationPython string `json:"auto-instrumentation-python"` } // Get returns the Version object with the relevant information. func Get() Version { return Version{ - Operator: version, - BuildDate: buildDate, - OpenTelemetryCollector: OpenTelemetryCollector(), - Go: runtime.Version(), - TargetAllocator: TargetAllocator(), - JavaAutoInstrumentation: javaAutoInstrumentation(), + Operator: version, + BuildDate: buildDate, + OpenTelemetryCollector: OpenTelemetryCollector(), + Go: runtime.Version(), + TargetAllocator: TargetAllocator(), + AutoInstrumentationJava: AutoInstrumentationJava(), + AutoInstrumentationNodeJS: AutoInstrumentationNodeJS(), + AutoInstrumentationPython: AutoInstrumentationPython(), } } func (v Version) String() string { return fmt.Sprintf( - "Version(Operator='%v', BuildDate='%v', OpenTelemetryCollector='%v', Go='%v', TargetAllocator='%v')", + "Version(Operator='%v', BuildDate='%v', OpenTelemetryCollector='%v', Go='%v', TargetAllocator='%v', AutoInstrumentationJava='%v', AutoInstrumentationNodeJS='%v', AutoInstrumentationPython='%v')", v.Operator, v.BuildDate, v.OpenTelemetryCollector, v.Go, v.TargetAllocator, + v.AutoInstrumentationJava, + v.AutoInstrumentationNodeJS, + v.AutoInstrumentationPython, ) } @@ -83,9 +92,23 @@ func TargetAllocator() string { return "0.0.0" } -func javaAutoInstrumentation() string { +func AutoInstrumentationJava() string { if len(autoInstrumentationJava) > 0 { return autoInstrumentationJava } return "0.0.0" } + +func AutoInstrumentationNodeJS() string { + if len(autoInstrumentationNodeJS) > 0 { + return autoInstrumentationNodeJS + } + return "0.0.0" +} + +func AutoInstrumentationPython() string { + if len(autoInstrumentationPython) > 0 { + return autoInstrumentationPython + } + return "0.0.0" +} diff --git a/internal/version/main_test.go b/internal/version/main_test.go index fdc282dd92..65d1943371 100644 --- a/internal/version/main_test.go +++ b/internal/version/main_test.go @@ -51,5 +51,13 @@ func TestTargetAllocatorVersionFromBuild(t *testing.T) { } func TestAutoInstrumentationJavaFallbackVersion(t *testing.T) { - assert.Equal(t, "0.0.0", javaAutoInstrumentation()) + assert.Equal(t, "0.0.0", AutoInstrumentationJava()) +} + +func TestAutoInstrumentationNodeJSFallbackVersion(t *testing.T) { + assert.Equal(t, "0.0.0", AutoInstrumentationNodeJS()) +} + +func TestAutoInstrumentationPythonFallbackVersion(t *testing.T) { + assert.Equal(t, "0.0.0", AutoInstrumentationPython()) } diff --git a/main.go b/main.go index 53fa9e9d42..62e2bfb388 100644 --- a/main.go +++ b/main.go @@ -70,12 +70,14 @@ func main() { // add flags related to this operator var ( - metricsAddr string - probeAddr string - enableLeaderElection bool - collectorImage string - targetAllocatorImage string - autoInstrumentationJava string + metricsAddr string + probeAddr string + enableLeaderElection bool + collectorImage string + targetAllocatorImage string + autoInstrumentationJava string + autoInstrumentationNodeJS string + autoInstrumentationPython string ) pflag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") flag.StringVar(&probeAddr, "health-probe-addr", ":8081", "The address the probe endpoint binds to.") @@ -84,7 +86,9 @@ func main() { "Enabling this will ensure there is only one active controller manager.") pflag.StringVar(&collectorImage, "collector-image", fmt.Sprintf("otel/opentelemetry-collector:%s", v.OpenTelemetryCollector), "The default OpenTelemetry collector image. This image is used when no image is specified in the CustomResource.") pflag.StringVar(&targetAllocatorImage, "target-allocator-image", fmt.Sprintf("quay.io/opentelemetry/target-allocator:%s", v.TargetAllocator), "The default OpenTelemetry target allocator image. This image is used when no image is specified in the CustomResource.") - pflag.StringVar(&autoInstrumentationJava, "auto-instrumentation-java-image", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:%s", v.JavaAutoInstrumentation), "The default OpenTelemetry Java instrumentation image. This image is used when no image is specified in the CustomResource.") + pflag.StringVar(&autoInstrumentationJava, "auto-instrumentation-java-image", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:%s", v.AutoInstrumentationJava), "The default OpenTelemetry Java instrumentation image. This image is used when no image is specified in the CustomResource.") + pflag.StringVar(&autoInstrumentationNodeJS, "auto-instrumentation-nodejs-image", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-nodejs:%s", v.AutoInstrumentationNodeJS), "The default OpenTelemetry NodeJS instrumentation image. This image is used when no image is specified in the CustomResource.") + pflag.StringVar(&autoInstrumentationPython, "auto-instrumentation-python-image", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-python:%s", v.AutoInstrumentationPython), "The default OpenTelemetry Python instrumentation image. This image is used when no image is specified in the CustomResource.") logger := zap.New(zap.UseFlagOptions(&opts)) ctrl.SetLogger(logger) @@ -94,6 +98,8 @@ func main() { "opentelemetry-collector", collectorImage, "opentelemetry-targetallocator", targetAllocatorImage, "auto-instrumentation-java", autoInstrumentationJava, + "auto-instrumentation-nodejs", autoInstrumentationNodeJS, + "auto-instrumentation-python", autoInstrumentationPython, "build-date", v.BuildDate, "go-version", v.Go, "go-arch", runtime.GOARCH, @@ -115,6 +121,8 @@ func main() { config.WithCollectorImage(collectorImage), config.WithTargetAllocatorImage(targetAllocatorImage), config.WithAutoInstrumentationJavaImage(autoInstrumentationJava), + config.WithAutoInstrumentationNodeJSImage(autoInstrumentationNodeJS), + config.WithAutoInstrumentationPythonImage(autoInstrumentationPython), config.WithAutoDetect(ad), ) @@ -175,7 +183,11 @@ func main() { } if err = (&otelv1alpha1.Instrumentation{ ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{otelv1alpha1.AnnotationDefaultAutoInstrumentationJava: autoInstrumentationJava}, + Annotations: map[string]string{ + otelv1alpha1.AnnotationDefaultAutoInstrumentationJava: autoInstrumentationJava, + otelv1alpha1.AnnotationDefaultAutoInstrumentationNodeJS: autoInstrumentationNodeJS, + otelv1alpha1.AnnotationDefaultAutoInstrumentationPython: autoInstrumentationPython, + }, }, }).SetupWebhookWithManager(mgr); err != nil { setupLog.Error(err, "unable to create webhook", "webhook", "Instrumentation") @@ -228,9 +240,10 @@ func addDependencies(_ context.Context, mgr ctrl.Manager, cfg config.Config, v v // adds the upgrade mechanism to be executed once the manager is ready err = mgr.Add(manager.RunnableFunc(func(c context.Context) error { u := &instrumentationupgrade.InstrumentationUpgrade{ - Logger: ctrl.Log.WithName("instrumentation-upgrade"), - DefaultAutoInstrJava: cfg.AutoInstrumentationJavaImage(), - Client: mgr.GetClient(), + Logger: ctrl.Log.WithName("instrumentation-upgrade"), + DefaultAutoInstJava: cfg.AutoInstrumentationJavaImage(), + DefaultAutoInstNodeJS: cfg.AutoInstrumentationJavaImage(), + Client: mgr.GetClient(), } return u.ManagedInstances(c) })) diff --git a/pkg/instrumentation/upgrade/upgrade.go b/pkg/instrumentation/upgrade/upgrade.go index e15aaab15d..9a702cbf3f 100644 --- a/pkg/instrumentation/upgrade/upgrade.go +++ b/pkg/instrumentation/upgrade/upgrade.go @@ -26,9 +26,11 @@ import ( ) type InstrumentationUpgrade struct { - Logger logr.Logger - DefaultAutoInstrJava string - Client client.Client + Logger logr.Logger + DefaultAutoInstJava string + DefaultAutoInstNodeJS string + DefaultAutoInstPython string + Client client.Client } //+kubebuilder:rbac:groups=opentelemetry.io,resources=instrumentations,verbs=get;list;watch;update;patch @@ -70,8 +72,24 @@ func (u *InstrumentationUpgrade) upgrade(_ context.Context, inst v1alpha1.Instru if autoInstJava != "" { // upgrade the image only if the image matches the annotation if inst.Spec.Java.Image == autoInstJava { - inst.Spec.Java.Image = u.DefaultAutoInstrJava - inst.Annotations[v1alpha1.AnnotationDefaultAutoInstrumentationJava] = u.DefaultAutoInstrJava + inst.Spec.Java.Image = u.DefaultAutoInstJava + inst.Annotations[v1alpha1.AnnotationDefaultAutoInstrumentationJava] = u.DefaultAutoInstJava + } + } + autoInstNodeJS := inst.Annotations[v1alpha1.AnnotationDefaultAutoInstrumentationNodeJS] + if autoInstNodeJS != "" { + // upgrade the image only if the image matches the annotation + if inst.Spec.NodeJS.Image == autoInstNodeJS { + inst.Spec.NodeJS.Image = u.DefaultAutoInstNodeJS + inst.Annotations[v1alpha1.AnnotationDefaultAutoInstrumentationNodeJS] = u.DefaultAutoInstNodeJS + } + } + autoInstPython := inst.Annotations[v1alpha1.AnnotationDefaultAutoInstrumentationPython] + if autoInstPython != "" { + // upgrade the image only if the image matches the annotation + if inst.Spec.Python.Image == autoInstPython { + inst.Spec.Python.Image = u.DefaultAutoInstPython + inst.Annotations[v1alpha1.AnnotationDefaultAutoInstrumentationPython] = u.DefaultAutoInstPython } } return inst diff --git a/pkg/instrumentation/upgrade/upgrade_test.go b/pkg/instrumentation/upgrade/upgrade_test.go index 5baa97d9a9..07eb0a9332 100644 --- a/pkg/instrumentation/upgrade/upgrade_test.go +++ b/pkg/instrumentation/upgrade/upgrade_test.go @@ -43,7 +43,9 @@ func TestUpgrade(t *testing.T) { Name: "my-inst", Namespace: nsName, Annotations: map[string]string{ - v1alpha1.AnnotationDefaultAutoInstrumentationJava: "java:1", + v1alpha1.AnnotationDefaultAutoInstrumentationJava: "java:1", + v1alpha1.AnnotationDefaultAutoInstrumentationNodeJS: "nodejs:1", + v1alpha1.AnnotationDefaultAutoInstrumentationPython: "python:1", }, }, Spec: v1alpha1.InstrumentationSpec{ @@ -54,13 +56,17 @@ func TestUpgrade(t *testing.T) { } inst.Default() assert.Equal(t, "java:1", inst.Spec.Java.Image) + assert.Equal(t, "nodejs:1", inst.Spec.NodeJS.Image) + assert.Equal(t, "python:1", inst.Spec.Python.Image) err = k8sClient.Create(context.Background(), inst) require.NoError(t, err) up := &InstrumentationUpgrade{ - Logger: logr.Discard(), - DefaultAutoInstrJava: "java:2", - Client: k8sClient, + Logger: logr.Discard(), + DefaultAutoInstJava: "java:2", + DefaultAutoInstNodeJS: "nodejs:2", + DefaultAutoInstPython: "python:2", + Client: k8sClient, } err = up.ManagedInstances(context.Background()) require.NoError(t, err) @@ -73,4 +79,8 @@ func TestUpgrade(t *testing.T) { require.NoError(t, err) assert.Equal(t, "java:2", updated.Annotations[v1alpha1.AnnotationDefaultAutoInstrumentationJava]) assert.Equal(t, "java:2", updated.Spec.Java.Image) + assert.Equal(t, "nodejs:2", updated.Annotations[v1alpha1.AnnotationDefaultAutoInstrumentationNodeJS]) + assert.Equal(t, "nodejs:2", updated.Spec.NodeJS.Image) + assert.Equal(t, "python:2", updated.Annotations[v1alpha1.AnnotationDefaultAutoInstrumentationPython]) + assert.Equal(t, "python:2", updated.Spec.Python.Image) } diff --git a/tests/e2e/instrumentation-nodejs/00-install-instrumentation.yaml b/tests/e2e/instrumentation-nodejs/00-install-instrumentation.yaml index a17642f744..9ea4358b9b 100644 --- a/tests/e2e/instrumentation-nodejs/00-install-instrumentation.yaml +++ b/tests/e2e/instrumentation-nodejs/00-install-instrumentation.yaml @@ -8,5 +8,3 @@ spec: propagators: - jaeger - b3 - nodejs: - image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-nodejs:latest diff --git a/tests/e2e/instrumentation-python/00-install-instrumentation.yaml b/tests/e2e/instrumentation-python/00-install-instrumentation.yaml index 786a4ba9e3..d41827bf8f 100644 --- a/tests/e2e/instrumentation-python/00-install-instrumentation.yaml +++ b/tests/e2e/instrumentation-python/00-install-instrumentation.yaml @@ -8,5 +8,3 @@ spec: propagators: - jaeger - b3 - python: - image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-python:latest