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

[Merged by Bors] - Added kuttl tests. #289

Closed
wants to merge 2 commits into from
Closed
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
- The command line argument `--watch-namespace` for the `run` subcommand or
the environment variable `WATCH_NAMESPACE` can be used to instruct the
operator to watch a particular namespace. ([#244])
- Added `kuttl` tests from `integration-test` repository ([#289])

### Changed

Expand All @@ -31,6 +32,7 @@ All notable changes to this project will be documented in this file.
[#252]: https://github.com/stackabletech/opa-operator/pull/252
[#273]: https://github.com/stackabletech/opa-operator/pull/273
[#287]: https://github.com/stackabletech/opa-operator/pull/287
[#289]: https://github.com/stackabletech/opa-operator/pull/289

## [0.8.0] - 2022-02-14

Expand Down
6 changes: 6 additions & 0 deletions tests/templates/kuttl/smoke/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
metadata:
name: install-opa
commands:
- script: kubectl -n $NAMESPACE rollout status daemonset test-opa-server-default --timeout 300s
31 changes: 31 additions & 0 deletions tests/templates/kuttl/smoke/01-install-opa.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: test
labels:
opa.stackable.tech/bundle: "true"
data:
test.rego: |
package test

hello {
true
}

world {
false
}
---
apiVersion: opa.stackable.tech/v1alpha1
kind: OpaCluster
metadata:
name: test-opa
spec:
version: {{ test_scenario['values']['opa'] }}
servers:
roleGroups:
default:
selector:
matchLabels:
kubernetes.io/os: linux
13 changes: 13 additions & 0 deletions tests/templates/kuttl/smoke/02-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
metadata:
name: test-regorule
timeout: 300
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: test-regorule
status:
readyReplicas: 1
replicas: 1
22 changes: 22 additions & 0 deletions tests/templates/kuttl/smoke/02-install-test-regorule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: test-regorule
labels:
app: test-regorule
spec:
replicas: 1
selector:
matchLabels:
app: test-regorule
template:
metadata:
labels:
app: test-regorule
spec:
containers:
- name: test-regorule
image: python:3.10-slim
stdin: true
tty: true
7 changes: 7 additions & 0 deletions tests/templates/kuttl/smoke/03-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
metadata:
name: test-regorule
commands:
- script: kubectl exec -n $NAMESPACE test-regorule-0 -- python /tmp/test-regorule.py -u 'http://test-opa-server-default:8081/v1/data/test'
6 changes: 6 additions & 0 deletions tests/templates/kuttl/smoke/03-prepare-test-regorule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: kubectl cp -n $NAMESPACE ./test-regorule.py test-regorule-0:/tmp
- script: kubectl cp -n $NAMESPACE ./requirements.txt test-regorule-0:/tmp
- script: kubectl exec -n $NAMESPACE test-regorule-0 -- pip install --user -r /tmp/requirements.txt
1 change: 1 addition & 0 deletions tests/templates/kuttl/smoke/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests==2.27.1
37 changes: 37 additions & 0 deletions tests/templates/kuttl/smoke/test-regorule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python
import requests
import argparse


if __name__ == "__main__":
all_args = argparse.ArgumentParser()
all_args.add_argument("-u", "--url", required=True, help="OPA service url")
args = vars(all_args.parse_args())

# rego rule to check (compare: 01-install-opa.yaml)
# ---
# package test
#
# hello {
# true
# }
#
# world {
# false
# }
# ---
# We need to query: http://<host>:<port>/v1/data/<package>/(<rule>)+
# In our case http://<host>:8081/v1/data/test
# --> {'result': {'hello': True}}
# or http://<host>:8081/v1/data/test/hello
# --> {'hello': True}

#url = 'http://test-opa-svc:8081/v1/data/test'
response = requests.post(args['url']).json()

if "result" in response and "hello" in response["result"] and response["result"]["hello"]:
print("Test successful!")
exit(0)
else:
print("Error: received " + str(response) + " - expected: {'result': {'hello': True}}")
exit(-1)
9 changes: 9 additions & 0 deletions tests/test-definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
dimensions:
- name: opa
values:
- 0.37.2
tests:
- name: smoke
dimensions:
- opa