diff --git a/tests/e2e/env-vars/00-install-collector.yaml b/tests/e2e/env-vars/00-install-collector.yaml new file mode 100644 index 0000000000..fe390c6cae --- /dev/null +++ b/tests/e2e/env-vars/00-install-collector.yaml @@ -0,0 +1,23 @@ +apiVersion: opentelemetry.io/v1alpha1 +kind: OpenTelemetryCollector +metadata: + name: sidecar +spec: + config: | + receivers: + otlp: + protocols: + grpc: + http: + processors: + + exporters: + debug: + + service: + pipelines: + traces: + receivers: [otlp] + processors: [] + exporters: [debug] + mode: sidecar diff --git a/tests/e2e/env-vars/00-install-instrumentation.yaml b/tests/e2e/env-vars/00-install-instrumentation.yaml new file mode 100644 index 0000000000..e803148fec --- /dev/null +++ b/tests/e2e/env-vars/00-install-instrumentation.yaml @@ -0,0 +1,7 @@ +apiVersion: opentelemetry.io/v1alpha1 +kind: Instrumentation +metadata: + name: sdk-only +spec: + exporter: + endpoint: http://localhost:4317 \ No newline at end of file diff --git a/tests/e2e/env-vars/01-assert.yaml b/tests/e2e/env-vars/01-assert.yaml new file mode 100644 index 0000000000..9bffa12f76 --- /dev/null +++ b/tests/e2e/env-vars/01-assert.yaml @@ -0,0 +1,35 @@ +apiVersion: v1 +kind: Pod +metadata: + annotations: + instrumentation.opentelemetry.io/inject-sdk: "true" + sidecar.opentelemetry.io/inject: "true" + labels: + app: my-deploy +spec: + (containers[?name == 'myapp']): + - name: myapp + env: + - name: OTEL_SERVICE_NAME + value: my-deploy + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://localhost:4317 + - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: spec.nodeName + - name: OTEL_RESOURCE_ATTRIBUTES + value: + ( contains(@, 'k8s.container.name=myapp') ): true + ( contains(@, 'k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)') ): true + ( contains(@, 'k8s.replicaset.name=my-deploy-') ): true + ( contains(@, 'k8s.deployment.name=my-deploy') ): true + ( contains(@, concat('k8s.namespace.name=', $namespace)) ): true + ( contains(@, 'k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME)') ): true + ( contains(@, 'service.version=main') ): true diff --git a/tests/e2e/env-vars/01-deployment.yaml b/tests/e2e/env-vars/01-deployment.yaml new file mode 100644 index 0000000000..2086aa5ee6 --- /dev/null +++ b/tests/e2e/env-vars/01-deployment.yaml @@ -0,0 +1,20 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-deploy +spec: + selector: + matchLabels: + app: my-deploy + replicas: 1 + template: + metadata: + labels: + app: my-deploy + annotations: + sidecar.opentelemetry.io/inject: "true" + instrumentation.opentelemetry.io/inject-sdk: "true" + spec: + containers: + - name: myapp + image: ghcr.io/open-telemetry/opentelemetry-operator/e2e-test-app-python:main diff --git a/tests/e2e/env-vars/02-assert.yaml b/tests/e2e/env-vars/02-assert.yaml new file mode 100644 index 0000000000..948c5a24d1 --- /dev/null +++ b/tests/e2e/env-vars/02-assert.yaml @@ -0,0 +1,38 @@ +apiVersion: v1 +kind: Pod +metadata: + annotations: + instrumentation.opentelemetry.io/inject-sdk: "true" + sidecar.opentelemetry.io/inject: "true" + labels: + job-name: my-cron-job-exec + ownerReferences: + - apiVersion: batch/v1 + kind: Job + name: my-cron-job-exec +spec: + (containers[?name == 'myapp']): + - name: myapp + env: + - name: OTEL_SERVICE_NAME + value: my-cron-job + - name: OTEL_EXPORTER_OTLP_ENDPOINT + - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: spec.nodeName + - name: OTEL_RESOURCE_ATTRIBUTES + value: + ( contains(@, 'k8s.container.name=myapp') ): true + ( contains(@, 'k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)') ): true + ( contains(@, 'k8s.job.name=my-cron-job-exec') ): true + ( contains(@, 'k8s.cronjob.name=my-cron-job') ): true + ( contains(@, concat('k8s.namespace.name=', $namespace)) ): true + ( contains(@, 'k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME)') ): true + ( contains(@, 'service.version=main') ): true diff --git a/tests/e2e/env-vars/02-cronjob.yaml b/tests/e2e/env-vars/02-cronjob.yaml new file mode 100644 index 0000000000..35261db85c --- /dev/null +++ b/tests/e2e/env-vars/02-cronjob.yaml @@ -0,0 +1,23 @@ +apiVersion: batch/v1 +kind: CronJob +metadata: + name: my-cron-job +spec: + schedule: "* * * * *" + suspend: true + jobTemplate: + spec: + template: + metadata: + annotations: + sidecar.opentelemetry.io/inject: "true" + instrumentation.opentelemetry.io/inject-sdk: "true" + spec: + restartPolicy: Never + containers: + - name: myapp + image: ghcr.io/open-telemetry/opentelemetry-operator/e2e-test-app-python:main + imagePullPolicy: IfNotPresent + command: + - echo + - ok \ No newline at end of file diff --git a/tests/e2e/env-vars/03-assert.yaml b/tests/e2e/env-vars/03-assert.yaml new file mode 100644 index 0000000000..a2223549e4 --- /dev/null +++ b/tests/e2e/env-vars/03-assert.yaml @@ -0,0 +1,37 @@ +apiVersion: v1 +kind: Pod +metadata: + annotations: + instrumentation.opentelemetry.io/inject-sdk: "true" + sidecar.opentelemetry.io/inject: "true" + labels: + job-name: my-job + ownerReferences: + - apiVersion: batch/v1 + kind: Job + name: my-job +spec: + (containers[?name == 'myapp']): + - name: myapp + env: + - name: OTEL_SERVICE_NAME + value: my-job + - name: OTEL_EXPORTER_OTLP_ENDPOINT + - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: spec.nodeName + - name: OTEL_RESOURCE_ATTRIBUTES + value: + ( contains(@, 'k8s.container.name=myapp') ): true + ( contains(@, 'k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)') ): true + ( contains(@, 'k8s.job.name=my-job') ): true + ( contains(@, concat('k8s.namespace.name=', $namespace)) ): true + ( contains(@, 'k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME)') ): true + ( contains(@, 'service.version=main') ): true diff --git a/tests/e2e/env-vars/03-job.yaml b/tests/e2e/env-vars/03-job.yaml new file mode 100644 index 0000000000..f3e65c9ffc --- /dev/null +++ b/tests/e2e/env-vars/03-job.yaml @@ -0,0 +1,19 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: my-job +spec: + template: + metadata: + annotations: + sidecar.opentelemetry.io/inject: "true" + instrumentation.opentelemetry.io/inject-sdk: "true" + spec: + restartPolicy: Never + containers: + - name: myapp + image: ghcr.io/open-telemetry/opentelemetry-operator/e2e-test-app-python:main + imagePullPolicy: IfNotPresent + command: + - echo + - ok \ No newline at end of file diff --git a/tests/e2e/env-vars/chainsaw-test.yaml b/tests/e2e/env-vars/chainsaw-test.yaml new file mode 100644 index 0000000000..6428c0f767 --- /dev/null +++ b/tests/e2e/env-vars/chainsaw-test.yaml @@ -0,0 +1,54 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + creationTimestamp: null + name: service-name +spec: + steps: + - name: step-00 + try: + - apply: + file: 00-install-collector.yaml + - apply: + file: 00-install-instrumentation.yaml + # Deployment + - name: step-01 + try: + - apply: + file: 01-deployment.yaml + - assert: + file: 01-assert.yaml + catch: + - podLogs: + selector: app=my-deploy + # CronJob + - name: step-02 + try: + - apply: + file: 02-cronjob.yaml + - command: + entrypoint: kubectl + args: + - -n + - ${NAMESPACE} + - create + - job + - --from + - cronjob/my-cron-job + - my-cron-job-exec + - assert: + file: 02-assert.yaml + catch: + - podLogs: + selector: job-name=my-cron-job-exec + # Job + - name: step-03 + try: + - apply: + file: 03-job.yaml + - assert: + file: 03-assert.yaml + catch: + - podLogs: + selector: job-name=my-job