From e1a0f4be907d5c3b668e470f8543329a4340fb67 Mon Sep 17 00:00:00 2001 From: Duncan-tree-zhou Date: Thu, 20 Jan 2022 01:13:41 +0800 Subject: [PATCH 1/8] allow config customized envs on common and language specific node. --- apis/v1alpha1/instrumentation_types.go | 25 +++++++ bundle.Dockerfile | 2 +- ...emetry-operator.clusterserviceversion.yaml | 70 +++++++++---------- bundle/metadata/annotations.yaml | 2 +- config/manager/kustomization.yaml | 8 ++- pkg/instrumentation/javaagent.go | 12 ++++ pkg/instrumentation/nodejs.go | 12 ++++ pkg/instrumentation/python.go | 12 ++++ pkg/instrumentation/sdk.go | 23 +++++- 9 files changed, 125 insertions(+), 41 deletions(-) diff --git a/apis/v1alpha1/instrumentation_types.go b/apis/v1alpha1/instrumentation_types.go index de60bdfc53..3e3006dcb2 100644 --- a/apis/v1alpha1/instrumentation_types.go +++ b/apis/v1alpha1/instrumentation_types.go @@ -36,6 +36,9 @@ type InstrumentationSpec struct { // +optional Sampler `json:"sampler,omitempty"` + // Env defines customized environments. + Env []Env `json:"env,omitempty"` + // Java defines configuration for java auto-instrumentation. // +optional Java Java `json:"java,omitempty"` @@ -83,11 +86,25 @@ type Sampler struct { Argument string `json:"argument,omitempty"` } +// Env defines customized envs. +type Env struct { + // Name defines environments name. + Name string `json:"name"` + + // Value defines environments value. + // +optional + Value string `json:"value,omitempty"` +} + // Java defines Java SDK and instrumentation configuration. type Java struct { // Image is a container image with javaagent auto-instrumentation JAR. // +optional Image string `json:"image,omitempty"` + + // Env defines customized environments. + // +optional + Env []Env `json:"env,omitempty"` } // NodeJS defines NodeJS SDK and instrumentation configuration. @@ -95,6 +112,10 @@ type NodeJS struct { // Image is a container image with NodeJS SDK and auto-instrumentation. // +optional Image string `json:"image,omitempty"` + + // Env defines customized environments. + // +optional + Env []Env `json:"env,omitempty"` } // Python defines Python SDK and instrumentation configuration. @@ -102,6 +123,10 @@ type Python struct { // Image is a container image with Python SDK and auto-instrumentation. // +optional Image string `json:"image,omitempty"` + + // Env defines customized environments. + // +optional + Env []Env `json:"env,omitempty"` } // InstrumentationStatus defines status of the instrumentation. diff --git a/bundle.Dockerfile b/bundle.Dockerfile index 7996432a7e..e9e88cc4e5 100644 --- a/bundle.Dockerfile +++ b/bundle.Dockerfile @@ -6,7 +6,7 @@ LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ LABEL operators.operatorframework.io.bundle.package.v1=opentelemetry-operator LABEL operators.operatorframework.io.bundle.channels.v1=alpha -LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.13.0+git +LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.16.0 LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1 LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3 diff --git a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml index 2882f81592..18cbc85761 100644 --- a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml +++ b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml @@ -33,7 +33,7 @@ metadata: containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator createdAt: "2020-12-16T13:37:00+00:00" description: Provides the OpenTelemetry components, including the Collector - operators.operatorframework.io/builder: operator-sdk-v1.13.0+git + operators.operatorframework.io/builder: operator-sdk-v1.16.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 repository: github.com/open-telemetry/opentelemetry-operator support: OpenTelemetry Community @@ -265,7 +265,7 @@ spec: - args: - --metrics-addr=127.0.0.1:8080 - --enable-leader-election - image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:v0.42.0 + image: ghcr.io/duncan/opentelemetry-operator/opentelemetry-operator:v0.42.0 livenessProbe: httpGet: path: /healthz @@ -376,29 +376,29 @@ spec: - v1beta1 containerPort: 443 deploymentName: opentelemetry-operator-controller-manager - failurePolicy: Ignore - generateName: mpod.kb.io + failurePolicy: Fail + generateName: minstrumentation.kb.io rules: - apiGroups: - - "" + - opentelemetry.io apiVersions: - - v1 + - v1alpha1 operations: - CREATE - UPDATE resources: - - pods + - instrumentations sideEffects: None targetPort: 9443 type: MutatingAdmissionWebhook - webhookPath: /mutate-v1-pod + webhookPath: /mutate-opentelemetry-io-v1alpha1-instrumentation - admissionReviewVersions: - v1 - v1beta1 containerPort: 443 deploymentName: opentelemetry-operator-controller-manager failurePolicy: Fail - generateName: minstrumentation.kb.io + generateName: mopentelemetrycollector.kb.io rules: - apiGroups: - opentelemetry.io @@ -408,46 +408,47 @@ spec: - CREATE - UPDATE resources: - - instrumentations + - opentelemetrycollectors sideEffects: None targetPort: 9443 type: MutatingAdmissionWebhook - webhookPath: /mutate-opentelemetry-io-v1alpha1-instrumentation + webhookPath: /mutate-opentelemetry-io-v1alpha1-opentelemetrycollector - admissionReviewVersions: - v1 - v1beta1 containerPort: 443 deploymentName: opentelemetry-operator-controller-manager - failurePolicy: Fail - generateName: mopentelemetrycollector.kb.io + failurePolicy: Ignore + generateName: mpod.kb.io rules: - apiGroups: - - opentelemetry.io + - "" apiVersions: - - v1alpha1 + - v1 operations: - CREATE - UPDATE resources: - - opentelemetrycollectors + - pods sideEffects: None targetPort: 9443 type: MutatingAdmissionWebhook - webhookPath: /mutate-opentelemetry-io-v1alpha1-opentelemetrycollector + webhookPath: /mutate-v1-pod - admissionReviewVersions: - v1 - v1beta1 containerPort: 443 deploymentName: opentelemetry-operator-controller-manager - failurePolicy: Ignore - generateName: vinstrumentationdelete.kb.io + failurePolicy: Fail + generateName: vinstrumentationcreateupdate.kb.io rules: - apiGroups: - opentelemetry.io apiVersions: - v1alpha1 operations: - - DELETE + - CREATE + - UPDATE resources: - instrumentations sideEffects: None @@ -459,36 +460,36 @@ spec: - v1beta1 containerPort: 443 deploymentName: opentelemetry-operator-controller-manager - failurePolicy: Fail - generateName: vopentelemetrycollectorcreateupdate.kb.io + failurePolicy: Ignore + generateName: vinstrumentationdelete.kb.io rules: - apiGroups: - opentelemetry.io apiVersions: - v1alpha1 operations: - - CREATE - - UPDATE + - DELETE resources: - - opentelemetrycollectors + - instrumentations sideEffects: None targetPort: 9443 type: ValidatingAdmissionWebhook - webhookPath: /validate-opentelemetry-io-v1alpha1-opentelemetrycollector + webhookPath: /validate-opentelemetry-io-v1alpha1-instrumentation - admissionReviewVersions: - v1 - v1beta1 containerPort: 443 deploymentName: opentelemetry-operator-controller-manager - failurePolicy: Ignore - generateName: vopentelemetrycollectordelete.kb.io + failurePolicy: Fail + generateName: vopentelemetrycollectorcreateupdate.kb.io rules: - apiGroups: - opentelemetry.io apiVersions: - v1alpha1 operations: - - DELETE + - CREATE + - UPDATE resources: - opentelemetrycollectors sideEffects: None @@ -500,19 +501,18 @@ spec: - v1beta1 containerPort: 443 deploymentName: opentelemetry-operator-controller-manager - failurePolicy: Fail - generateName: vinstrumentationcreateupdate.kb.io + failurePolicy: Ignore + generateName: vopentelemetrycollectordelete.kb.io rules: - apiGroups: - opentelemetry.io apiVersions: - v1alpha1 operations: - - CREATE - - UPDATE + - DELETE resources: - - instrumentations + - opentelemetrycollectors sideEffects: None targetPort: 9443 type: ValidatingAdmissionWebhook - webhookPath: /validate-opentelemetry-io-v1alpha1-instrumentation + webhookPath: /validate-opentelemetry-io-v1alpha1-opentelemetrycollector diff --git a/bundle/metadata/annotations.yaml b/bundle/metadata/annotations.yaml index 963e2b6a18..0a27391f05 100644 --- a/bundle/metadata/annotations.yaml +++ b/bundle/metadata/annotations.yaml @@ -5,7 +5,7 @@ annotations: operators.operatorframework.io.bundle.metadata.v1: metadata/ operators.operatorframework.io.bundle.package.v1: opentelemetry-operator operators.operatorframework.io.bundle.channels.v1: alpha - operators.operatorframework.io.metrics.builder: operator-sdk-v1.13.0+git + operators.operatorframework.io.metrics.builder: operator-sdk-v1.16.0 operators.operatorframework.io.metrics.mediatype.v1: metrics+v1 operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v3 diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 7394a6d059..d24a8cf8ad 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,2 +1,8 @@ resources: - - manager.yaml +- manager.yaml +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +images: +- name: controller + newName: ghcr.io/duncan/opentelemetry-operator/opentelemetry-operator + newTag: v0.42.0 diff --git a/pkg/instrumentation/javaagent.go b/pkg/instrumentation/javaagent.go index 4636395898..7a1ccfa38e 100644 --- a/pkg/instrumentation/javaagent.go +++ b/pkg/instrumentation/javaagent.go @@ -29,6 +29,18 @@ const ( func injectJavaagent(logger logr.Logger, javaSpec v1alpha1.Java, pod corev1.Pod) corev1.Pod { // caller checks if there is at least one container container := &pod.Spec.Containers[0] + + // inject customized environments + for _, env := range javaSpec.Env { + idx := getIndexOfEnv(container.Env, env.Name) + if idx == -1 && len(env.Value) > 0 { + container.Env = append(container.Env, corev1.EnvVar{ + Name: env.Name, + Value: env.Value, + }) + } + } + idx := getIndexOfEnv(container.Env, envJavaToolsOptions) if idx == -1 { container.Env = append(container.Env, corev1.EnvVar{ diff --git a/pkg/instrumentation/nodejs.go b/pkg/instrumentation/nodejs.go index 5830481c6b..f7beaeb1a9 100644 --- a/pkg/instrumentation/nodejs.go +++ b/pkg/instrumentation/nodejs.go @@ -29,6 +29,18 @@ const ( func injectNodeJSSDK(logger logr.Logger, nodeJSSpec v1alpha1.NodeJS, pod corev1.Pod) corev1.Pod { // caller checks if there is at least one container container := &pod.Spec.Containers[0] + + // inject customized environments + for _, env := range nodeJSSpec.Env { + idx := getIndexOfEnv(container.Env, env.Name) + if idx == -1 && len(env.Value) > 0 { + container.Env = append(container.Env, corev1.EnvVar{ + Name: env.Name, + Value: env.Value, + }) + } + } + idx := getIndexOfEnv(container.Env, envNodeOptions) if idx == -1 { container.Env = append(container.Env, corev1.EnvVar{ diff --git a/pkg/instrumentation/python.go b/pkg/instrumentation/python.go index 5c9f3b1de7..4a946d8288 100644 --- a/pkg/instrumentation/python.go +++ b/pkg/instrumentation/python.go @@ -33,6 +33,18 @@ const ( func injectPythonSDK(logger logr.Logger, pythonSpec v1alpha1.Python, pod corev1.Pod) corev1.Pod { // caller checks if there is at least one container container := &pod.Spec.Containers[0] + + // inject customized environments + for _, env := range pythonSpec.Env { + idx := getIndexOfEnv(container.Env, env.Name) + if idx == -1 && len(env.Value) > 0 { + container.Env = append(container.Env, corev1.EnvVar{ + Name: env.Name, + Value: env.Value, + }) + } + } + idx := getIndexOfEnv(container.Env, envPythonPath) if idx == -1 { container.Env = append(container.Env, corev1.EnvVar{ diff --git a/pkg/instrumentation/sdk.go b/pkg/instrumentation/sdk.go index ad72757411..c32313fcab 100644 --- a/pkg/instrumentation/sdk.go +++ b/pkg/instrumentation/sdk.go @@ -66,20 +66,37 @@ func (i *sdkInjector) inject(ctx context.Context, insts languageInstrumentations if insts.Java != nil { otelinst := *insts.Java i.logger.V(1).Info("injecting java instrumentation into pod", "otelinst-namespace", otelinst.Namespace, "otelinst-name", otelinst.Name) - pod = i.injectCommonSDKConfig(ctx, otelinst, ns, pod) + pod = i.injectCommonCustomizedEnv(otelinst, ns, pod) pod = injectJavaagent(i.logger, otelinst.Spec.Java, pod) + pod = i.injectCommonSDKConfig(ctx, otelinst, ns, pod) } if insts.NodeJS != nil { otelinst := *insts.NodeJS i.logger.V(1).Info("injecting nodejs instrumentation into pod", "otelinst-namespace", otelinst.Namespace, "otelinst-name", otelinst.Name) - pod = i.injectCommonSDKConfig(ctx, otelinst, ns, pod) + pod = i.injectCommonCustomizedEnv(otelinst, ns, pod) pod = injectNodeJSSDK(i.logger, otelinst.Spec.NodeJS, pod) + pod = i.injectCommonSDKConfig(ctx, otelinst, ns, pod) } if insts.Python != nil { otelinst := *insts.Python i.logger.V(1).Info("injecting python instrumentation into pod", "otelinst-namespace", otelinst.Namespace, "otelinst-name", otelinst.Name) - pod = i.injectCommonSDKConfig(ctx, otelinst, ns, pod) + pod = i.injectCommonCustomizedEnv(otelinst, ns, pod) pod = injectPythonSDK(i.logger, otelinst.Spec.Python, pod) + pod = i.injectCommonSDKConfig(ctx, otelinst, ns, pod) + } + return pod +} + +func (i *sdkInjector) injectCommonCustomizedEnv(otelinst v1alpha1.Instrumentation, ns corev1.Namespace, pod corev1.Pod) corev1.Pod { + container := &pod.Spec.Containers[0] + for _, env := range otelinst.Spec.Env { + idx := getIndexOfEnv(container.Env, env.Name) + if idx == -1 && len(env.Value) > 0 { + container.Env = append(container.Env, corev1.EnvVar{ + Name: env.Name, + Value: env.Value, + }) + } } return pod } From d4efa35a50d14e0b41576dc7a036ab46ea2322f5 Mon Sep 17 00:00:00 2001 From: Duncan-tree-zhou Date: Thu, 20 Jan 2022 01:38:55 +0800 Subject: [PATCH 2/8] only env name start with "OTEL_" is allowed. --- apis/v1alpha1/instrumentation_webhook.go | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/apis/v1alpha1/instrumentation_webhook.go b/apis/v1alpha1/instrumentation_webhook.go index fd71daada2..7d982ea64e 100644 --- a/apis/v1alpha1/instrumentation_webhook.go +++ b/apis/v1alpha1/instrumentation_webhook.go @@ -17,6 +17,7 @@ package v1alpha1 import ( "fmt" "strconv" + "strings" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" @@ -28,6 +29,7 @@ const ( 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" + CustomizedEnvPrefix = "OTEL_" ) // log is for logging in this package. @@ -107,5 +109,31 @@ func (in *Instrumentation) validate() error { } case AlwaysOn, AlwaysOff, JaegerRemote, ParentBasedAlwaysOn, ParentBasedAlwaysOff, XRaySampler: } + + // validate customized environments + if err := in.validateEnv(in.Spec.Env); err != nil { + return err + } + if err := in.validateEnv(in.Spec.Java.Env); err != nil { + return err + } + if err := in.validateEnv(in.Spec.NodeJS.Env); err != nil { + return err + } + if err := in.validateEnv(in.Spec.Python.Env); err != nil { + return err + } + + return nil +} + +func (in *Instrumentation) validateEnv(envs []Env) error { + if len(envs) > 0 { + for _, env := range envs { + if !strings.HasPrefix(env.Name, CustomizedEnvPrefix) { + return fmt.Errorf("customized env name should start with \"OTEL_\": %s", env.Name) + } + } + } return nil } From b5e0cdf9e0e473ab5e628b6045155deda5342b80 Mon Sep 17 00:00:00 2001 From: Duncan-tree-zhou Date: Thu, 20 Jan 2022 01:46:11 +0800 Subject: [PATCH 3/8] deployment env > language spec customzied env > language spec config type> common customized env > common config type --- pkg/instrumentation/sdk.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/instrumentation/sdk.go b/pkg/instrumentation/sdk.go index c32313fcab..88ed74de20 100644 --- a/pkg/instrumentation/sdk.go +++ b/pkg/instrumentation/sdk.go @@ -66,22 +66,22 @@ func (i *sdkInjector) inject(ctx context.Context, insts languageInstrumentations if insts.Java != nil { otelinst := *insts.Java i.logger.V(1).Info("injecting java instrumentation into pod", "otelinst-namespace", otelinst.Namespace, "otelinst-name", otelinst.Name) - pod = i.injectCommonCustomizedEnv(otelinst, ns, pod) pod = injectJavaagent(i.logger, otelinst.Spec.Java, pod) + pod = i.injectCommonCustomizedEnv(otelinst, ns, pod) pod = i.injectCommonSDKConfig(ctx, otelinst, ns, pod) } if insts.NodeJS != nil { otelinst := *insts.NodeJS i.logger.V(1).Info("injecting nodejs instrumentation into pod", "otelinst-namespace", otelinst.Namespace, "otelinst-name", otelinst.Name) - pod = i.injectCommonCustomizedEnv(otelinst, ns, pod) pod = injectNodeJSSDK(i.logger, otelinst.Spec.NodeJS, pod) + pod = i.injectCommonCustomizedEnv(otelinst, ns, pod) pod = i.injectCommonSDKConfig(ctx, otelinst, ns, pod) } if insts.Python != nil { otelinst := *insts.Python i.logger.V(1).Info("injecting python instrumentation into pod", "otelinst-namespace", otelinst.Namespace, "otelinst-name", otelinst.Name) - pod = i.injectCommonCustomizedEnv(otelinst, ns, pod) pod = injectPythonSDK(i.logger, otelinst.Spec.Python, pod) + pod = i.injectCommonCustomizedEnv(otelinst, ns, pod) pod = i.injectCommonSDKConfig(ctx, otelinst, ns, pod) } return pod From fa8eb3dddce2d7ea670f23aea64c878284774e67 Mon Sep 17 00:00:00 2001 From: Duncan-tree-zhou Date: Thu, 20 Jan 2022 21:53:42 +0800 Subject: [PATCH 4/8] api docs gen and code fmt --- apis/v1alpha1/instrumentation_webhook.go | 2 +- apis/v1alpha1/zz_generated.deepcopy.go | 42 ++++- ...emetry-operator.clusterserviceversion.yaml | 2 +- .../opentelemetry.io_instrumentations.yaml | 60 +++++++ .../opentelemetry.io_instrumentations.yaml | 60 +++++++ config/manager/kustomization.yaml | 2 +- docs/api.md | 164 ++++++++++++++++++ 7 files changed, 325 insertions(+), 7 deletions(-) diff --git a/apis/v1alpha1/instrumentation_webhook.go b/apis/v1alpha1/instrumentation_webhook.go index 7d982ea64e..b06868126b 100644 --- a/apis/v1alpha1/instrumentation_webhook.go +++ b/apis/v1alpha1/instrumentation_webhook.go @@ -29,7 +29,7 @@ const ( 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" - CustomizedEnvPrefix = "OTEL_" + CustomizedEnvPrefix = "OTEL_" ) // log is for logging in this package. diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index 20b2a4e645..42228aef5d 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated // Copyright The OpenTelemetry Authors @@ -24,6 +23,21 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Env) DeepCopyInto(out *Env) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Env. +func (in *Env) DeepCopy() *Env { + if in == nil { + return nil + } + out := new(Env) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Exporter) DeepCopyInto(out *Exporter) { *out = *in @@ -109,9 +123,14 @@ func (in *InstrumentationSpec) DeepCopyInto(out *InstrumentationSpec) { copy(*out, *in) } out.Sampler = in.Sampler - out.Java = in.Java - out.NodeJS = in.NodeJS - out.Python = in.Python + if in.Env != nil { + in, out := &in.Env, &out.Env + *out = make([]Env, len(*in)) + copy(*out, *in) + } + in.Java.DeepCopyInto(&out.Java) + in.NodeJS.DeepCopyInto(&out.NodeJS) + in.Python.DeepCopyInto(&out.Python) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InstrumentationSpec. @@ -142,6 +161,11 @@ func (in *InstrumentationStatus) DeepCopy() *InstrumentationStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Java) DeepCopyInto(out *Java) { *out = *in + if in.Env != nil { + in, out := &in.Env, &out.Env + *out = make([]Env, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Java. @@ -157,6 +181,11 @@ func (in *Java) DeepCopy() *Java { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NodeJS) DeepCopyInto(out *NodeJS) { *out = *in + if in.Env != nil { + in, out := &in.Env, &out.Env + *out = make([]Env, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeJS. @@ -361,6 +390,11 @@ func (in *OpenTelemetryTargetAllocator) DeepCopy() *OpenTelemetryTargetAllocator // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Python) DeepCopyInto(out *Python) { *out = *in + if in.Env != nil { + in, out := &in.Env, &out.Env + *out = make([]Env, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Python. diff --git a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml index 18cbc85761..8c271570c5 100644 --- a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml +++ b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml @@ -265,7 +265,7 @@ spec: - args: - --metrics-addr=127.0.0.1:8080 - --enable-leader-election - image: ghcr.io/duncan/opentelemetry-operator/opentelemetry-operator:v0.42.0 + image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:v0.42.0 livenessProbe: httpGet: path: /healthz diff --git a/bundle/manifests/opentelemetry.io_instrumentations.yaml b/bundle/manifests/opentelemetry.io_instrumentations.yaml index aa70aabcd3..6d77d62447 100644 --- a/bundle/manifests/opentelemetry.io_instrumentations.yaml +++ b/bundle/manifests/opentelemetry.io_instrumentations.yaml @@ -42,6 +42,21 @@ spec: description: InstrumentationSpec defines the desired state of OpenTelemetry SDK and instrumentation. properties: + env: + description: Env defines customized environments. + items: + description: Env defines customized envs. + properties: + name: + description: Name defines environments name. + type: string + value: + description: Value defines environments value. + type: string + required: + - name + type: object + type: array exporter: description: Exporter defines exporter configuration. properties: @@ -52,6 +67,21 @@ spec: java: description: Java defines configuration for java auto-instrumentation. properties: + env: + description: Env defines customized environments. + items: + description: Env defines customized envs. + properties: + name: + description: Name defines environments name. + type: string + value: + description: Value defines environments value. + type: string + required: + - name + type: object + type: array image: description: Image is a container image with javaagent auto-instrumentation JAR. @@ -60,6 +90,21 @@ spec: nodejs: description: NodeJS defines configuration for nodejs auto-instrumentation. properties: + env: + description: Env defines customized environments. + items: + description: Env defines customized envs. + properties: + name: + description: Name defines environments name. + type: string + value: + description: Value defines environments value. + type: string + required: + - name + type: object + type: array image: description: Image is a container image with NodeJS SDK and auto-instrumentation. type: string @@ -83,6 +128,21 @@ spec: python: description: Python defines configuration for python auto-instrumentation. properties: + env: + description: Env defines customized environments. + items: + description: Env defines customized envs. + properties: + name: + description: Name defines environments name. + type: string + value: + description: Value defines environments value. + type: string + required: + - name + type: object + type: array image: description: Image is a container image with Python SDK and auto-instrumentation. type: string diff --git a/config/crd/bases/opentelemetry.io_instrumentations.yaml b/config/crd/bases/opentelemetry.io_instrumentations.yaml index 4626ce2c2a..36a98587c2 100644 --- a/config/crd/bases/opentelemetry.io_instrumentations.yaml +++ b/config/crd/bases/opentelemetry.io_instrumentations.yaml @@ -44,6 +44,21 @@ spec: description: InstrumentationSpec defines the desired state of OpenTelemetry SDK and instrumentation. properties: + env: + description: Env defines customized environments. + items: + description: Env defines customized envs. + properties: + name: + description: Name defines environments name. + type: string + value: + description: Value defines environments value. + type: string + required: + - name + type: object + type: array exporter: description: Exporter defines exporter configuration. properties: @@ -54,6 +69,21 @@ spec: java: description: Java defines configuration for java auto-instrumentation. properties: + env: + description: Env defines customized environments. + items: + description: Env defines customized envs. + properties: + name: + description: Name defines environments name. + type: string + value: + description: Value defines environments value. + type: string + required: + - name + type: object + type: array image: description: Image is a container image with javaagent auto-instrumentation JAR. @@ -62,6 +92,21 @@ spec: nodejs: description: NodeJS defines configuration for nodejs auto-instrumentation. properties: + env: + description: Env defines customized environments. + items: + description: Env defines customized envs. + properties: + name: + description: Name defines environments name. + type: string + value: + description: Value defines environments value. + type: string + required: + - name + type: object + type: array image: description: Image is a container image with NodeJS SDK and auto-instrumentation. type: string @@ -85,6 +130,21 @@ spec: python: description: Python defines configuration for python auto-instrumentation. properties: + env: + description: Env defines customized environments. + items: + description: Env defines customized envs. + properties: + name: + description: Name defines environments name. + type: string + value: + description: Value defines environments value. + type: string + required: + - name + type: object + type: array image: description: Image is a container image with Python SDK and auto-instrumentation. type: string diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index d24a8cf8ad..8f550ee5f4 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -5,4 +5,4 @@ kind: Kustomization images: - name: controller newName: ghcr.io/duncan/opentelemetry-operator/opentelemetry-operator - newTag: v0.42.0 + newTag: v0.42.0-3-gb5e0cdf diff --git a/docs/api.md b/docs/api.md index 0e756e3f9a..a626c75ae1 100644 --- a/docs/api.md +++ b/docs/api.md @@ -86,6 +86,13 @@ InstrumentationSpec defines the desired state of OpenTelemetry SDK and instrumen + env + []object + + Env defines customized environments.
+ + false + exporter object @@ -138,6 +145,40 @@ InstrumentationSpec defines the desired state of OpenTelemetry SDK and instrumen +### Instrumentation.spec.env[index] +[↩ Parent](#instrumentationspec) + + + +Env defines customized envs. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
namestring + Name defines environments name.
+
true
valuestring + Value defines environments value.
+
false
+ + ### Instrumentation.spec.exporter [↩ Parent](#instrumentationspec) @@ -182,6 +223,13 @@ Java defines configuration for java auto-instrumentation. + env + []object + + Env defines customized environments.
+ + false + image string @@ -192,6 +240,40 @@ Java defines configuration for java auto-instrumentation. +### Instrumentation.spec.java.env[index] +[↩ Parent](#instrumentationspecjava) + + + +Env defines customized envs. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
namestring + Name defines environments name.
+
true
valuestring + Value defines environments value.
+
false
+ + ### Instrumentation.spec.nodejs [↩ Parent](#instrumentationspec) @@ -209,6 +291,13 @@ NodeJS defines configuration for nodejs auto-instrumentation. + env + []object + + Env defines customized environments.
+ + false + image string @@ -219,6 +308,40 @@ NodeJS defines configuration for nodejs auto-instrumentation. +### Instrumentation.spec.nodejs.env[index] +[↩ Parent](#instrumentationspecnodejs) + + + +Env defines customized envs. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
namestring + Name defines environments name.
+
true
valuestring + Value defines environments value.
+
false
+ + ### Instrumentation.spec.python [↩ Parent](#instrumentationspec) @@ -236,6 +359,13 @@ Python defines configuration for python auto-instrumentation. + env + []object + + Env defines customized environments.
+ + false + image string @@ -246,6 +376,40 @@ Python defines configuration for python auto-instrumentation. +### Instrumentation.spec.python.env[index] +[↩ Parent](#instrumentationspecpython) + + + +Env defines customized envs. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
namestring + Name defines environments name.
+
true
valuestring + Value defines environments value.
+
false
+ + ### Instrumentation.spec.resource [↩ Parent](#instrumentationspec) From 34c36d3581356e8d3189e97be011de6ddc59a71e Mon Sep 17 00:00:00 2001 From: Duncan-tree-zhou Date: Tue, 25 Jan 2022 17:42:31 +0800 Subject: [PATCH 5/8] use corev1.EnvVar instead of Env --- apis/v1alpha1/instrumentation_types.go | 28 +- apis/v1alpha1/instrumentation_webhook.go | 11 +- apis/v1alpha1/zz_generated.deepcopy.go | 39 +- .../opentelemetry.io_instrumentations.yaml | 407 +++++++- config/manager/kustomization.yaml | 4 +- docs/api.md | 948 +++++++++++++++++- pkg/instrumentation/javaagent.go | 9 +- pkg/instrumentation/nodejs.go | 9 +- pkg/instrumentation/python.go | 9 +- pkg/instrumentation/sdk.go | 15 +- 10 files changed, 1338 insertions(+), 141 deletions(-) diff --git a/apis/v1alpha1/instrumentation_types.go b/apis/v1alpha1/instrumentation_types.go index 3e3006dcb2..37e2592546 100644 --- a/apis/v1alpha1/instrumentation_types.go +++ b/apis/v1alpha1/instrumentation_types.go @@ -15,6 +15,7 @@ package v1alpha1 import ( + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -36,8 +37,9 @@ type InstrumentationSpec struct { // +optional Sampler `json:"sampler,omitempty"` - // Env defines customized environments. - Env []Env `json:"env,omitempty"` + // Env defines env vars. + // +optional + Env []corev1.EnvVar `json:"env,omitempty"` // Java defines configuration for java auto-instrumentation. // +optional @@ -86,25 +88,15 @@ type Sampler struct { Argument string `json:"argument,omitempty"` } -// Env defines customized envs. -type Env struct { - // Name defines environments name. - Name string `json:"name"` - - // Value defines environments value. - // +optional - Value string `json:"value,omitempty"` -} - // Java defines Java SDK and instrumentation configuration. type Java struct { // Image is a container image with javaagent auto-instrumentation JAR. // +optional Image string `json:"image,omitempty"` - // Env defines customized environments. + // Env defines env vars. // +optional - Env []Env `json:"env,omitempty"` + Env []corev1.EnvVar `json:"env,omitempty"` } // NodeJS defines NodeJS SDK and instrumentation configuration. @@ -113,9 +105,9 @@ type NodeJS struct { // +optional Image string `json:"image,omitempty"` - // Env defines customized environments. + // Env defines env vars. // +optional - Env []Env `json:"env,omitempty"` + Env []corev1.EnvVar `json:"env,omitempty"` } // Python defines Python SDK and instrumentation configuration. @@ -124,9 +116,9 @@ type Python struct { // +optional Image string `json:"image,omitempty"` - // Env defines customized environments. + // Env defines env vars. // +optional - Env []Env `json:"env,omitempty"` + Env []corev1.EnvVar `json:"env,omitempty"` } // InstrumentationStatus defines status of the instrumentation. diff --git a/apis/v1alpha1/instrumentation_webhook.go b/apis/v1alpha1/instrumentation_webhook.go index b06868126b..ff884d409b 100644 --- a/apis/v1alpha1/instrumentation_webhook.go +++ b/apis/v1alpha1/instrumentation_webhook.go @@ -16,6 +16,7 @@ package v1alpha1 import ( "fmt" + corev1 "k8s.io/api/core/v1" "strconv" "strings" @@ -29,7 +30,7 @@ const ( 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" - CustomizedEnvPrefix = "OTEL_" + EnvPrefix = "OTEL_" ) // log is for logging in this package. @@ -110,7 +111,7 @@ func (in *Instrumentation) validate() error { case AlwaysOn, AlwaysOff, JaegerRemote, ParentBasedAlwaysOn, ParentBasedAlwaysOff, XRaySampler: } - // validate customized environments + // validate env vars if err := in.validateEnv(in.Spec.Env); err != nil { return err } @@ -127,11 +128,11 @@ func (in *Instrumentation) validate() error { return nil } -func (in *Instrumentation) validateEnv(envs []Env) error { +func (in *Instrumentation) validateEnv(envs []corev1.EnvVar) error { if len(envs) > 0 { for _, env := range envs { - if !strings.HasPrefix(env.Name, CustomizedEnvPrefix) { - return fmt.Errorf("customized env name should start with \"OTEL_\": %s", env.Name) + if !strings.HasPrefix(env.Name, EnvPrefix) { + return fmt.Errorf("env name should start with \"OTEL_\": %s", env.Name) } } } diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index 42228aef5d..d21b1f660a 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -23,21 +23,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Env) DeepCopyInto(out *Env) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Env. -func (in *Env) DeepCopy() *Env { - if in == nil { - return nil - } - out := new(Env) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Exporter) DeepCopyInto(out *Exporter) { *out = *in @@ -125,8 +110,10 @@ func (in *InstrumentationSpec) DeepCopyInto(out *InstrumentationSpec) { out.Sampler = in.Sampler if in.Env != nil { in, out := &in.Env, &out.Env - *out = make([]Env, len(*in)) - copy(*out, *in) + *out = make([]v1.EnvVar, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } in.Java.DeepCopyInto(&out.Java) in.NodeJS.DeepCopyInto(&out.NodeJS) @@ -163,8 +150,10 @@ func (in *Java) DeepCopyInto(out *Java) { *out = *in if in.Env != nil { in, out := &in.Env, &out.Env - *out = make([]Env, len(*in)) - copy(*out, *in) + *out = make([]v1.EnvVar, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } } @@ -183,8 +172,10 @@ func (in *NodeJS) DeepCopyInto(out *NodeJS) { *out = *in if in.Env != nil { in, out := &in.Env, &out.Env - *out = make([]Env, len(*in)) - copy(*out, *in) + *out = make([]v1.EnvVar, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } } @@ -392,8 +383,10 @@ func (in *Python) DeepCopyInto(out *Python) { *out = *in if in.Env != nil { in, out := &in.Env, &out.Env - *out = make([]Env, len(*in)) - copy(*out, *in) + *out = make([]v1.EnvVar, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } } diff --git a/config/crd/bases/opentelemetry.io_instrumentations.yaml b/config/crd/bases/opentelemetry.io_instrumentations.yaml index 36a98587c2..2a5789397e 100644 --- a/config/crd/bases/opentelemetry.io_instrumentations.yaml +++ b/config/crd/bases/opentelemetry.io_instrumentations.yaml @@ -45,16 +45,106 @@ spec: SDK and instrumentation. properties: env: - description: Env defines customized environments. + description: Env defines env vars. items: - description: Env defines customized envs. + description: EnvVar represents an environment variable present in + a Container. properties: name: - description: Name defines environments name. + description: Name of the environment variable. Must be a C_IDENTIFIER. type: string value: - description: Value defines environments value. + description: 'Variable references $(VAR_NAME) are expanded using + the previously defined environment variables in the container + and any service environment variables. If a variable cannot + be resolved, the reference in the input string will be unchanged. + Double $$ are reduced to a single $, which allows for escaping + the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce the + string literal "$(VAR_NAME)". Escaped references will never + be expanded, regardless of whether the variable exists or + not. Defaults to "".' type: string + valueFrom: + description: Source for the environment variable's value. Cannot + be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + optional: + description: Specify whether the ConfigMap or its key + must be defined + type: boolean + required: + - key + type: object + fieldRef: + description: 'Selects a field of the pod: supports metadata.name, + metadata.namespace, `metadata.labels['''']`, `metadata.annotations['''']`, + spec.nodeName, spec.serviceAccountName, status.hostIP, + status.podIP, status.podIPs.' + properties: + apiVersion: + description: Version of the schema the FieldPath is + written in terms of, defaults to "v1". + type: string + fieldPath: + description: Path of the field to select in the specified + API version. + type: string + required: + - fieldPath + type: object + resourceFieldRef: + description: 'Selects a resource of the container: only + resources limits and requests (limits.cpu, limits.memory, + limits.ephemeral-storage, requests.cpu, requests.memory + and requests.ephemeral-storage) are currently supported.' + properties: + containerName: + description: 'Container name: required for volumes, + optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format of the exposed + resources, defaults to "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + secretKeyRef: + description: Selects a key of a secret in the pod's namespace + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + optional: + description: Specify whether the Secret or its key must + be defined + type: boolean + required: + - key + type: object + type: object required: - name type: object @@ -70,16 +160,111 @@ spec: description: Java defines configuration for java auto-instrumentation. properties: env: - description: Env defines customized environments. + description: Env defines env vars. items: - description: Env defines customized envs. + description: EnvVar represents an environment variable present + in a Container. properties: name: - description: Name defines environments name. + description: Name of the environment variable. Must be a + C_IDENTIFIER. type: string value: - description: Value defines environments value. + description: 'Variable references $(VAR_NAME) are expanded + using the previously defined environment variables in + the container and any service environment variables. If + a variable cannot be resolved, the reference in the input + string will be unchanged. Double $$ are reduced to a single + $, which allows for escaping the $(VAR_NAME) syntax: i.e. + "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". + Escaped references will never be expanded, regardless + of whether the variable exists or not. Defaults to "".' type: string + valueFrom: + description: Source for the environment variable's value. + Cannot be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the ConfigMap or its + key must be defined + type: boolean + required: + - key + type: object + fieldRef: + description: 'Selects a field of the pod: supports metadata.name, + metadata.namespace, `metadata.labels['''']`, + `metadata.annotations['''']`, spec.nodeName, + spec.serviceAccountName, status.hostIP, status.podIP, + status.podIPs.' + properties: + apiVersion: + description: Version of the schema the FieldPath + is written in terms of, defaults to "v1". + type: string + fieldPath: + description: Path of the field to select in the + specified API version. + type: string + required: + - fieldPath + type: object + resourceFieldRef: + description: 'Selects a resource of the container: only + resources limits and requests (limits.cpu, limits.memory, + limits.ephemeral-storage, requests.cpu, requests.memory + and requests.ephemeral-storage) are currently supported.' + properties: + containerName: + description: 'Container name: required for volumes, + optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format of the + exposed resources, defaults to "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + secretKeyRef: + description: Selects a key of a secret in the pod's + namespace + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the Secret or its key + must be defined + type: boolean + required: + - key + type: object + type: object required: - name type: object @@ -93,16 +278,111 @@ spec: description: NodeJS defines configuration for nodejs auto-instrumentation. properties: env: - description: Env defines customized environments. + description: Env defines env vars. items: - description: Env defines customized envs. + description: EnvVar represents an environment variable present + in a Container. properties: name: - description: Name defines environments name. + description: Name of the environment variable. Must be a + C_IDENTIFIER. type: string value: - description: Value defines environments value. + description: 'Variable references $(VAR_NAME) are expanded + using the previously defined environment variables in + the container and any service environment variables. If + a variable cannot be resolved, the reference in the input + string will be unchanged. Double $$ are reduced to a single + $, which allows for escaping the $(VAR_NAME) syntax: i.e. + "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". + Escaped references will never be expanded, regardless + of whether the variable exists or not. Defaults to "".' type: string + valueFrom: + description: Source for the environment variable's value. + Cannot be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the ConfigMap or its + key must be defined + type: boolean + required: + - key + type: object + fieldRef: + description: 'Selects a field of the pod: supports metadata.name, + metadata.namespace, `metadata.labels['''']`, + `metadata.annotations['''']`, spec.nodeName, + spec.serviceAccountName, status.hostIP, status.podIP, + status.podIPs.' + properties: + apiVersion: + description: Version of the schema the FieldPath + is written in terms of, defaults to "v1". + type: string + fieldPath: + description: Path of the field to select in the + specified API version. + type: string + required: + - fieldPath + type: object + resourceFieldRef: + description: 'Selects a resource of the container: only + resources limits and requests (limits.cpu, limits.memory, + limits.ephemeral-storage, requests.cpu, requests.memory + and requests.ephemeral-storage) are currently supported.' + properties: + containerName: + description: 'Container name: required for volumes, + optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format of the + exposed resources, defaults to "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + secretKeyRef: + description: Selects a key of a secret in the pod's + namespace + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the Secret or its key + must be defined + type: boolean + required: + - key + type: object + type: object required: - name type: object @@ -131,16 +411,111 @@ spec: description: Python defines configuration for python auto-instrumentation. properties: env: - description: Env defines customized environments. + description: Env defines env vars. items: - description: Env defines customized envs. + description: EnvVar represents an environment variable present + in a Container. properties: name: - description: Name defines environments name. + description: Name of the environment variable. Must be a + C_IDENTIFIER. type: string value: - description: Value defines environments value. + description: 'Variable references $(VAR_NAME) are expanded + using the previously defined environment variables in + the container and any service environment variables. If + a variable cannot be resolved, the reference in the input + string will be unchanged. Double $$ are reduced to a single + $, which allows for escaping the $(VAR_NAME) syntax: i.e. + "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". + Escaped references will never be expanded, regardless + of whether the variable exists or not. Defaults to "".' type: string + valueFrom: + description: Source for the environment variable's value. + Cannot be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the ConfigMap or its + key must be defined + type: boolean + required: + - key + type: object + fieldRef: + description: 'Selects a field of the pod: supports metadata.name, + metadata.namespace, `metadata.labels['''']`, + `metadata.annotations['''']`, spec.nodeName, + spec.serviceAccountName, status.hostIP, status.podIP, + status.podIPs.' + properties: + apiVersion: + description: Version of the schema the FieldPath + is written in terms of, defaults to "v1". + type: string + fieldPath: + description: Path of the field to select in the + specified API version. + type: string + required: + - fieldPath + type: object + resourceFieldRef: + description: 'Selects a resource of the container: only + resources limits and requests (limits.cpu, limits.memory, + limits.ephemeral-storage, requests.cpu, requests.memory + and requests.ephemeral-storage) are currently supported.' + properties: + containerName: + description: 'Container name: required for volumes, + optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format of the + exposed resources, defaults to "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + secretKeyRef: + description: Selects a key of a secret in the pod's + namespace + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the Secret or its key + must be defined + type: boolean + required: + - key + type: object + type: object required: - name type: object diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 8f550ee5f4..46c1861f30 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization images: - name: controller - newName: ghcr.io/duncan/opentelemetry-operator/opentelemetry-operator - newTag: v0.42.0-3-gb5e0cdf + newName: local/opentelemetry-operator + newTag: e2e diff --git a/docs/api.md b/docs/api.md index a626c75ae1..9d35c0bce8 100644 --- a/docs/api.md +++ b/docs/api.md @@ -89,7 +89,7 @@ InstrumentationSpec defines the desired state of OpenTelemetry SDK and instrumen env []object - Env defines customized environments.
+ Env defines env vars.
false @@ -150,7 +150,7 @@ InstrumentationSpec defines the desired state of OpenTelemetry SDK and instrumen -Env defines customized envs. +EnvVar represents an environment variable present in a Container. @@ -165,26 +165,33 @@ Env defines customized envs. + + + + +
name string - Name defines environments name.
+ Name of the environment variable. Must be a C_IDENTIFIER.
true
value string - Value defines environments value.
+ Variable references $(VAR_NAME) are expanded using the previously defined environment variables in the container and any service environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless of whether the variable exists or not. Defaults to "".
+
false
valueFromobject + Source for the environment variable's value. Cannot be used if value is not empty.
false
-### Instrumentation.spec.exporter -[↩ Parent](#instrumentationspec) +### Instrumentation.spec.env[index].valueFrom +[↩ Parent](#instrumentationspecenvindex) -Exporter defines exporter configuration. +Source for the environment variable's value. Cannot be used if value is not empty. @@ -196,22 +203,84 @@ Exporter defines exporter configuration. - + + + + + + + + + + + + + + + + + + + + +
endpointconfigMapKeyRefobject + Selects a key of a ConfigMap.
+
false
fieldRefobject + Selects a field of the pod: supports metadata.name, metadata.namespace, `metadata.labels['']`, `metadata.annotations['']`, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs.
+
false
resourceFieldRefobject + Selects a resource of the container: only resources limits and requests (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported.
+
false
secretKeyRefobject + Selects a key of a secret in the pod's namespace
+
false
+ + +### Instrumentation.spec.env[index].valueFrom.configMapKeyRef +[↩ Parent](#instrumentationspecenvindexvaluefrom) + + + +Selects a key of a ConfigMap. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
key string - Endpoint is address of the collector with OTLP endpoint.
+ The key to select.
+
true
namestring + Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?
+
false
optionalboolean + Specify whether the ConfigMap or its key must be defined
false
-### Instrumentation.spec.java -[↩ Parent](#instrumentationspec) +### Instrumentation.spec.env[index].valueFrom.fieldRef +[↩ Parent](#instrumentationspecenvindexvaluefrom) -Java defines configuration for java auto-instrumentation. +Selects a field of the pod: supports metadata.name, metadata.namespace, `metadata.labels['']`, `metadata.annotations['']`, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs. @@ -223,29 +292,70 @@ Java defines configuration for java auto-instrumentation. - - + + + + + + + + +
env[]objectfieldPathstring + Path of the field to select in the specified API version.
+
true
apiVersionstring - Env defines customized environments.
+ Version of the schema the FieldPath is written in terms of, defaults to "v1".
false
+ + +### Instrumentation.spec.env[index].valueFrom.resourceFieldRef +[↩ Parent](#instrumentationspecenvindexvaluefrom) + + + +Selects a resource of the container: only resources limits and requests (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported. + + + + + + + + + + + + + + + - + + + + + +
NameTypeDescriptionRequired
resourcestring + Required: resource to select
+
true
imagecontainerName string - Image is a container image with javaagent auto-instrumentation JAR.
+ Container name: required for volumes, optional for env vars
+
false
divisorint or string + Specifies the output format of the exposed resources, defaults to "1"
false
-### Instrumentation.spec.java.env[index] -[↩ Parent](#instrumentationspecjava) +### Instrumentation.spec.env[index].valueFrom.secretKeyRef +[↩ Parent](#instrumentationspecenvindexvaluefrom) -Env defines customized envs. +Selects a key of a secret in the pod's namespace @@ -257,29 +367,36 @@ Env defines customized envs. - + - + + + + + +
namekey string - Name defines environments name.
+ The key of the secret to select from. Must be a valid secret key.
true
valuename string - Value defines environments value.
+ Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?
+
false
optionalboolean + Specify whether the Secret or its key must be defined
false
-### Instrumentation.spec.nodejs +### Instrumentation.spec.exporter [↩ Parent](#instrumentationspec) -NodeJS defines configuration for nodejs auto-instrumentation. +Exporter defines exporter configuration. @@ -291,29 +408,56 @@ NodeJS defines configuration for nodejs auto-instrumentation. - + + + + + +
envendpointstring + Endpoint is address of the collector with OTLP endpoint.
+
false
+ + +### Instrumentation.spec.java +[↩ Parent](#instrumentationspec) + + + +Java defines configuration for java auto-instrumentation. + + + + + + + + + + + +
NameTypeDescriptionRequired
env []object - Env defines customized environments.
+ Env defines env vars.
false
image string - Image is a container image with NodeJS SDK and auto-instrumentation.
+ Image is a container image with javaagent auto-instrumentation JAR.
false
-### Instrumentation.spec.nodejs.env[index] -[↩ Parent](#instrumentationspecnodejs) +### Instrumentation.spec.java.env[index] +[↩ Parent](#instrumentationspecjava) -Env defines customized envs. +EnvVar represents an environment variable present in a Container. @@ -328,26 +472,33 @@ Env defines customized envs. + + + + +
name string - Name defines environments name.
+ Name of the environment variable. Must be a C_IDENTIFIER.
true
value string - Value defines environments value.
+ Variable references $(VAR_NAME) are expanded using the previously defined environment variables in the container and any service environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless of whether the variable exists or not. Defaults to "".
+
false
valueFromobject + Source for the environment variable's value. Cannot be used if value is not empty.
false
-### Instrumentation.spec.python -[↩ Parent](#instrumentationspec) +### Instrumentation.spec.java.env[index].valueFrom +[↩ Parent](#instrumentationspecjavaenvindex) -Python defines configuration for python auto-instrumentation. +Source for the environment variable's value. Cannot be used if value is not empty. @@ -359,29 +510,43 @@ Python defines configuration for python auto-instrumentation. - - + + - - + + + + + + + + + + + +
env[]objectconfigMapKeyRefobject - Env defines customized environments.
+ Selects a key of a ConfigMap.
false
imagestringfieldRefobject - Image is a container image with Python SDK and auto-instrumentation.
+ Selects a field of the pod: supports metadata.name, metadata.namespace, `metadata.labels['']`, `metadata.annotations['']`, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs.
+
false
resourceFieldRefobject + Selects a resource of the container: only resources limits and requests (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported.
+
false
secretKeyRefobject + Selects a key of a secret in the pod's namespace
false
-### Instrumentation.spec.python.env[index] -[↩ Parent](#instrumentationspecpython) +### Instrumentation.spec.java.env[index].valueFrom.configMapKeyRef +[↩ Parent](#instrumentationspecjavaenvindexvaluefrom) -Env defines customized envs. +Selects a key of a ConfigMap. @@ -393,17 +558,700 @@ Env defines customized envs. - + - + + + + + + + + + + +
namekey string - Name defines environments name.
+ The key to select.
true
valuenamestring + Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?
+
false
optionalboolean + Specify whether the ConfigMap or its key must be defined
+
false
+ + +### Instrumentation.spec.java.env[index].valueFrom.fieldRef +[↩ Parent](#instrumentationspecjavaenvindexvaluefrom) + + + +Selects a field of the pod: supports metadata.name, metadata.namespace, `metadata.labels['']`, `metadata.annotations['']`, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs. + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
fieldPath string - Value defines environments value.
+ Path of the field to select in the specified API version.
+
true
apiVersionstring + Version of the schema the FieldPath is written in terms of, defaults to "v1".
+
false
+ + +### Instrumentation.spec.java.env[index].valueFrom.resourceFieldRef +[↩ Parent](#instrumentationspecjavaenvindexvaluefrom) + + + +Selects a resource of the container: only resources limits and requests (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported. + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
resourcestring + Required: resource to select
+
true
containerNamestring + Container name: required for volumes, optional for env vars
+
false
divisorint or string + Specifies the output format of the exposed resources, defaults to "1"
+
false
+ + +### Instrumentation.spec.java.env[index].valueFrom.secretKeyRef +[↩ Parent](#instrumentationspecjavaenvindexvaluefrom) + + + +Selects a key of a secret in the pod's namespace + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
keystring + The key of the secret to select from. Must be a valid secret key.
+
true
namestring + Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?
+
false
optionalboolean + Specify whether the Secret or its key must be defined
+
false
+ + +### Instrumentation.spec.nodejs +[↩ Parent](#instrumentationspec) + + + +NodeJS defines configuration for nodejs auto-instrumentation. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
env[]object + Env defines env vars.
+
false
imagestring + Image is a container image with NodeJS SDK and auto-instrumentation.
+
false
+ + +### Instrumentation.spec.nodejs.env[index] +[↩ Parent](#instrumentationspecnodejs) + + + +EnvVar represents an environment variable present in a Container. + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
namestring + Name of the environment variable. Must be a C_IDENTIFIER.
+
true
valuestring + Variable references $(VAR_NAME) are expanded using the previously defined environment variables in the container and any service environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless of whether the variable exists or not. Defaults to "".
+
false
valueFromobject + Source for the environment variable's value. Cannot be used if value is not empty.
+
false
+ + +### Instrumentation.spec.nodejs.env[index].valueFrom +[↩ Parent](#instrumentationspecnodejsenvindex) + + + +Source for the environment variable's value. Cannot be used if value is not empty. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
configMapKeyRefobject + Selects a key of a ConfigMap.
+
false
fieldRefobject + Selects a field of the pod: supports metadata.name, metadata.namespace, `metadata.labels['']`, `metadata.annotations['']`, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs.
+
false
resourceFieldRefobject + Selects a resource of the container: only resources limits and requests (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported.
+
false
secretKeyRefobject + Selects a key of a secret in the pod's namespace
+
false
+ + +### Instrumentation.spec.nodejs.env[index].valueFrom.configMapKeyRef +[↩ Parent](#instrumentationspecnodejsenvindexvaluefrom) + + + +Selects a key of a ConfigMap. + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
keystring + The key to select.
+
true
namestring + Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?
+
false
optionalboolean + Specify whether the ConfigMap or its key must be defined
+
false
+ + +### Instrumentation.spec.nodejs.env[index].valueFrom.fieldRef +[↩ Parent](#instrumentationspecnodejsenvindexvaluefrom) + + + +Selects a field of the pod: supports metadata.name, metadata.namespace, `metadata.labels['']`, `metadata.annotations['']`, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
fieldPathstring + Path of the field to select in the specified API version.
+
true
apiVersionstring + Version of the schema the FieldPath is written in terms of, defaults to "v1".
+
false
+ + +### Instrumentation.spec.nodejs.env[index].valueFrom.resourceFieldRef +[↩ Parent](#instrumentationspecnodejsenvindexvaluefrom) + + + +Selects a resource of the container: only resources limits and requests (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported. + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
resourcestring + Required: resource to select
+
true
containerNamestring + Container name: required for volumes, optional for env vars
+
false
divisorint or string + Specifies the output format of the exposed resources, defaults to "1"
+
false
+ + +### Instrumentation.spec.nodejs.env[index].valueFrom.secretKeyRef +[↩ Parent](#instrumentationspecnodejsenvindexvaluefrom) + + + +Selects a key of a secret in the pod's namespace + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
keystring + The key of the secret to select from. Must be a valid secret key.
+
true
namestring + Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?
+
false
optionalboolean + Specify whether the Secret or its key must be defined
+
false
+ + +### Instrumentation.spec.python +[↩ Parent](#instrumentationspec) + + + +Python defines configuration for python auto-instrumentation. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
env[]object + Env defines env vars.
+
false
imagestring + Image is a container image with Python SDK and auto-instrumentation.
+
false
+ + +### Instrumentation.spec.python.env[index] +[↩ Parent](#instrumentationspecpython) + + + +EnvVar represents an environment variable present in a Container. + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
namestring + Name of the environment variable. Must be a C_IDENTIFIER.
+
true
valuestring + Variable references $(VAR_NAME) are expanded using the previously defined environment variables in the container and any service environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. Double $$ are reduced to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". Escaped references will never be expanded, regardless of whether the variable exists or not. Defaults to "".
+
false
valueFromobject + Source for the environment variable's value. Cannot be used if value is not empty.
+
false
+ + +### Instrumentation.spec.python.env[index].valueFrom +[↩ Parent](#instrumentationspecpythonenvindex) + + + +Source for the environment variable's value. Cannot be used if value is not empty. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
configMapKeyRefobject + Selects a key of a ConfigMap.
+
false
fieldRefobject + Selects a field of the pod: supports metadata.name, metadata.namespace, `metadata.labels['']`, `metadata.annotations['']`, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs.
+
false
resourceFieldRefobject + Selects a resource of the container: only resources limits and requests (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported.
+
false
secretKeyRefobject + Selects a key of a secret in the pod's namespace
+
false
+ + +### Instrumentation.spec.python.env[index].valueFrom.configMapKeyRef +[↩ Parent](#instrumentationspecpythonenvindexvaluefrom) + + + +Selects a key of a ConfigMap. + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
keystring + The key to select.
+
true
namestring + Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?
+
false
optionalboolean + Specify whether the ConfigMap or its key must be defined
+
false
+ + +### Instrumentation.spec.python.env[index].valueFrom.fieldRef +[↩ Parent](#instrumentationspecpythonenvindexvaluefrom) + + + +Selects a field of the pod: supports metadata.name, metadata.namespace, `metadata.labels['']`, `metadata.annotations['']`, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs. + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
fieldPathstring + Path of the field to select in the specified API version.
+
true
apiVersionstring + Version of the schema the FieldPath is written in terms of, defaults to "v1".
+
false
+ + +### Instrumentation.spec.python.env[index].valueFrom.resourceFieldRef +[↩ Parent](#instrumentationspecpythonenvindexvaluefrom) + + + +Selects a resource of the container: only resources limits and requests (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported. + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
resourcestring + Required: resource to select
+
true
containerNamestring + Container name: required for volumes, optional for env vars
+
false
divisorint or string + Specifies the output format of the exposed resources, defaults to "1"
+
false
+ + +### Instrumentation.spec.python.env[index].valueFrom.secretKeyRef +[↩ Parent](#instrumentationspecpythonenvindexvaluefrom) + + + +Selects a key of a secret in the pod's namespace + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pkg/instrumentation/javaagent.go b/pkg/instrumentation/javaagent.go index 7a1ccfa38e..aba5501100 100644 --- a/pkg/instrumentation/javaagent.go +++ b/pkg/instrumentation/javaagent.go @@ -30,14 +30,11 @@ func injectJavaagent(logger logr.Logger, javaSpec v1alpha1.Java, pod corev1.Pod) // caller checks if there is at least one container container := &pod.Spec.Containers[0] - // inject customized environments + // inject env vars for _, env := range javaSpec.Env { idx := getIndexOfEnv(container.Env, env.Name) - if idx == -1 && len(env.Value) > 0 { - container.Env = append(container.Env, corev1.EnvVar{ - Name: env.Name, - Value: env.Value, - }) + if idx == -1 { + container.Env = append(container.Env, env) } } diff --git a/pkg/instrumentation/nodejs.go b/pkg/instrumentation/nodejs.go index f7beaeb1a9..810866a0af 100644 --- a/pkg/instrumentation/nodejs.go +++ b/pkg/instrumentation/nodejs.go @@ -30,14 +30,11 @@ func injectNodeJSSDK(logger logr.Logger, nodeJSSpec v1alpha1.NodeJS, pod corev1. // caller checks if there is at least one container container := &pod.Spec.Containers[0] - // inject customized environments + // inject env vars for _, env := range nodeJSSpec.Env { idx := getIndexOfEnv(container.Env, env.Name) - if idx == -1 && len(env.Value) > 0 { - container.Env = append(container.Env, corev1.EnvVar{ - Name: env.Name, - Value: env.Value, - }) + if idx == -1 { + container.Env = append(container.Env, env) } } diff --git a/pkg/instrumentation/python.go b/pkg/instrumentation/python.go index 4a946d8288..d6ebdddb97 100644 --- a/pkg/instrumentation/python.go +++ b/pkg/instrumentation/python.go @@ -34,14 +34,11 @@ func injectPythonSDK(logger logr.Logger, pythonSpec v1alpha1.Python, pod corev1. // caller checks if there is at least one container container := &pod.Spec.Containers[0] - // inject customized environments + // inject env vars for _, env := range pythonSpec.Env { idx := getIndexOfEnv(container.Env, env.Name) - if idx == -1 && len(env.Value) > 0 { - container.Env = append(container.Env, corev1.EnvVar{ - Name: env.Name, - Value: env.Value, - }) + if idx == -1 { + container.Env = append(container.Env, env) } } diff --git a/pkg/instrumentation/sdk.go b/pkg/instrumentation/sdk.go index 88ed74de20..f8cfb1e55b 100644 --- a/pkg/instrumentation/sdk.go +++ b/pkg/instrumentation/sdk.go @@ -67,35 +67,32 @@ func (i *sdkInjector) inject(ctx context.Context, insts languageInstrumentations otelinst := *insts.Java i.logger.V(1).Info("injecting java instrumentation into pod", "otelinst-namespace", otelinst.Namespace, "otelinst-name", otelinst.Name) pod = injectJavaagent(i.logger, otelinst.Spec.Java, pod) - pod = i.injectCommonCustomizedEnv(otelinst, ns, pod) + pod = i.injectCommonEnvVar(otelinst, ns, pod) pod = i.injectCommonSDKConfig(ctx, otelinst, ns, pod) } if insts.NodeJS != nil { otelinst := *insts.NodeJS i.logger.V(1).Info("injecting nodejs instrumentation into pod", "otelinst-namespace", otelinst.Namespace, "otelinst-name", otelinst.Name) pod = injectNodeJSSDK(i.logger, otelinst.Spec.NodeJS, pod) - pod = i.injectCommonCustomizedEnv(otelinst, ns, pod) + pod = i.injectCommonEnvVar(otelinst, ns, pod) pod = i.injectCommonSDKConfig(ctx, otelinst, ns, pod) } if insts.Python != nil { otelinst := *insts.Python i.logger.V(1).Info("injecting python instrumentation into pod", "otelinst-namespace", otelinst.Namespace, "otelinst-name", otelinst.Name) pod = injectPythonSDK(i.logger, otelinst.Spec.Python, pod) - pod = i.injectCommonCustomizedEnv(otelinst, ns, pod) + pod = i.injectCommonEnvVar(otelinst, ns, pod) pod = i.injectCommonSDKConfig(ctx, otelinst, ns, pod) } return pod } -func (i *sdkInjector) injectCommonCustomizedEnv(otelinst v1alpha1.Instrumentation, ns corev1.Namespace, pod corev1.Pod) corev1.Pod { +func (i *sdkInjector) injectCommonEnvVar(otelinst v1alpha1.Instrumentation, ns corev1.Namespace, pod corev1.Pod) corev1.Pod { container := &pod.Spec.Containers[0] for _, env := range otelinst.Spec.Env { idx := getIndexOfEnv(container.Env, env.Name) - if idx == -1 && len(env.Value) > 0 { - container.Env = append(container.Env, corev1.EnvVar{ - Name: env.Name, - Value: env.Value, - }) + if idx == -1 { + container.Env = append(container.Env, env) } } return pod From dadd4daf638ece6d42593fde0a5a47434976bac1 Mon Sep 17 00:00:00 2001 From: Duncan-tree-zhou Date: Tue, 25 Jan 2022 19:36:04 +0800 Subject: [PATCH 6/8] fixing wrong change. --- apis/v1alpha1/instrumentation_webhook.go | 4 +- bundle.Dockerfile | 2 +- ...emetry-operator.clusterserviceversion.yaml | 68 +-- .../opentelemetry.io_instrumentations.yaml | 407 +++++++++++++++++- bundle/metadata/annotations.yaml | 2 +- config/manager/kustomization.yaml | 8 +- pkg/instrumentation/sdk.go | 8 +- 7 files changed, 434 insertions(+), 65 deletions(-) diff --git a/apis/v1alpha1/instrumentation_webhook.go b/apis/v1alpha1/instrumentation_webhook.go index ff884d409b..800e8d1781 100644 --- a/apis/v1alpha1/instrumentation_webhook.go +++ b/apis/v1alpha1/instrumentation_webhook.go @@ -30,7 +30,7 @@ const ( 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" - EnvPrefix = "OTEL_" + envPrefix = "OTEL_" ) // log is for logging in this package. @@ -131,7 +131,7 @@ func (in *Instrumentation) validate() error { func (in *Instrumentation) validateEnv(envs []corev1.EnvVar) error { if len(envs) > 0 { for _, env := range envs { - if !strings.HasPrefix(env.Name, EnvPrefix) { + if !strings.HasPrefix(env.Name, envPrefix) { return fmt.Errorf("env name should start with \"OTEL_\": %s", env.Name) } } diff --git a/bundle.Dockerfile b/bundle.Dockerfile index e9e88cc4e5..7996432a7e 100644 --- a/bundle.Dockerfile +++ b/bundle.Dockerfile @@ -6,7 +6,7 @@ LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/ LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ LABEL operators.operatorframework.io.bundle.package.v1=opentelemetry-operator LABEL operators.operatorframework.io.bundle.channels.v1=alpha -LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.16.0 +LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.13.0+git LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1 LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3 diff --git a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml index 8c271570c5..2882f81592 100644 --- a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml +++ b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml @@ -33,7 +33,7 @@ metadata: containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator createdAt: "2020-12-16T13:37:00+00:00" description: Provides the OpenTelemetry components, including the Collector - operators.operatorframework.io/builder: operator-sdk-v1.16.0 + operators.operatorframework.io/builder: operator-sdk-v1.13.0+git operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 repository: github.com/open-telemetry/opentelemetry-operator support: OpenTelemetry Community @@ -376,29 +376,29 @@ spec: - v1beta1 containerPort: 443 deploymentName: opentelemetry-operator-controller-manager - failurePolicy: Fail - generateName: minstrumentation.kb.io + failurePolicy: Ignore + generateName: mpod.kb.io rules: - apiGroups: - - opentelemetry.io + - "" apiVersions: - - v1alpha1 + - v1 operations: - CREATE - UPDATE resources: - - instrumentations + - pods sideEffects: None targetPort: 9443 type: MutatingAdmissionWebhook - webhookPath: /mutate-opentelemetry-io-v1alpha1-instrumentation + webhookPath: /mutate-v1-pod - admissionReviewVersions: - v1 - v1beta1 containerPort: 443 deploymentName: opentelemetry-operator-controller-manager failurePolicy: Fail - generateName: mopentelemetrycollector.kb.io + generateName: minstrumentation.kb.io rules: - apiGroups: - opentelemetry.io @@ -408,47 +408,46 @@ spec: - CREATE - UPDATE resources: - - opentelemetrycollectors + - instrumentations sideEffects: None targetPort: 9443 type: MutatingAdmissionWebhook - webhookPath: /mutate-opentelemetry-io-v1alpha1-opentelemetrycollector + webhookPath: /mutate-opentelemetry-io-v1alpha1-instrumentation - admissionReviewVersions: - v1 - v1beta1 containerPort: 443 deploymentName: opentelemetry-operator-controller-manager - failurePolicy: Ignore - generateName: mpod.kb.io + failurePolicy: Fail + generateName: mopentelemetrycollector.kb.io rules: - apiGroups: - - "" + - opentelemetry.io apiVersions: - - v1 + - v1alpha1 operations: - CREATE - UPDATE resources: - - pods + - opentelemetrycollectors sideEffects: None targetPort: 9443 type: MutatingAdmissionWebhook - webhookPath: /mutate-v1-pod + webhookPath: /mutate-opentelemetry-io-v1alpha1-opentelemetrycollector - admissionReviewVersions: - v1 - v1beta1 containerPort: 443 deploymentName: opentelemetry-operator-controller-manager - failurePolicy: Fail - generateName: vinstrumentationcreateupdate.kb.io + failurePolicy: Ignore + generateName: vinstrumentationdelete.kb.io rules: - apiGroups: - opentelemetry.io apiVersions: - v1alpha1 operations: - - CREATE - - UPDATE + - DELETE resources: - instrumentations sideEffects: None @@ -460,36 +459,36 @@ spec: - v1beta1 containerPort: 443 deploymentName: opentelemetry-operator-controller-manager - failurePolicy: Ignore - generateName: vinstrumentationdelete.kb.io + failurePolicy: Fail + generateName: vopentelemetrycollectorcreateupdate.kb.io rules: - apiGroups: - opentelemetry.io apiVersions: - v1alpha1 operations: - - DELETE + - CREATE + - UPDATE resources: - - instrumentations + - opentelemetrycollectors sideEffects: None targetPort: 9443 type: ValidatingAdmissionWebhook - webhookPath: /validate-opentelemetry-io-v1alpha1-instrumentation + webhookPath: /validate-opentelemetry-io-v1alpha1-opentelemetrycollector - admissionReviewVersions: - v1 - v1beta1 containerPort: 443 deploymentName: opentelemetry-operator-controller-manager - failurePolicy: Fail - generateName: vopentelemetrycollectorcreateupdate.kb.io + failurePolicy: Ignore + generateName: vopentelemetrycollectordelete.kb.io rules: - apiGroups: - opentelemetry.io apiVersions: - v1alpha1 operations: - - CREATE - - UPDATE + - DELETE resources: - opentelemetrycollectors sideEffects: None @@ -501,18 +500,19 @@ spec: - v1beta1 containerPort: 443 deploymentName: opentelemetry-operator-controller-manager - failurePolicy: Ignore - generateName: vopentelemetrycollectordelete.kb.io + failurePolicy: Fail + generateName: vinstrumentationcreateupdate.kb.io rules: - apiGroups: - opentelemetry.io apiVersions: - v1alpha1 operations: - - DELETE + - CREATE + - UPDATE resources: - - opentelemetrycollectors + - instrumentations sideEffects: None targetPort: 9443 type: ValidatingAdmissionWebhook - webhookPath: /validate-opentelemetry-io-v1alpha1-opentelemetrycollector + webhookPath: /validate-opentelemetry-io-v1alpha1-instrumentation diff --git a/bundle/manifests/opentelemetry.io_instrumentations.yaml b/bundle/manifests/opentelemetry.io_instrumentations.yaml index 6d77d62447..7b513cae68 100644 --- a/bundle/manifests/opentelemetry.io_instrumentations.yaml +++ b/bundle/manifests/opentelemetry.io_instrumentations.yaml @@ -43,16 +43,106 @@ spec: SDK and instrumentation. properties: env: - description: Env defines customized environments. + description: Env defines env vars. items: - description: Env defines customized envs. + description: EnvVar represents an environment variable present in + a Container. properties: name: - description: Name defines environments name. + description: Name of the environment variable. Must be a C_IDENTIFIER. type: string value: - description: Value defines environments value. + description: 'Variable references $(VAR_NAME) are expanded using + the previously defined environment variables in the container + and any service environment variables. If a variable cannot + be resolved, the reference in the input string will be unchanged. + Double $$ are reduced to a single $, which allows for escaping + the $(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce the + string literal "$(VAR_NAME)". Escaped references will never + be expanded, regardless of whether the variable exists or + not. Defaults to "".' type: string + valueFrom: + description: Source for the environment variable's value. Cannot + be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + optional: + description: Specify whether the ConfigMap or its key + must be defined + type: boolean + required: + - key + type: object + fieldRef: + description: 'Selects a field of the pod: supports metadata.name, + metadata.namespace, `metadata.labels['''']`, `metadata.annotations['''']`, + spec.nodeName, spec.serviceAccountName, status.hostIP, + status.podIP, status.podIPs.' + properties: + apiVersion: + description: Version of the schema the FieldPath is + written in terms of, defaults to "v1". + type: string + fieldPath: + description: Path of the field to select in the specified + API version. + type: string + required: + - fieldPath + type: object + resourceFieldRef: + description: 'Selects a resource of the container: only + resources limits and requests (limits.cpu, limits.memory, + limits.ephemeral-storage, requests.cpu, requests.memory + and requests.ephemeral-storage) are currently supported.' + properties: + containerName: + description: 'Container name: required for volumes, + optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format of the exposed + resources, defaults to "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + secretKeyRef: + description: Selects a key of a secret in the pod's namespace + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + optional: + description: Specify whether the Secret or its key must + be defined + type: boolean + required: + - key + type: object + type: object required: - name type: object @@ -68,16 +158,111 @@ spec: description: Java defines configuration for java auto-instrumentation. properties: env: - description: Env defines customized environments. + description: Env defines env vars. items: - description: Env defines customized envs. + description: EnvVar represents an environment variable present + in a Container. properties: name: - description: Name defines environments name. + description: Name of the environment variable. Must be a + C_IDENTIFIER. type: string value: - description: Value defines environments value. + description: 'Variable references $(VAR_NAME) are expanded + using the previously defined environment variables in + the container and any service environment variables. If + a variable cannot be resolved, the reference in the input + string will be unchanged. Double $$ are reduced to a single + $, which allows for escaping the $(VAR_NAME) syntax: i.e. + "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". + Escaped references will never be expanded, regardless + of whether the variable exists or not. Defaults to "".' type: string + valueFrom: + description: Source for the environment variable's value. + Cannot be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the ConfigMap or its + key must be defined + type: boolean + required: + - key + type: object + fieldRef: + description: 'Selects a field of the pod: supports metadata.name, + metadata.namespace, `metadata.labels['''']`, + `metadata.annotations['''']`, spec.nodeName, + spec.serviceAccountName, status.hostIP, status.podIP, + status.podIPs.' + properties: + apiVersion: + description: Version of the schema the FieldPath + is written in terms of, defaults to "v1". + type: string + fieldPath: + description: Path of the field to select in the + specified API version. + type: string + required: + - fieldPath + type: object + resourceFieldRef: + description: 'Selects a resource of the container: only + resources limits and requests (limits.cpu, limits.memory, + limits.ephemeral-storage, requests.cpu, requests.memory + and requests.ephemeral-storage) are currently supported.' + properties: + containerName: + description: 'Container name: required for volumes, + optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format of the + exposed resources, defaults to "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + secretKeyRef: + description: Selects a key of a secret in the pod's + namespace + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the Secret or its key + must be defined + type: boolean + required: + - key + type: object + type: object required: - name type: object @@ -91,16 +276,111 @@ spec: description: NodeJS defines configuration for nodejs auto-instrumentation. properties: env: - description: Env defines customized environments. + description: Env defines env vars. items: - description: Env defines customized envs. + description: EnvVar represents an environment variable present + in a Container. properties: name: - description: Name defines environments name. + description: Name of the environment variable. Must be a + C_IDENTIFIER. type: string value: - description: Value defines environments value. + description: 'Variable references $(VAR_NAME) are expanded + using the previously defined environment variables in + the container and any service environment variables. If + a variable cannot be resolved, the reference in the input + string will be unchanged. Double $$ are reduced to a single + $, which allows for escaping the $(VAR_NAME) syntax: i.e. + "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". + Escaped references will never be expanded, regardless + of whether the variable exists or not. Defaults to "".' type: string + valueFrom: + description: Source for the environment variable's value. + Cannot be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the ConfigMap or its + key must be defined + type: boolean + required: + - key + type: object + fieldRef: + description: 'Selects a field of the pod: supports metadata.name, + metadata.namespace, `metadata.labels['''']`, + `metadata.annotations['''']`, spec.nodeName, + spec.serviceAccountName, status.hostIP, status.podIP, + status.podIPs.' + properties: + apiVersion: + description: Version of the schema the FieldPath + is written in terms of, defaults to "v1". + type: string + fieldPath: + description: Path of the field to select in the + specified API version. + type: string + required: + - fieldPath + type: object + resourceFieldRef: + description: 'Selects a resource of the container: only + resources limits and requests (limits.cpu, limits.memory, + limits.ephemeral-storage, requests.cpu, requests.memory + and requests.ephemeral-storage) are currently supported.' + properties: + containerName: + description: 'Container name: required for volumes, + optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format of the + exposed resources, defaults to "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + secretKeyRef: + description: Selects a key of a secret in the pod's + namespace + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the Secret or its key + must be defined + type: boolean + required: + - key + type: object + type: object required: - name type: object @@ -129,16 +409,111 @@ spec: description: Python defines configuration for python auto-instrumentation. properties: env: - description: Env defines customized environments. + description: Env defines env vars. items: - description: Env defines customized envs. + description: EnvVar represents an environment variable present + in a Container. properties: name: - description: Name defines environments name. + description: Name of the environment variable. Must be a + C_IDENTIFIER. type: string value: - description: Value defines environments value. + description: 'Variable references $(VAR_NAME) are expanded + using the previously defined environment variables in + the container and any service environment variables. If + a variable cannot be resolved, the reference in the input + string will be unchanged. Double $$ are reduced to a single + $, which allows for escaping the $(VAR_NAME) syntax: i.e. + "$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)". + Escaped references will never be expanded, regardless + of whether the variable exists or not. Defaults to "".' type: string + valueFrom: + description: Source for the environment variable's value. + Cannot be used if value is not empty. + properties: + configMapKeyRef: + description: Selects a key of a ConfigMap. + properties: + key: + description: The key to select. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the ConfigMap or its + key must be defined + type: boolean + required: + - key + type: object + fieldRef: + description: 'Selects a field of the pod: supports metadata.name, + metadata.namespace, `metadata.labels['''']`, + `metadata.annotations['''']`, spec.nodeName, + spec.serviceAccountName, status.hostIP, status.podIP, + status.podIPs.' + properties: + apiVersion: + description: Version of the schema the FieldPath + is written in terms of, defaults to "v1". + type: string + fieldPath: + description: Path of the field to select in the + specified API version. + type: string + required: + - fieldPath + type: object + resourceFieldRef: + description: 'Selects a resource of the container: only + resources limits and requests (limits.cpu, limits.memory, + limits.ephemeral-storage, requests.cpu, requests.memory + and requests.ephemeral-storage) are currently supported.' + properties: + containerName: + description: 'Container name: required for volumes, + optional for env vars' + type: string + divisor: + anyOf: + - type: integer + - type: string + description: Specifies the output format of the + exposed resources, defaults to "1" + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true + resource: + description: 'Required: resource to select' + type: string + required: + - resource + type: object + secretKeyRef: + description: Selects a key of a secret in the pod's + namespace + properties: + key: + description: The key of the secret to select from. Must + be a valid secret key. + type: string + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, + uid?' + type: string + optional: + description: Specify whether the Secret or its key + must be defined + type: boolean + required: + - key + type: object + type: object required: - name type: object diff --git a/bundle/metadata/annotations.yaml b/bundle/metadata/annotations.yaml index 0a27391f05..963e2b6a18 100644 --- a/bundle/metadata/annotations.yaml +++ b/bundle/metadata/annotations.yaml @@ -5,7 +5,7 @@ annotations: operators.operatorframework.io.bundle.metadata.v1: metadata/ operators.operatorframework.io.bundle.package.v1: opentelemetry-operator operators.operatorframework.io.bundle.channels.v1: alpha - operators.operatorframework.io.metrics.builder: operator-sdk-v1.16.0 + operators.operatorframework.io.metrics.builder: operator-sdk-v1.13.0+git operators.operatorframework.io.metrics.mediatype.v1: metrics+v1 operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v3 diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 46c1861f30..7394a6d059 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,8 +1,2 @@ resources: -- manager.yaml -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -images: -- name: controller - newName: local/opentelemetry-operator - newTag: e2e + - manager.yaml diff --git a/pkg/instrumentation/sdk.go b/pkg/instrumentation/sdk.go index f8cfb1e55b..161e08ad29 100644 --- a/pkg/instrumentation/sdk.go +++ b/pkg/instrumentation/sdk.go @@ -67,27 +67,27 @@ func (i *sdkInjector) inject(ctx context.Context, insts languageInstrumentations otelinst := *insts.Java i.logger.V(1).Info("injecting java instrumentation into pod", "otelinst-namespace", otelinst.Namespace, "otelinst-name", otelinst.Name) pod = injectJavaagent(i.logger, otelinst.Spec.Java, pod) - pod = i.injectCommonEnvVar(otelinst, ns, pod) + pod = i.injectCommonEnvVar(otelinst, pod) pod = i.injectCommonSDKConfig(ctx, otelinst, ns, pod) } if insts.NodeJS != nil { otelinst := *insts.NodeJS i.logger.V(1).Info("injecting nodejs instrumentation into pod", "otelinst-namespace", otelinst.Namespace, "otelinst-name", otelinst.Name) pod = injectNodeJSSDK(i.logger, otelinst.Spec.NodeJS, pod) - pod = i.injectCommonEnvVar(otelinst, ns, pod) + pod = i.injectCommonEnvVar(otelinst, pod) pod = i.injectCommonSDKConfig(ctx, otelinst, ns, pod) } if insts.Python != nil { otelinst := *insts.Python i.logger.V(1).Info("injecting python instrumentation into pod", "otelinst-namespace", otelinst.Namespace, "otelinst-name", otelinst.Name) pod = injectPythonSDK(i.logger, otelinst.Spec.Python, pod) - pod = i.injectCommonEnvVar(otelinst, ns, pod) + pod = i.injectCommonEnvVar(otelinst, pod) pod = i.injectCommonSDKConfig(ctx, otelinst, ns, pod) } return pod } -func (i *sdkInjector) injectCommonEnvVar(otelinst v1alpha1.Instrumentation, ns corev1.Namespace, pod corev1.Pod) corev1.Pod { +func (i *sdkInjector) injectCommonEnvVar(otelinst v1alpha1.Instrumentation, pod corev1.Pod) corev1.Pod { container := &pod.Spec.Containers[0] for _, env := range otelinst.Spec.Env { idx := getIndexOfEnv(container.Env, env.Name) From 29cbdb1829313c2fd5e07ccd6564c04893facea4 Mon Sep 17 00:00:00 2001 From: Duncan-tree-zhou Date: Wed, 26 Jan 2022 00:50:51 +0800 Subject: [PATCH 7/8] update e2e testcases --- apis/v1alpha1/instrumentation_types.go | 16 +++++++++---- apis/v1alpha1/instrumentation_webhook.go | 10 ++++---- .../opentelemetry.io_instrumentations.yaml | 24 +++++++++++++++---- docs/api.md | 8 +++---- .../00-install-instrumentation.yaml | 17 +++++++++++++ tests/e2e/instrumentation-java/01-assert.yaml | 24 ++++++++++++------- .../00-install-instrumentation.yaml | 19 +++++++++++++++ .../e2e/instrumentation-nodejs/01-assert.yaml | 18 ++++++++++---- .../00-install-instrumentation.yaml | 20 +++++++++++++++- .../e2e/instrumentation-python/01-assert.yaml | 20 +++++++++++----- 10 files changed, 139 insertions(+), 37 deletions(-) diff --git a/apis/v1alpha1/instrumentation_types.go b/apis/v1alpha1/instrumentation_types.go index 37e2592546..1c066a229f 100644 --- a/apis/v1alpha1/instrumentation_types.go +++ b/apis/v1alpha1/instrumentation_types.go @@ -37,7 +37,9 @@ type InstrumentationSpec struct { // +optional Sampler `json:"sampler,omitempty"` - // Env defines env vars. + // Env defines common env vars. There are four layers for env vars' definitions and + // the precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars`. + // If the former var had been defined, then the other vars would be ignored. // +optional Env []corev1.EnvVar `json:"env,omitempty"` @@ -94,7 +96,9 @@ type Java struct { // +optional Image string `json:"image,omitempty"` - // Env defines env vars. + // Env defines java specific env vars. There are four layers for env vars' definitions and + // the precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars`. + // If the former var had been defined, then the other vars would be ignored. // +optional Env []corev1.EnvVar `json:"env,omitempty"` } @@ -105,7 +109,9 @@ type NodeJS struct { // +optional Image string `json:"image,omitempty"` - // Env defines env vars. + // Env defines nodejs specific env vars. There are four layers for env vars' definitions and + // the precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars`. + // If the former var had been defined, then the other vars would be ignored. // +optional Env []corev1.EnvVar `json:"env,omitempty"` } @@ -116,7 +122,9 @@ type Python struct { // +optional Image string `json:"image,omitempty"` - // Env defines env vars. + // Env defines python specific env vars. There are four layers for env vars' definitions and + // the precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars`. + // If the former var had been defined, then the other vars would be ignored. // +optional Env []corev1.EnvVar `json:"env,omitempty"` } diff --git a/apis/v1alpha1/instrumentation_webhook.go b/apis/v1alpha1/instrumentation_webhook.go index 800e8d1781..1a977ee192 100644 --- a/apis/v1alpha1/instrumentation_webhook.go +++ b/apis/v1alpha1/instrumentation_webhook.go @@ -16,10 +16,10 @@ package v1alpha1 import ( "fmt" - corev1 "k8s.io/api/core/v1" "strconv" "strings" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" logf "sigs.k8s.io/controller-runtime/pkg/log" @@ -129,11 +129,9 @@ func (in *Instrumentation) validate() error { } func (in *Instrumentation) validateEnv(envs []corev1.EnvVar) error { - if len(envs) > 0 { - for _, env := range envs { - if !strings.HasPrefix(env.Name, envPrefix) { - return fmt.Errorf("env name should start with \"OTEL_\": %s", env.Name) - } + for _, env := range envs { + if !strings.HasPrefix(env.Name, envPrefix) { + return fmt.Errorf("env name should start with \"OTEL_\": %s", env.Name) } } return nil diff --git a/config/crd/bases/opentelemetry.io_instrumentations.yaml b/config/crd/bases/opentelemetry.io_instrumentations.yaml index 2a5789397e..32bc99b9a6 100644 --- a/config/crd/bases/opentelemetry.io_instrumentations.yaml +++ b/config/crd/bases/opentelemetry.io_instrumentations.yaml @@ -45,7 +45,11 @@ spec: SDK and instrumentation. properties: env: - description: Env defines env vars. + description: 'Env defines common env vars. There are four layers for + env vars'' definitions and the precedence order is: `original container + env vars` > `language specific env vars` > `common env vars` > `instrument + spec configs'' vars`. If the former var had been defined, then the + other vars would be ignored.' items: description: EnvVar represents an environment variable present in a Container. @@ -160,7 +164,11 @@ spec: description: Java defines configuration for java auto-instrumentation. properties: env: - description: Env defines env vars. + description: 'Env defines java specific env vars. There are four + layers for env vars'' definitions and the precedence order is: + `original container env vars` > `language specific env vars` + > `common env vars` > `instrument spec configs'' vars`. If the + former var had been defined, then the other vars would be ignored.' items: description: EnvVar represents an environment variable present in a Container. @@ -278,7 +286,11 @@ spec: description: NodeJS defines configuration for nodejs auto-instrumentation. properties: env: - description: Env defines env vars. + description: 'Env defines nodejs specific env vars. There are + four layers for env vars'' definitions and the precedence order + is: `original container env vars` > `language specific env vars` + > `common env vars` > `instrument spec configs'' vars`. If the + former var had been defined, then the other vars would be ignored.' items: description: EnvVar represents an environment variable present in a Container. @@ -411,7 +423,11 @@ spec: description: Python defines configuration for python auto-instrumentation. properties: env: - description: Env defines env vars. + description: 'Env defines python specific env vars. There are + four layers for env vars'' definitions and the precedence order + is: `original container env vars` > `language specific env vars` + > `common env vars` > `instrument spec configs'' vars`. If the + former var had been defined, then the other vars would be ignored.' items: description: EnvVar represents an environment variable present in a Container. diff --git a/docs/api.md b/docs/api.md index 9d35c0bce8..c057c7f0d2 100644 --- a/docs/api.md +++ b/docs/api.md @@ -89,7 +89,7 @@ InstrumentationSpec defines the desired state of OpenTelemetry SDK and instrumen @@ -438,7 +438,7 @@ Java defines configuration for java auto-instrumentation. @@ -718,7 +718,7 @@ NodeJS defines configuration for nodejs auto-instrumentation. @@ -998,7 +998,7 @@ Python defines configuration for python auto-instrumentation. diff --git a/tests/e2e/instrumentation-java/00-install-instrumentation.yaml b/tests/e2e/instrumentation-java/00-install-instrumentation.yaml index 6c1347b139..793f5a87f7 100644 --- a/tests/e2e/instrumentation-java/00-install-instrumentation.yaml +++ b/tests/e2e/instrumentation-java/00-install-instrumentation.yaml @@ -3,6 +3,17 @@ kind: Instrumentation metadata: name: java spec: + env: + - name: OTEL_TRACES_EXPORTER + value: otlp + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://localhost:4317 + - name: OTEL_EXPORTER_OTLP_TIMEOUT + value: "20" + - name: OTEL_TRACES_SAMPLER + value: parentbased_traceidratio + - name: OTEL_TRACES_SAMPLER_ARG + value: "0.85" exporter: endpoint: http://localhost:4317 propagators: @@ -11,3 +22,9 @@ spec: sampler: type: parentbased_traceidratio argument: "0.25" + java: + env: + - name: OTEL_JAVAAGENT_DEBUG + value: "true" + - name: OTEL_INSTRUMENTATION_JDBC_ENABLED + value: "false" diff --git a/tests/e2e/instrumentation-java/01-assert.yaml b/tests/e2e/instrumentation-java/01-assert.yaml index 63b4bd8330..cdc33dcc36 100644 --- a/tests/e2e/instrumentation-java/01-assert.yaml +++ b/tests/e2e/instrumentation-java/01-assert.yaml @@ -10,21 +10,29 @@ spec: containers: - name: myapp env: - - name: OTEL_SERVICE_NAME - value: my-deployment-with-sidecar + - name: OTEL_JAVAAGENT_DEBUG + value: "true" + - name: OTEL_INSTRUMENTATION_JDBC_ENABLED + value: "false" + - name: JAVA_TOOL_OPTIONS + value: " -javaagent:/otel-auto-instrumentation/javaagent.jar" + - name: OTEL_TRACES_EXPORTER + value: otlp - name: OTEL_EXPORTER_OTLP_ENDPOINT value: http://localhost:4317 + - name: OTEL_EXPORTER_OTLP_TIMEOUT + value: "20" + - name: OTEL_TRACES_SAMPLER + value: parentbased_traceidratio + - name: OTEL_TRACES_SAMPLER_ARG + value: "0.85" + - name: OTEL_SERVICE_NAME + value: my-deployment-with-sidecar - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME - name: OTEL_RESOURCE_ATTRIBUTES - name: OTEL_PROPAGATORS value: jaeger,b3 - - name: OTEL_TRACES_SAMPLER - value: parentbased_traceidratio - - name: OTEL_TRACES_SAMPLER_ARG - value: "0.25" - - name: JAVA_TOOL_OPTIONS - value: " -javaagent:/otel-auto-instrumentation/javaagent.jar" volumeMounts: - mountPath: /var/run/secrets/kubernetes.io/serviceaccount - mountPath: /otel-auto-instrumentation diff --git a/tests/e2e/instrumentation-nodejs/00-install-instrumentation.yaml b/tests/e2e/instrumentation-nodejs/00-install-instrumentation.yaml index 9ea4358b9b..40459f483a 100644 --- a/tests/e2e/instrumentation-nodejs/00-install-instrumentation.yaml +++ b/tests/e2e/instrumentation-nodejs/00-install-instrumentation.yaml @@ -3,8 +3,27 @@ kind: Instrumentation metadata: name: nodejs spec: + env: + - name: OTEL_TRACES_EXPORTER + value: otlp + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://localhost:4317 + - name: OTEL_EXPORTER_OTLP_TIMEOUT + value: "20" + - name: OTEL_TRACES_SAMPLER + value: parentbased_traceidratio + - name: OTEL_TRACES_SAMPLER_ARG + value: "0.85" exporter: endpoint: http://localhost:4317 propagators: - jaeger - b3 + sampler: + type: parentbased_traceidratio + argument: "0.25" + nodejs: + env: + - name: OTEL_NODEJS_DEBUG + value: "true" + diff --git a/tests/e2e/instrumentation-nodejs/01-assert.yaml b/tests/e2e/instrumentation-nodejs/01-assert.yaml index b796a5b8e5..d327e85962 100644 --- a/tests/e2e/instrumentation-nodejs/01-assert.yaml +++ b/tests/e2e/instrumentation-nodejs/01-assert.yaml @@ -10,17 +10,27 @@ spec: containers: - name: myapp env: - - name: OTEL_SERVICE_NAME - value: my-deployment-with-sidecar + - name: OTEL_NODEJS_DEBUG + value: "true" + - name: NODE_OPTIONS + value: " --require /otel-auto-instrumentation/autoinstrumentation.js" + - name: OTEL_TRACES_EXPORTER + value: otlp - name: OTEL_EXPORTER_OTLP_ENDPOINT value: http://localhost:4317 + - name: OTEL_EXPORTER_OTLP_TIMEOUT + value: "20" + - name: OTEL_TRACES_SAMPLER + value: parentbased_traceidratio + - name: OTEL_TRACES_SAMPLER_ARG + value: "0.85" + - name: OTEL_SERVICE_NAME + value: my-deployment-with-sidecar - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME - name: OTEL_RESOURCE_ATTRIBUTES - name: OTEL_PROPAGATORS value: jaeger,b3 - - name: NODE_OPTIONS - value: " --require /otel-auto-instrumentation/autoinstrumentation.js" volumeMounts: - mountPath: /var/run/secrets/kubernetes.io/serviceaccount - mountPath: /otel-auto-instrumentation diff --git a/tests/e2e/instrumentation-python/00-install-instrumentation.yaml b/tests/e2e/instrumentation-python/00-install-instrumentation.yaml index d41827bf8f..fa1fff2353 100644 --- a/tests/e2e/instrumentation-python/00-install-instrumentation.yaml +++ b/tests/e2e/instrumentation-python/00-install-instrumentation.yaml @@ -3,8 +3,26 @@ kind: Instrumentation metadata: name: python spec: + env: + - name: OTEL_EXPORTER_OTLP_TIMEOUT + value: "20" + - name: OTEL_TRACES_SAMPLER + value: parentbased_traceidratio + - name: OTEL_TRACES_SAMPLER_ARG + value: "0.85" exporter: - endpoint: http://localhost:4318/v1/traces + endpoint: http://localhost:4317 propagators: - jaeger - b3 + sampler: + type: parentbased_traceidratio + argument: "0.25" + python: + env: + - name: OTEL_LOG_LEVEL + value: "debug" + - name: OTEL_TRACES_EXPORTER + value: otlp_proto_http + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://localhost:4317 \ No newline at end of file diff --git a/tests/e2e/instrumentation-python/01-assert.yaml b/tests/e2e/instrumentation-python/01-assert.yaml index 35ea2acb80..105cfd30cd 100644 --- a/tests/e2e/instrumentation-python/01-assert.yaml +++ b/tests/e2e/instrumentation-python/01-assert.yaml @@ -10,19 +10,27 @@ spec: containers: - name: myapp env: + - name: OTEL_LOG_LEVEL + value: "debug" + - name: OTEL_TRACES_EXPORTER + value: otlp_proto_http + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://localhost:4317 + - name: PYTHONPATH + value: "/otel-auto-instrumentation/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation" + - name: OTEL_EXPORTER_OTLP_TIMEOUT + value: "20" + - name: OTEL_TRACES_SAMPLER + value: parentbased_traceidratio + - name: OTEL_TRACES_SAMPLER_ARG + value: "0.85" - name: OTEL_SERVICE_NAME value: my-deployment-with-sidecar - - name: OTEL_EXPORTER_OTLP_ENDPOINT - value: http://localhost:4318/v1/traces - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME - name: OTEL_RESOURCE_ATTRIBUTES - name: OTEL_PROPAGATORS value: jaeger,b3 - - name: PYTHONPATH - value: "/otel-auto-instrumentation/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation" - - name: OTEL_TRACES_EXPORTER - value: otlp_proto_http volumeMounts: - mountPath: /var/run/secrets/kubernetes.io/serviceaccount - mountPath: /otel-auto-instrumentation From a8a4d80f323f2e665b2c8282702ed76bb4ad14dd Mon Sep 17 00:00:00 2001 From: Duncan-tree-zhou Date: Wed, 26 Jan 2022 23:25:13 +0800 Subject: [PATCH 8/8] fix unit tests --- apis/v1alpha1/zz_generated.deepcopy.go | 1 + .../opentelemetry.io_instrumentations.yaml | 24 ++- pkg/instrumentation/podmutator_test.go | 201 +++++++++++++++--- pkg/instrumentation/sdk_test.go | 32 +-- 4 files changed, 212 insertions(+), 46 deletions(-) diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index d21b1f660a..5ea87e5479 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -1,3 +1,4 @@ +//go:build !ignore_autogenerated // +build !ignore_autogenerated // Copyright The OpenTelemetry Authors diff --git a/bundle/manifests/opentelemetry.io_instrumentations.yaml b/bundle/manifests/opentelemetry.io_instrumentations.yaml index 7b513cae68..13321f7c89 100644 --- a/bundle/manifests/opentelemetry.io_instrumentations.yaml +++ b/bundle/manifests/opentelemetry.io_instrumentations.yaml @@ -43,7 +43,11 @@ spec: SDK and instrumentation. properties: env: - description: Env defines env vars. + description: 'Env defines common env vars. There are four layers for + env vars'' definitions and the precedence order is: `original container + env vars` > `language specific env vars` > `common env vars` > `instrument + spec configs'' vars`. If the former var had been defined, then the + other vars would be ignored.' items: description: EnvVar represents an environment variable present in a Container. @@ -158,7 +162,11 @@ spec: description: Java defines configuration for java auto-instrumentation. properties: env: - description: Env defines env vars. + description: 'Env defines java specific env vars. There are four + layers for env vars'' definitions and the precedence order is: + `original container env vars` > `language specific env vars` + > `common env vars` > `instrument spec configs'' vars`. If the + former var had been defined, then the other vars would be ignored.' items: description: EnvVar represents an environment variable present in a Container. @@ -276,7 +284,11 @@ spec: description: NodeJS defines configuration for nodejs auto-instrumentation. properties: env: - description: Env defines env vars. + description: 'Env defines nodejs specific env vars. There are + four layers for env vars'' definitions and the precedence order + is: `original container env vars` > `language specific env vars` + > `common env vars` > `instrument spec configs'' vars`. If the + former var had been defined, then the other vars would be ignored.' items: description: EnvVar represents an environment variable present in a Container. @@ -409,7 +421,11 @@ spec: description: Python defines configuration for python auto-instrumentation. properties: env: - description: Env defines env vars. + description: 'Env defines python specific env vars. There are + four layers for env vars'' definitions and the precedence order + is: `original container env vars` > `language specific env vars` + > `common env vars` > `instrument spec configs'' vars`. If the + former var had been defined, then the other vars would be ignored.' items: description: EnvVar represents an environment variable present in a Container. diff --git a/pkg/instrumentation/podmutator_test.go b/pkg/instrumentation/podmutator_test.go index 2512fd832d..15766b7a44 100644 --- a/pkg/instrumentation/podmutator_test.go +++ b/pkg/instrumentation/podmutator_test.go @@ -53,7 +53,40 @@ func TestMutatePod(t *testing.T) { Namespace: "javaagent", }, Spec: v1alpha1.InstrumentationSpec{ - Java: v1alpha1.Java{}, + Java: v1alpha1.Java{ + Env: []corev1.EnvVar{ + { + Name: "OTEL_JAVAAGENT_DEBUG", + Value: "true", + }, + { + Name: "OTEL_INSTRUMENTATION_JDBC_ENABLED", + Value: "false", + }, + }, + }, + Env: []corev1.EnvVar{ + { + Name: "OTEL_TRACES_EXPORTER", + Value: "otlp", + }, + { + Name: "OTEL_EXPORTER_OTLP_ENDPOINT", + Value: "http://localhost:4317", + }, + { + Name: "OTEL_EXPORTER_OTLP_TIMEOUT", + Value: "20", + }, + { + Name: "OTEL_TRACES_SAMPLER", + Value: "parentbased_traceidratio", + }, + { + Name: "OTEL_TRACES_SAMPLER_ARG", + Value: "0.85", + }, + }, Exporter: v1alpha1.Exporter{ Endpoint: "http://collector:12345", }, @@ -103,12 +136,40 @@ func TestMutatePod(t *testing.T) { Name: "app", Env: []corev1.EnvVar{ { - Name: "OTEL_SERVICE_NAME", - Value: "app", + Name: "OTEL_JAVAAGENT_DEBUG", + Value: "true", + }, + { + Name: "OTEL_INSTRUMENTATION_JDBC_ENABLED", + Value: "false", + }, + { + Name: "JAVA_TOOL_OPTIONS", + Value: javaJVMArgument, + }, + { + Name: "OTEL_TRACES_EXPORTER", + Value: "otlp", }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", - Value: "http://collector:12345", + Value: "http://localhost:4317", + }, + { + Name: "OTEL_EXPORTER_OTLP_TIMEOUT", + Value: "20", + }, + { + Name: "OTEL_TRACES_SAMPLER", + Value: "parentbased_traceidratio", + }, + { + Name: "OTEL_TRACES_SAMPLER_ARG", + Value: "0.85", + }, + { + Name: "OTEL_SERVICE_NAME", + Value: "app", }, { Name: "OTEL_RESOURCE_ATTRIBUTES_POD_NAME", @@ -130,10 +191,6 @@ func TestMutatePod(t *testing.T) { Name: "OTEL_RESOURCE_ATTRIBUTES", Value: "k8s.container.name=app,k8s.namespace.name=javaagent,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)", }, - { - Name: "JAVA_TOOL_OPTIONS", - Value: javaJVMArgument, - }, }, VolumeMounts: []corev1.VolumeMount{ { @@ -161,6 +218,34 @@ func TestMutatePod(t *testing.T) { Spec: v1alpha1.InstrumentationSpec{ NodeJS: v1alpha1.NodeJS{ Image: "otel/nodejs:1", + Env: []corev1.EnvVar{ + { + Name: "OTEL_NODEJS_DEBUG", + Value: "true", + }, + }, + }, + Env: []corev1.EnvVar{ + { + Name: "OTEL_TRACES_EXPORTER", + Value: "otlp", + }, + { + Name: "OTEL_EXPORTER_OTLP_ENDPOINT", + Value: "http://localhost:4317", + }, + { + Name: "OTEL_EXPORTER_OTLP_TIMEOUT", + Value: "20", + }, + { + Name: "OTEL_TRACES_SAMPLER", + Value: "parentbased_traceidratio", + }, + { + Name: "OTEL_TRACES_SAMPLER_ARG", + Value: "0.85", + }, }, Exporter: v1alpha1.Exporter{ Endpoint: "http://collector:12345", @@ -212,12 +297,36 @@ func TestMutatePod(t *testing.T) { Name: "app", Env: []corev1.EnvVar{ { - Name: "OTEL_SERVICE_NAME", - Value: "app", + Name: "OTEL_NODEJS_DEBUG", + Value: "true", + }, + { + Name: "NODE_OPTIONS", + Value: nodeRequireArgument, + }, + { + Name: "OTEL_TRACES_EXPORTER", + Value: "otlp", }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", - Value: "http://collector:12345", + Value: "http://localhost:4317", + }, + { + Name: "OTEL_EXPORTER_OTLP_TIMEOUT", + Value: "20", + }, + { + Name: "OTEL_TRACES_SAMPLER", + Value: "parentbased_traceidratio", + }, + { + Name: "OTEL_TRACES_SAMPLER_ARG", + Value: "0.85", + }, + { + Name: "OTEL_SERVICE_NAME", + Value: "app", }, { Name: "OTEL_RESOURCE_ATTRIBUTES_POD_NAME", @@ -239,10 +348,6 @@ func TestMutatePod(t *testing.T) { Name: "OTEL_RESOURCE_ATTRIBUTES", Value: "k8s.container.name=app,k8s.namespace.name=nodejs,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)", }, - { - Name: "NODE_OPTIONS", - Value: nodeRequireArgument, - }, }, VolumeMounts: []corev1.VolumeMount{ { @@ -270,10 +375,38 @@ func TestMutatePod(t *testing.T) { Spec: v1alpha1.InstrumentationSpec{ Python: v1alpha1.Python{ Image: "otel/python:1", + Env: []corev1.EnvVar{ + { + Name: "OTEL_LOG_LEVEL", + Value: "debug", + }, + { + Name: "OTEL_TRACES_EXPORTER", + Value: "otlp_proto_http", + }, + { + Name: "OTEL_EXPORTER_OTLP_ENDPOINT", + Value: "http://localhost:4317", + }, + }, }, Exporter: v1alpha1.Exporter{ Endpoint: "http://collector:12345", }, + Env: []corev1.EnvVar{ + { + Name: "OTEL_EXPORTER_OTLP_TIMEOUT", + Value: "20", + }, + { + Name: "OTEL_TRACES_SAMPLER", + Value: "parentbased_traceidratio", + }, + { + Name: "OTEL_TRACES_SAMPLER_ARG", + Value: "0.85", + }, + }, }, }, pod: corev1.Pod{ @@ -321,12 +454,36 @@ func TestMutatePod(t *testing.T) { Name: "app", Env: []corev1.EnvVar{ { - Name: "OTEL_SERVICE_NAME", - Value: "app", + Name: "OTEL_LOG_LEVEL", + Value: "debug", + }, + { + Name: "OTEL_TRACES_EXPORTER", + Value: "otlp_proto_http", }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", - Value: "http://collector:12345", + Value: "http://localhost:4317", + }, + { + Name: "PYTHONPATH", + Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix), + }, + { + Name: "OTEL_EXPORTER_OTLP_TIMEOUT", + Value: "20", + }, + { + Name: "OTEL_TRACES_SAMPLER", + Value: "parentbased_traceidratio", + }, + { + Name: "OTEL_TRACES_SAMPLER_ARG", + Value: "0.85", + }, + { + Name: "OTEL_SERVICE_NAME", + Value: "app", }, { Name: "OTEL_RESOURCE_ATTRIBUTES_POD_NAME", @@ -348,14 +505,6 @@ func TestMutatePod(t *testing.T) { Name: "OTEL_RESOURCE_ATTRIBUTES", Value: "k8s.container.name=app,k8s.namespace.name=python,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)", }, - { - Name: "PYTHONPATH", - Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix), - }, - { - Name: "OTEL_TRACES_EXPORTER", - Value: "otlp_proto_http", - }, }, VolumeMounts: []corev1.VolumeMount{ { diff --git a/pkg/instrumentation/sdk_test.go b/pkg/instrumentation/sdk_test.go index c667e73619..4ee0e63c0f 100644 --- a/pkg/instrumentation/sdk_test.go +++ b/pkg/instrumentation/sdk_test.go @@ -431,6 +431,10 @@ func TestInjectJava(t *testing.T) { }, }, Env: []corev1.EnvVar{ + { + Name: "JAVA_TOOL_OPTIONS", + Value: javaJVMArgument, + }, { Name: "OTEL_SERVICE_NAME", Value: "app", @@ -459,10 +463,6 @@ func TestInjectJava(t *testing.T) { Name: "OTEL_RESOURCE_ATTRIBUTES", Value: "k8s.container.name=app,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)", }, - { - Name: "JAVA_TOOL_OPTIONS", - Value: javaJVMArgument, - }, }, }, }, @@ -529,6 +529,10 @@ func TestInjectNodeJS(t *testing.T) { }, }, Env: []corev1.EnvVar{ + { + Name: "NODE_OPTIONS", + Value: nodeRequireArgument, + }, { Name: "OTEL_SERVICE_NAME", Value: "app", @@ -557,10 +561,6 @@ func TestInjectNodeJS(t *testing.T) { Name: "OTEL_RESOURCE_ATTRIBUTES", Value: "k8s.container.name=app,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)", }, - { - Name: "NODE_OPTIONS", - Value: nodeRequireArgument, - }, }, }, }, @@ -628,6 +628,14 @@ func TestInjectPython(t *testing.T) { }, }, Env: []corev1.EnvVar{ + { + Name: "PYTHONPATH", + Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix), + }, + { + Name: "OTEL_TRACES_EXPORTER", + Value: "otlp_proto_http", + }, { Name: "OTEL_SERVICE_NAME", Value: "app", @@ -656,14 +664,6 @@ func TestInjectPython(t *testing.T) { Name: "OTEL_RESOURCE_ATTRIBUTES", Value: "k8s.container.name=app,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)", }, - { - Name: "PYTHONPATH", - Value: fmt.Sprintf("%s:%s", pythonPathPrefix, pythonPathSuffix), - }, - { - Name: "OTEL_TRACES_EXPORTER", - Value: "otlp_proto_http", - }, }, }, },
NameTypeDescriptionRequired
keystring + The key of the secret to select from. Must be a valid secret key.
+
true
namestring + Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?
+
false
optionalboolean + Specify whether the Secret or its key must be defined
false
env []object - Env defines env vars.
+ Env defines common env vars. There are four layers for env vars' definitions and the precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars`. If the former var had been defined, then the other vars would be ignored.
false
env []object - Env defines env vars.
+ Env defines java specific env vars. There are four layers for env vars' definitions and the precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars`. If the former var had been defined, then the other vars would be ignored.
false
env []object - Env defines env vars.
+ Env defines nodejs specific env vars. There are four layers for env vars' definitions and the precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars`. If the former var had been defined, then the other vars would be ignored.
false
env []object - Env defines env vars.
+ Env defines python specific env vars. There are four layers for env vars' definitions and the precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars`. If the former var had been defined, then the other vars would be ignored.
false