Skip to content

Commit

Permalink
Add e2e test case
Browse files Browse the repository at this point in the history
Signed-off-by: Janario Oliveira <[email protected]>
  • Loading branch information
janario committed Mar 26, 2024
1 parent 082962c commit c5bea75
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/e2e/env-vars/00-install-collector.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions tests/e2e/env-vars/00-install-instrumentation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: opentelemetry.io/v1alpha1
kind: Instrumentation
metadata:
name: sdk-only
spec:
exporter:
endpoint: http://localhost:4317
35 changes: 35 additions & 0 deletions tests/e2e/env-vars/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions tests/e2e/env-vars/01-deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions tests/e2e/env-vars/02-assert.yaml
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions tests/e2e/env-vars/02-cronjob.yaml
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions tests/e2e/env-vars/03-assert.yaml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions tests/e2e/env-vars/03-job.yaml
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions tests/e2e/env-vars/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c5bea75

Please sign in to comment.