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..0948617a36 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.1 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..b5a31bd67b 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)