Skip to content

Commit

Permalink
feat(test): substitute kuttl to bash e2e test (#411)
Browse files Browse the repository at this point in the history
Signed-off-by: realanna <anna.reale@dynatrace.com>
  • Loading branch information
RealAnna authored Mar 23, 2023
1 parent 2a86b03 commit ff199f1
Show file tree
Hide file tree
Showing 11 changed files with 316 additions and 3 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ on:
env:
# Default minimum version of Go to support.
DEFAULT_GO_VERSION: 1.19
# renovate: datasource=github-tags depName=kudobuilder/kuttl
KUTTL_VERSION: "v0.15.0"

permissions:
contents: read
Expand Down Expand Up @@ -168,13 +170,18 @@ jobs:
with:
config: ./test/e2e/kind-cluster.yml
cluster_name: open-feature-operator-test
- name: Download KUTTL
run: |
curl -fL https://github.com/kudobuilder/kuttl/releases/download/${{ env.KUTTL_VERSION }}/kubectl-kuttl_${KUTTL_VERSION#v}_linux_x86_64 -o kubectl-kuttl
chmod +x kubectl-kuttl
mv kubectl-kuttl /usr/local/bin
- name: Load open-feature-operator image into Kind cluster
run: |
kind load docker-image open-feature-operator-local:${{ github.sha }} --name open-feature-operator-test
- name: Run e2e test
run: |
IMG=open-feature-operator-local:${{ github.sha }} make deploy-operator
IMG=open-feature-operator-local:${{ github.sha }} make e2e-test
IMG=open-feature-operator-local:${{ github.sha }} make e2e-test-kuttl
- name: Create reports
if: always()
working-directory: ./.github/scripts
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ e2e-test: manifests generate fmt vet
kubectl wait --for=condition=Available=True deploy --all -n 'open-feature-operator-system'
./test/e2e/run.sh

.PHONY: e2e-test-kuttl #these tests should run on a real cluster!
e2e-test-kuttl:
kubectl kuttl test --start-kind=false ./test/e2e/kuttl --config=./kuttl-test.yaml

.PHONY: e2e-test-kuttl-local #these tests should run on a real cluster!
e2e-test-kuttl-local:
kubectl kuttl test --start-kind=false ./test/e2e/kuttl/scenarios --config=./kuttl-test-local.yaml

.PHONY: lint
lint:
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest
Expand Down
2 changes: 0 additions & 2 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
resources:
- manager.yaml

generatorOptions:
disableNameSuffixHash: true

configMapGenerator:
- files:
- controller_manager_config.yaml
Expand Down
6 changes: 6 additions & 0 deletions kuttl-test-local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1
kind: TestSuite
crdDir: ./config/crd/bases
testDirs:
- ./test/e2e/kuttl/scenarios/
timeout: 300
7 changes: 7 additions & 0 deletions kuttl-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: kuttl.dev/v1
kind: TestSuite
crdDir: ./config/crd/bases
testDirs:
- ./test/e2e/kuttl/scenarios/
timeout: 150
skipDelete: true
9 changes: 9 additions & 0 deletions test/e2e/kuttl/flagd-disabled/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: batch/v1
kind: Job
metadata:
name: flagd-query-test
status:
conditions:
- type: Complete
status: 'True' #this ensures flagd is running
succeeded: 1
117 changes: 117 additions & 0 deletions test/e2e/kuttl/flagd-disabled/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# This configuration deploys the means to test the mutating injection webhook by proxying through an nginx server
# to assert that flagd is reachable
---
apiVersion: core.openfeature.dev/v1alpha1
kind: FeatureFlagConfiguration
metadata:
name: end-to-end-test
spec:
featureFlagSpec: |
{
"flags": {
"simple-flag": {
"state": "ENABLED",
"variants": {
"on": true,
"off": false
},
"defaultVariant": "on"
}
}
}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: open-feature-e2e-test-sa
automountServiceAccountToken: true
---
apiVersion: v1
kind: ConfigMap
metadata:
name: open-feature-e2e-nginx-conf
data:
nginx.conf: |
events {}
http {
server {
location / {
proxy_pass http://127.0.0.1:8013;
}
}
}
---
# Deployment of nginx using our custom resource
apiVersion: apps/v1
kind: Deployment
metadata:
name: open-feature-e2e-test-deployment
labels:
app: open-feature-e2e-test
spec:
replicas: 1
selector:
matchLabels:
app: open-feature-e2e-test
template:
metadata:
annotations:
openfeature.dev/enabled: "false"
labels:
app: open-feature-e2e-test
spec:
serviceAccountName: open-feature-e2e-test-sa
volumes:
- name: open-feature-e2e-nginx-conf
configMap:
name: open-feature-e2e-nginx-conf
items:
- key: nginx.conf
path: nginx.conf
containers:
- name: open-feature-e2e-test
image: nginx:stable-alpine
ports:
- containerPort: 80
volumeMounts:
- name: open-feature-e2e-nginx-conf
mountPath: /etc/nginx
readOnly: true
---
# Service exposed using NodePort
apiVersion: v1
kind: Service
metadata:
name: open-feature-e2e-failtest-service
spec:
type: ClusterIP
selector:
app: open-feature-e2e-test
ports:
- protocol: TCP
port: 40000
targetPort: 80
---
apiVersion: batch/v1
kind: Job
metadata:
name: flagd-query-test
spec:
backoffLimit: 5
template:
spec:
containers:
- name: test-flagd-endpoint
image: curlimages/curl:7.72.0
args:
- /bin/sh
- -ec
- |
STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST "open-feature-e2e-failtest-service:40000/schema.v1.Service/ResolveBoolean" -d "{\"flagKey\":\"simple-flag\",\"context\":{}}" -H "Content-Type: application/json")
if [ "$STATUS_CODE" -eq 200 ]; then
echo "Expected curl to nginx reverse proxy to return non 200 status code when openfeature.dev/enabled annotation is false."
exit 1
fi
exit 0
restartPolicy: Never
11 changes: 11 additions & 0 deletions test/e2e/kuttl/flagd-disabled/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Pod
metadata:
labels:
app: open-feature-e2e-test
status:
phase: Running
spec:
containers:
- name: open-feature-e2e-test
image: nginx:stable-alpine
10 changes: 10 additions & 0 deletions test/e2e/kuttl/inject-flagd/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: batch/v1
kind: Job
metadata:
name: flagd-query-test
status:
conditions:
- type: Complete
status: 'True' #this ensures flagd is running
succeeded: 1

