Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Fix daemonset-features E2E test for OpenShift #1354

Merged
merged 1 commit into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I copied, pasted and adapted.

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