Skip to content

Commit 2c9a16e

Browse files
authored
Fix daemonset-features E2E test for OpenShift (open-telemetry#1354)
Signed-off-by: Israel Blancas <[email protected]>
1 parent f2dc678 commit 2c9a16e

10 files changed

+57
-6
lines changed

hack/install-metrics-server.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# you can just add --addons "metrics-server" to the start command.
66

77

8-
if [[ "$(kubectl api-resources)" =~ "openshift" ]]; then
8+
if [[ "$(kubectl api-resources --api-group=operator.openshift.io -o name)" ]]; then
99
echo "Connected to an OpenShift cluster. metrics-server installation is not needed"
1010
elif [[ "$(kubectl get deployment metrics-server -n kube-system 2>&1 )" =~ "NotFound" ]]; then
1111
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

hack/install-openshift-routes.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
if [[ "$(kubectl api-resources)" =~ "openshift" ]]; then
3+
if [[ "$(kubectl api-resources --api-group=operator.openshift.io -o name)" ]]; then
44
echo "Connected to an OpenShift cluster. OpenShift routes installation is not needed"
55
else
66
kubectl apply -f https://raw.githubusercontent.com/openshift/router/release-4.12/deploy/router_rbac.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
commands:
4+
- script: ./add-scc-openshift.sh

tests/e2e/daemonset-features/00-install.yaml tests/e2e/daemonset-features/01-install.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
apiVersion: opentelemetry.io/v1alpha1
22
kind: OpenTelemetryCollector
33
metadata:
4-
name: daemonset
4+
name: daemonset
55
spec:
6-
mode: daemonset
6+
mode: daemonset
77
hostNetwork: true
88
config: |
99
receivers:

tests/e2e/daemonset-features/00-assert.yaml tests/e2e/daemonset-features/02-assert.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,3 @@ spec:
1010
- args:
1111
- --config=/conf/collector.yaml
1212
name: otc-container
13-
status:
14-
numberReady: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
commands:
4+
- script: ./add-sa-collector.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: daemonset-collector
6+
app.kubernetes.io/part-of: opentelemetry
7+
status:
8+
phase: Running
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
if [[ "$(kubectl api-resources --api-group=operator.openshift.io -o name)" ]]; then
3+
echo "Adding service account to the OpenTelemetry Collector"
4+
kubectl patch otelcol daemonset --type=merge -p '{"spec":{"serviceAccount":"otel-collector-daemonset"}}' -n $NAMESPACE
5+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
if [[ "$(kubectl api-resources --api-group=operator.openshift.io -o name)" ]]; then
3+
echo "Running the test against an OpenShift Cluster"
4+
echo "Creating an Service Account"
5+
echo "Creating a Security Context Constrain"
6+
echo "Setting the Service Account for the Daemonset"
7+
echo "Adding the new policy to the Service Account"
8+
kubectl apply -f scc.yaml -n $NAMESPACE
9+
oc adm policy add-scc-to-user -z otel-collector-daemonset daemonset-with-hostport -n $NAMESPACE
10+
fi

tests/e2e/daemonset-features/scc.yaml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
kind: SecurityContextConstraints
2+
apiVersion: security.openshift.io/v1
3+
metadata:
4+
name: daemonset-with-hostport
5+
annotations:
6+
kubernetes.io/description: 'Allows DaemonSets to bind to a well-known host port'
7+
runAsUser:
8+
type: RunAsAny
9+
seLinuxContext:
10+
type: RunAsAny
11+
allowHostPorts: true
12+
allowHostDirVolumePlugin: false
13+
allowHostIPC: false
14+
allowHostNetwork: true
15+
allowHostPID: false
16+
allowPrivilegedContainer: false
17+
readOnlyRootFilesystem: false
18+
---
19+
apiVersion: v1
20+
kind: ServiceAccount
21+
metadata:
22+
name: otel-collector-daemonset

0 commit comments

Comments
 (0)