123 changes: 123 additions & 0 deletions test/e2e/kuttl/inject-flagd/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# This configuration deploys the means to test the mutating injection webhook by proxying through an nginx server
# to assert that flagd is reachable
---
apiVersion: core.openfeature.dev/v1alpha1
kind: FeatureFlagConfiguration
metadata:
name: end-to-end-test
spec:
featureFlagSpec: |
{
"flags": {
"simple-flag": {
"state": "ENABLED",
"variants": {
"on": true,
"off": false
},
"defaultVariant": "on"
}
}
}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: open-feature-e2e-test-sa
automountServiceAccountToken: true
---
apiVersion: v1
kind: ConfigMap
metadata:
name: open-feature-e2e-nginx-conf
data:
nginx.conf: |
events {}
http {
server {
location / {
proxy_pass http://127.0.0.1:8013;
}
}
}
---
# Deployment of nginx using our custom resource
apiVersion: apps/v1
kind: Deployment
metadata:
name: open-feature-e2e-test-deployment
labels:
app: open-feature-e2e-test
spec:
replicas: 1
selector:
matchLabels:
app: open-feature-e2e-test
template:
metadata:
labels:
app: open-feature-e2e-test
annotations:
openfeature.dev/enabled: "true"
openfeature.dev/featureflagconfiguration: "end-to-end-test"
spec:
serviceAccountName: open-feature-e2e-test-sa
volumes:
- name: open-feature-e2e-nginx-conf
configMap:
name: open-feature-e2e-nginx-conf
items:
- key: nginx.conf
path: nginx.conf
containers:
- name: open-feature-e2e-test
image: nginx:stable-alpine
ports:
- containerPort: 80
volumeMounts:
- name: open-feature-e2e-nginx-conf
mountPath: /etc/nginx
readOnly: true
---
# Service exposed using NodePort
apiVersion: v1
kind: Service
metadata:
name: open-feature-e2e-test-service
spec:
type: ClusterIP
selector:
app: open-feature-e2e-test
ports:
- protocol: TCP
port: 30000
targetPort: 80
---
apiVersion: batch/v1
kind: Job
metadata:
name: flagd-query-test
spec:
backoffLimit: 5
template:
spec:
containers:
- name: test-flagd-endpoint
image: curlimages/curl:7.72.0
args:
- /bin/sh
- -ec
- |
EXPECTED_RESPONSE='{"value":true,"reason":"STATIC","variant":"on"}'
RESPONSE=$(curl -s -X POST "open-feature-e2e-test-service:30000/schema.v1.Service/ResolveBoolean" -d '{"flagKey":"simple-flag","context":{}}' -H "Content-Type: application/json")
RESPONSE="${RESPONSE//[[:space:]]/}" # strip whitespace from response
if [ "$RESPONSE" == "$EXPECTED_RESPONSE" ]
then
exit 0
fi
echo "Expected response: $EXPECTED_RESPONSE"
echo "Got response: $RESPONSE"
exit 1
restartPolicy: Never
17 changes: 17 additions & 0 deletions test/e2e/kuttl/inject-flagd/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Pod
metadata:
annotations:
openfeature.dev/allowkubernetessync: "true"
openfeature.dev/enabled: "true"
openfeature.dev/featureflagconfiguration: end-to-end-test
labels:
app: open-feature-e2e-test
status:
phase: Running
spec:
containers:
- name: open-feature-e2e-test
image: nginx:stable-alpine
- name: flagd # this part verifies flagd injection happened
image: ghcr.io/open-feature/flagd:v0.4.4

0 comments on commit ff199f1

Please sign in to comment.