Skip to content

Commit 8c0f9e6

Browse files
committed
Add E2E test; put TA E2E tests into separate target
Signed-off-by: Matej Gera <[email protected]>
1 parent c08f560 commit 8c0f9e6

File tree

17 files changed

+285
-3
lines changed

17 files changed

+285
-3
lines changed

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ e2e-multi-instrumentation:
233233
e2e-opampbridge:
234234
$(KUTTL) test --config kuttl-test-opampbridge.yaml
235235

236+
# Target allocator end-to-tests
237+
.PHONY: e2e-targetallocator
238+
e2e-targetallocator:
239+
$(KUTTL) test --config kuttl-test-targetallocator.yaml
240+
236241
.PHONY: prepare-e2e
237242
prepare-e2e: kuttl set-image-controller container container-target-allocator container-operator-opamp-bridge start-kind cert-manager install-metrics-server install-targetallocator-prometheus-crds load-image-all deploy
238243
TARGETALLOCATOR_IMG=$(TARGETALLOCATOR_IMG) OPERATOROPAMPBRIDGE_IMG=$(OPERATOROPAMPBRIDGE_IMG) OPERATOR_IMG=$(IMG) SED_BIN="$(SED)" ./hack/modify-test-images.sh

hack/modify-test-images.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ DEFAULT_OPERATOROPAMPBRIDGE_IMG=${DEFAULT_OPERATOROPAMPBRIDGE_IMG:-local/opentel
77
DEFAULT_OPERATOR_IMG=${DEFAULT_OPERATOR_IMG:-local/opentelemetry-operator:e2e}
88

99
${SED_BIN} -i "s#${DEFAULT_TARGETALLOCATOR_IMG}#${TARGETALLOCATOR_IMG}#g" tests/e2e/smoke-targetallocator/*.yaml
10-
${SED_BIN} -i "s#${DEFAULT_TARGETALLOCATOR_IMG}#${TARGETALLOCATOR_IMG}#g" tests/e2e/targetallocator-features/00-install.yaml
10+
${SED_BIN} -i "s#${DEFAULT_TARGETALLOCATOR_IMG}#${TARGETALLOCATOR_IMG}#g" tests/e2e-targetallocator/targetallocator-features/00-install.yaml
1111
${SED_BIN} -i "s#${DEFAULT_TARGETALLOCATOR_IMG}#${TARGETALLOCATOR_IMG}#g" tests/e2e/prometheus-config-validation/*.yaml
12-
${SED_BIN} -i "s#${DEFAULT_TARGETALLOCATOR_IMG}#${TARGETALLOCATOR_IMG}#g" tests/e2e/targetallocator-prometheuscr/*.yaml
12+
${SED_BIN} -i "s#${DEFAULT_TARGETALLOCATOR_IMG}#${TARGETALLOCATOR_IMG}#g" tests/e2e-targetallocator/targetallocator-prometheuscr/*.yaml
13+
${SED_BIN} -i "s#${DEFAULT_TARGETALLOCATOR_IMG}#${TARGETALLOCATOR_IMG}#g" tests/e2e-targetallocator/targetallocator-kubernetessd/*.yaml
1314

1415
${SED_BIN} -i "s#${DEFAULT_OPERATOR_IMG}#${OPERATOR_IMG}#g" tests/e2e-multi-instrumentation/*.yaml
1516

kuttl-test-targetallocator.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestSuite
3+
artifactsDir: ./tests/_build/artifacts/
4+
testDirs:
5+
- ./tests/e2e-targetallocator/
6+
timeout: 150
7+
parallel: 4

tests/e2e-opampbridge/opampbridge/00-install.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ kind: OpAMPBridge
2626
metadata:
2727
name: test
2828
spec:
29-
image: "local/opentelemetry-operator-opamp-bridge:e2e"
29+
image: "ghcr.io/open-telemetry/opentelemetry-operator/operator-opamp-bridge:v0.90.0-14-g082e678"
3030
endpoint: ws://opamp-server:4320/v1/opamp
3131
capabilities:
3232
AcceptsOpAMPConnectionSettings: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# This KUTTL assert uses the check-daemonset.sh script to ensure the number of ready pods in a daemonset matches the desired count, retrying until successful or a timeout occurs. The script is needed as the number of Kubernetes cluster nodes can vary and we cannot statically set desiredNumberScheduled and numberReady in the assert for daemonset status.
2+
3+
apiVersion: kuttl.dev/v1beta1
4+
kind: TestAssert
5+
commands:
6+
- script: ./tests/e2e/smoke-daemonset/check-daemonset.sh
7+
---
8+
apiVersion: apps/v1
9+
kind: Deployment
10+
metadata:
11+
name: prometheus-kubernetessd-targetallocator
12+
status:
13+
replicas: 1
14+
readyReplicas: 1
15+
observedGeneration: 1
16+
---
17+
apiVersion: v1
18+
kind: ConfigMap
19+
metadata:
20+
name: prometheus-kubernetessd-targetallocator
21+
---
22+
apiVersion: v1
23+
kind: ConfigMap
24+
metadata:
25+
name: prometheus-kubernetessd-collector
26+
data:
27+
collector.yaml: |
28+
exporters:
29+
prometheus:
30+
endpoint: 0.0.0.0:9090
31+
processors: null
32+
receivers:
33+
prometheus:
34+
config: {}
35+
target_allocator:
36+
collector_id: ${POD_NAME}
37+
endpoint: http://prometheus-kubernetessd-targetallocator:80
38+
interval: 30s
39+
service:
40+
pipelines:
41+
metrics:
42+
exporters:
43+
- prometheus
44+
processors: []
45+
receivers:
46+
- prometheus
47+
---
48+
# Print TA pod logs if test fails
49+
apiVersion: kuttl.dev/v1beta1
50+
kind: TestAssert
51+
collectors:
52+
- selector: app.kubernetes.io/managed-by=opentelemetry-operator
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: ta
5+
automountServiceAccountToken: true
6+
---
7+
apiVersion: v1
8+
kind: ServiceAccount
9+
metadata:
10+
name: collector
11+
automountServiceAccountToken: true
12+
---
13+
apiVersion: rbac.authorization.k8s.io/v1
14+
kind: ClusterRole
15+
metadata:
16+
name: ta
17+
rules:
18+
- apiGroups: [""]
19+
resources:
20+
- pods
21+
- nodes
22+
- services
23+
- endpoints
24+
- configmaps
25+
- secrets
26+
- namespaces
27+
verbs:
28+
- get
29+
- watch
30+
- list
31+
- apiGroups: ["apps"]
32+
resources:
33+
- statefulsets
34+
- daemonsets
35+
- services
36+
- endpoints
37+
verbs:
38+
- get
39+
- watch
40+
- list
41+
- apiGroups: ["discovery.k8s.io"]
42+
resources:
43+
- endpointslices
44+
verbs:
45+
- get
46+
- watch
47+
- list
48+
- apiGroups: ["networking.k8s.io"]
49+
resources:
50+
- ingresses
51+
verbs:
52+
- get
53+
- watch
54+
- list
55+
- nonResourceURLs: ["/metrics"]
56+
verbs: ["get"]
57+
---
58+
apiVersion: rbac.authorization.k8s.io/v1
59+
kind: ClusterRole
60+
metadata:
61+
name: collector
62+
rules:
63+
- apiGroups: [""]
64+
resources:
65+
- pods
66+
- nodes
67+
- nodes/metrics
68+
- services
69+
- endpoints
70+
verbs:
71+
- get
72+
- watch
73+
- list
74+
- apiGroups: ["networking.k8s.io"]
75+
resources:
76+
- ingresses
77+
verbs:
78+
- get
79+
- watch
80+
- list
81+
- nonResourceURLs: ["/metrics", "/metrics/cadvisor"]
82+
verbs: ["get"]
83+
---
84+
apiVersion: kuttl.dev/v1beta1
85+
kind: TestStep
86+
commands:
87+
- command: kubectl create clusterrolebinding ta-$NAMESPACE --clusterrole=ta --serviceaccount=$NAMESPACE:ta
88+
- command: kubectl create clusterrolebinding collector-$NAMESPACE --clusterrole=collector --serviceaccount=$NAMESPACE:collector
89+
---
90+
apiVersion: opentelemetry.io/v1alpha1
91+
kind: OpenTelemetryCollector
92+
metadata:
93+
name: prometheus-kubernetessd
94+
spec:
95+
mode: daemonset
96+
serviceAccount: collector
97+
targetAllocator:
98+
enabled: true
99+
serviceAccount: ta
100+
image: "local/opentelemetry-operator-targetallocator:e2e"
101+
prometheusCR:
102+
enabled: false
103+
config: |
104+
receivers:
105+
prometheus:
106+
config:
107+
scrape_configs:
108+
- job_name: kubelet
109+
scheme: https
110+
authorization:
111+
credentials_file: /var/run/secrets/kubernetes.io/serviceaccount/token
112+
tls_config:
113+
ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
114+
insecure_skip_verify: true
115+
honor_labels: true
116+
kubernetes_sd_configs:
117+
- role: node
118+
metric_relabel_configs:
119+
- action: keep
120+
regex: "kubelet_running_pods"
121+
source_labels: [__name__]
122+
123+
processors:
124+
125+
exporters:
126+
prometheus:
127+
endpoint: 0.0.0.0:9090
128+
service:
129+
pipelines:
130+
metrics:
131+
receivers: [prometheus]
132+
processors: []
133+
exporters: [prometheus]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
apiVersion: batch/v1
3+
kind: Job
4+
metadata:
5+
name: check-metrics
6+
spec:
7+
template:
8+
spec:
9+
restartPolicy: OnFailure
10+
containers:
11+
- name: check-metrics
12+
image: curlimages/curl
13+
args:
14+
- /bin/sh
15+
- -c
16+
- curl -s http://prometheus-kubernetessd-collector:9090/metrics | grep "kubelet_running_pods{"
17+
---
18+
apiVersion: batch/v1
19+
kind: Job
20+
metadata:
21+
name: check-ta-jobs
22+
spec:
23+
template:
24+
spec:
25+
restartPolicy: OnFailure
26+
containers:
27+
- name: check-metrics
28+
image: curlimages/curl
29+
args:
30+
- /bin/sh
31+
- -c
32+
- curl -s http://prometheus-kubernetessd-targetallocator/scrape_configs | grep "kubelet"
33+
---
34+
apiVersion: batch/v1
35+
kind: Job
36+
metadata:
37+
name: check-ta-scrape-configs
38+
spec:
39+
template:
40+
spec:
41+
restartPolicy: OnFailure
42+
containers:
43+
- name: check-metrics
44+
image: curlimages/curl
45+
args:
46+
- /bin/sh
47+
- -c
48+
# First get the collector pod name, subsequently check that the targets for the collector include the node name label.
49+
- curl -s http://prometheus-kubernetessd-targetallocator/jobs/kubelet/targets?collector_id=$(curl -s http://prometheus-kubernetessd-targetallocator/jobs/kubelet/targets | grep -oE "prometheus-kubernetessd-collector-.{5}") | grep "__meta_kubernetes_node_name"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# Name of the daemonset to check
4+
DAEMONSET_NAME="prometheus-kubernetessd-collector"
5+
6+
# Get the desired and ready pod counts for the daemonset
7+
read DESIRED READY <<< $(kubectl get daemonset -n $NAMESPACE $DAEMONSET_NAME -o custom-columns=:status.desiredNumberScheduled,:status.numberReady --no-headers)
8+
9+
# Check if the desired count matches the ready count
10+
if [ "$DESIRED" -eq "$READY" ]; then
11+
echo "Desired count ($DESIRED) matches the ready count ($READY) for $DAEMONSET_NAME."
12+
else
13+
echo "Desired count ($DESIRED) does not match the ready count ($READY) for $DAEMONSET_NAME."
14+
exit 1
15+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: check-metrics
5+
status:
6+
succeeded: 1
7+
---
8+
apiVersion: batch/v1
9+
kind: Job
10+
metadata:
11+
name: check-ta-jobs
12+
status:
13+
succeeded: 1
14+
---
15+
apiVersion: batch/v1
16+
kind: Job
17+
metadata:
18+
name: check-ta-scrape-configs
19+
status:
20+
succeeded: 1

0 commit comments

Comments
 (0)