Skip to content

Commit 51c27cc

Browse files
committed
Fix flaky target allocator tests
We had a race condition where concurrently running tests used the same ClusterRole name with different RBAC permissions.
1 parent 02e44fb commit 51c27cc

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

tests/e2e-targetallocator/targetallocator-features/00-install.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ automountServiceAccountToken: true
77
apiVersion: rbac.authorization.k8s.io/v1
88
kind: ClusterRole
99
metadata:
10-
name: pod-view
10+
name: targetallocator-features
1111
rules:
1212
- apiGroups: [""]
1313
resources: [ "pods", "namespaces" ]
@@ -19,7 +19,7 @@ rules:
1919
apiVersion: kuttl.dev/v1beta1
2020
kind: TestStep
2121
commands:
22-
- command: kubectl -n $NAMESPACE create clusterrolebinding default-view-$NAMESPACE --clusterrole=pod-view --serviceaccount=$NAMESPACE:ta
22+
- command: kubectl -n $NAMESPACE create clusterrolebinding default-view-$NAMESPACE --clusterrole=targetallocator-features --serviceaccount=$NAMESPACE:ta
2323
# Annotate the namespace to allow the application to run using an specific group and user in OpenShift
2424
# https://docs.openshift.com/dedicated/authentication/managing-security-context-constraints.html
2525
# This annotation has no effect in Kubernetes

tests/e2e-targetallocator/targetallocator-kubernetessd/00-install.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ automountServiceAccountToken: true
1313
apiVersion: rbac.authorization.k8s.io/v1
1414
kind: ClusterRole
1515
metadata:
16-
name: ta
16+
name: targetallocator-kubernetessd
1717
rules:
1818
- apiGroups: [""]
1919
resources:
@@ -58,7 +58,7 @@ rules:
5858
apiVersion: rbac.authorization.k8s.io/v1
5959
kind: ClusterRole
6060
metadata:
61-
name: collector
61+
name: collector-kubernetessd
6262
rules:
6363
- apiGroups: [""]
6464
resources:
@@ -84,8 +84,8 @@ rules:
8484
apiVersion: kuttl.dev/v1beta1
8585
kind: TestStep
8686
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
87+
- command: kubectl create clusterrolebinding ta-$NAMESPACE --clusterrole=targetallocator-kubernetessd --serviceaccount=$NAMESPACE:ta
88+
- command: kubectl create clusterrolebinding collector-$NAMESPACE --clusterrole=collector-kubernetessd --serviceaccount=$NAMESPACE:collector
8989
---
9090
apiVersion: opentelemetry.io/v1alpha1
9191
kind: OpenTelemetryCollector

tests/e2e-targetallocator/targetallocator-kubernetessd/01-install.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ spec:
1313
args:
1414
- /bin/sh
1515
- -c
16-
- curl -s http://prometheus-kubernetessd-collector:9090/metrics | grep "kubelet_running_pods{"
16+
- |
17+
for i in $(seq 30); do
18+
if curl -m 1 -s http://prometheus-kubernetessd-collector:9090/metrics | grep "kubelet_running_pods"; then exit 0; fi
19+
sleep 5
20+
done
21+
exit 1
1722
---
1823
apiVersion: batch/v1
1924
kind: Job

tests/e2e-targetallocator/targetallocator-prometheuscr/00-install.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ automountServiceAccountToken: true
1313
apiVersion: rbac.authorization.k8s.io/v1
1414
kind: ClusterRole
1515
metadata:
16-
name: ta
16+
name: targetallocator-prometheuscr
1717
rules:
1818
- apiGroups: [""]
1919
resources:
@@ -65,7 +65,7 @@ rules:
6565
apiVersion: rbac.authorization.k8s.io/v1
6666
kind: ClusterRole
6767
metadata:
68-
name: collector
68+
name: collector-prometheuscr
6969
rules:
7070
- apiGroups: [""]
7171
resources:
@@ -92,8 +92,8 @@ rules:
9292
apiVersion: kuttl.dev/v1beta1
9393
kind: TestStep
9494
commands:
95-
- command: kubectl create clusterrolebinding ta-$NAMESPACE --clusterrole=ta --serviceaccount=$NAMESPACE:ta
96-
- command: kubectl create clusterrolebinding collector-$NAMESPACE --clusterrole=collector --serviceaccount=$NAMESPACE:collector
95+
- command: kubectl create clusterrolebinding ta-$NAMESPACE --clusterrole=targetallocator-prometheuscr --serviceaccount=$NAMESPACE:ta
96+
- command: kubectl create clusterrolebinding collector-$NAMESPACE --clusterrole=collector-prometheuscr --serviceaccount=$NAMESPACE:collector
9797
---
9898
apiVersion: opentelemetry.io/v1alpha1
9999
kind: OpenTelemetryCollector

0 commit comments

Comments
 (0)