Skip to content

Commit

Permalink
Fix daemonset-features E2E test for OpenShift
Browse files Browse the repository at this point in the history
Signed-off-by: Israel Blancas <iblancasa@gmail.com>
  • Loading branch information
iblancasa committed Feb 1, 2023
1 parent 55c37bc commit 16467ec
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 6 deletions.
2 changes: 1 addition & 1 deletion hack/install-metrics-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# you can just add --addons "metrics-server" to the start command.


if [[ "$(kubectl api-resources)" =~ "openshift" ]]; then
if [[ "$(kubectl api-resources --api-group=operator.openshift.io -o name)" ]]; then
echo "Connected to an OpenShift cluster. metrics-server installation is not needed"
elif [[ "$(kubectl get deployment metrics-server -n kube-system 2>&1 )" =~ "NotFound" ]]; then
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
Expand Down
2 changes: 1 addition & 1 deletion hack/install-openshift-routes.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

if [[ "$(kubectl api-resources)" =~ "openshift" ]]; then
if [[ "$(kubectl api-resources --api-group=operator.openshift.io -o name)" ]]; then
echo "Connected to an OpenShift cluster. OpenShift routes installation is not needed"
else
kubectl apply -f https://raw.githubusercontent.com/openshift/router/release-4.12/deploy/router_rbac.yaml
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/daemonset-features/00-add-scc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: ./add-scc-openshift.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: opentelemetry.io/v1alpha1
kind: OpenTelemetryCollector
metadata:
name: daemonset
name: daemonset
spec:
mode: daemonset
mode: daemonset
hostNetwork: true
config: |
receivers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ spec:
- args:
- --config=/conf/collector.yaml
name: otc-container
status:
numberReady: 1
4 changes: 4 additions & 0 deletions tests/e2e/daemonset-features/03-add-sa-collector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: ./add-sa-collector.sh
8 changes: 8 additions & 0 deletions tests/e2e/daemonset-features/03-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Pod
metadata:
labels:
app.kubernetes.io/name: daemonset-collector
app.kubernetes.io/part-of: opentelemetry
status:
phase: Running
5 changes: 5 additions & 0 deletions tests/e2e/daemonset-features/add-sa-collector.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
if [[ "$(kubectl api-resources --api-group=operator.openshift.io -o name)" ]]; then
echo "Adding service account to the OpenTelemetry Collector"
kubectl patch otelcol daemonset --type=merge -p '{"spec":{"serviceAccount":"otel-collector-daemonset"}}' -n $NAMESPACE
fi
10 changes: 10 additions & 0 deletions tests/e2e/daemonset-features/add-scc-openshift.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
if [[ "$(kubectl api-resources --api-group=operator.openshift.io -o name)" ]]; then
echo "Running the test against an OpenShift Cluster"
echo "Creating an Service Account"
echo "Creating a Security Context Constrain"
echo "Setting the Service Account for the Daemonset"
echo "Adding the new policy to the Service Account"
kubectl apply -f scc.yaml -n $NAMESPACE
oc adm policy add-scc-to-user -z otel-collector-daemonset daemonset-with-hostport -n $NAMESPACE
fi
22 changes: 22 additions & 0 deletions tests/e2e/daemonset-features/scc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
kind: SecurityContextConstraints
apiVersion: security.openshift.io/v1
metadata:
name: daemonset-with-hostport
annotations:
kubernetes.io/description: 'Allows DaemonSets to bind to a well-known host port'
runAsUser:
type: RunAsAny
seLinuxContext:
type: RunAsAny
allowHostPorts: true
allowHostDirVolumePlugin: false
allowHostIPC: false
allowHostNetwork: true
allowHostPID: false
allowPrivilegedContainer: false
readOnlyRootFilesystem: false
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: otel-collector-daemonset

0 comments on commit 16467ec

Please sign in to comment.