Skip to content

Commit 7c5ac95

Browse files
test(metrics): Fix the test on OpenShift for long namespace names
1 parent 0e7ef58 commit 7c5ac95

3 files changed

Lines changed: 25 additions & 18 deletions

File tree

tests/templates/kuttl/metrics/01-rbac.yaml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
apiVersion: kuttl.dev/v1beta1
33
kind: TestStep
44
commands:
5-
- script: >
6-
envsubst '$NAMESPACE' < 01_rbac.yaml |
7-
kubectl apply -n $NAMESPACE -f -
5+
- script: |
6+
PROMETHEUS_HELM_RELEASE_NAME=prometheus-$NAMESPACE
7+
PROMETHEUS_HELM_CHART_NAME=kube-prometheus-stack
8+
9+
# `kube-prometheus-stack.fullname` in the Prometheus Helm Chart is used to create the
10+
# ServiceAccount names. It is set to `<.Release.Name>-<.Chart.Name>` and truncated to
11+
# 26 characters, see
12+
# https://github.com/prometheus-community/helm-charts/blob/kube-prometheus-stack-81.2.2/charts/kube-prometheus-stack/templates/_helpers.tpl#L22
13+
KUBE_PROMETHEUS_STACK_FULLNAME=$PROMETHEUS_HELM_RELEASE_NAME-$PROMETHEUS_HELM_CHART_NAME
14+
export KUBE_PROMETHEUS_STACK_FULLNAME=${KUBE_PROMETHEUS_STACK_FULLNAME:0:26}
15+
16+
envsubst '$KUBE_PROMETHEUS_STACK_FULLNAME' < 01_rbac.yaml | \
17+
kubectl apply --namespace=$NAMESPACE --filename=-

tests/templates/kuttl/metrics/01_rbac.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ rules:
1818
verbs:
1919
- use
2020
---
21-
# `fullnameOverride` in the Prometheus Helm values must be set to `prometheus-$NAMESPACE`, so that
22-
# the ServiceAccounts are created with the names listed in this RoleBinding.
2321
kind: RoleBinding
2422
apiVersion: rbac.authorization.k8s.io/v1
2523
metadata:
@@ -28,11 +26,11 @@ subjects:
2826
- kind: ServiceAccount
2927
name: test-service-account
3028
- kind: ServiceAccount
31-
name: prometheus-$NAMESPACE-admission
29+
name: $KUBE_PROMETHEUS_STACK_FULLNAME-admission
3230
- kind: ServiceAccount
33-
name: prometheus-$NAMESPACE-operator
31+
name: $KUBE_PROMETHEUS_STACK_FULLNAME-operator
3432
- kind: ServiceAccount
35-
name: prometheus-$NAMESPACE-prometheus
33+
name: $KUBE_PROMETHEUS_STACK_FULLNAME-prometheus
3634
roleRef:
3735
apiGroup: rbac.authorization.k8s.io
3836
kind: Role

tests/templates/kuttl/metrics/10-install-prometheus.yaml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ apiVersion: kuttl.dev/v1beta1
33
kind: TestStep
44
commands:
55
# Append the namespace to the Helm release name so that cluster-wide resources get unique names.
6-
# `fullnameOverride` is set to `prometheus-$NAMESPACE`, so that the ServiceAccounts are created
7-
# with the names that are defined in `test-role-binding`.
8-
- script: >
9-
helm install prometheus-$NAMESPACE
10-
--namespace $NAMESPACE
11-
--version 80.14.2
12-
--values 10_kube-prometheus-stack-values.yaml
13-
--set fullnameOverride=prometheus-$NAMESPACE
14-
--wait
15-
oci://ghcr.io/prometheus-community/charts/kube-prometheus-stack
6+
- script: |
7+
PROMETHEUS_HELM_RELEASE_NAME=prometheus-$NAMESPACE
8+
9+
helm install $PROMETHEUS_HELM_RELEASE_NAME \
10+
--namespace $NAMESPACE \
11+
--version 81.2.2 \
12+
--values 10_kube-prometheus-stack-values.yaml \
13+
--wait \
14+
oci://ghcr.io/prometheus-community/charts/kube-prometheus-stack
1615
timeout: 600

0 commit comments

Comments
 (0)