Skip to content

Commit ee64394

Browse files
committed
feat: test OPA using HTTP in smoke test as well
1 parent 2897872 commit ee64394

9 files changed

Lines changed: 98 additions & 23 deletions

File tree

tests/templates/kuttl/smoke/10-assert.yaml.j2

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,42 @@ apiVersion: kuttl.dev/v1beta1
22
kind: TestAssert
33
timeout: 300
44
commands:
5-
- script: kubectl -n $NAMESPACE wait --for=condition=available opaclusters.opa.stackable.tech/test-opa --timeout 301s
5+
- script: kubectl -n $NAMESPACE wait --for=condition=available opaclusters.opa.stackable.tech/test-opa-https --timeout 301s
6+
- script: kubectl -n $NAMESPACE wait --for=condition=available opaclusters.opa.stackable.tech/test-opa-http --timeout 301s
67
---
78
apiVersion: apps/v1
89
kind: DaemonSet
910
metadata:
10-
name: test-opa-server-default
11+
name: test-opa-https-server-default
12+
spec:
13+
template:
14+
spec:
15+
containers:
16+
- name: opa
17+
resources:
18+
limits:
19+
cpu: 500m
20+
memory: 256Mi
21+
requests:
22+
cpu: 250m
23+
memory: 256Mi
24+
- name: bundle-builder
25+
resources:
26+
limits:
27+
cpu: 200m
28+
memory: 128Mi
29+
requests:
30+
cpu: 100m
31+
memory: 128Mi
32+
{% if lookup('env', 'VECTOR_AGGREGATOR') %}
33+
- name: vector
34+
{% endif %}
35+
terminationGracePeriodSeconds: 125 # 2 minutes + 5s safety buffer
36+
---
37+
apiVersion: apps/v1
38+
kind: DaemonSet
39+
metadata:
40+
name: test-opa-http-server-default
1141
spec:
1242
template:
1343
spec:

tests/templates/kuttl/smoke/10-install-opa.yaml.j2

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ data:
2020
apiVersion: opa.stackable.tech/v1alpha1
2121
kind: OpaCluster
2222
metadata:
23-
name: test-opa
23+
name: test-opa-https
2424
spec:
2525
image:
2626
{% if test_scenario['values']['opa'].find(",") > 0 %}
@@ -46,3 +46,31 @@ spec:
4646
default:
4747
envOverrides:
4848
SERVER_ROLE_GROUP_LEVEL_ENV_VAR: "SERVER_ROLE_GROUP_LEVEL_ENV_VAR"
49+
---
50+
apiVersion: opa.stackable.tech/v1alpha1
51+
kind: OpaCluster
52+
metadata:
53+
name: test-opa-http
54+
spec:
55+
image:
56+
{% if test_scenario['values']['opa'].find(",") > 0 %}
57+
custom: "{{ test_scenario['values']['opa'].split(',')[1] }}"
58+
productVersion: "{{ test_scenario['values']['opa'].split(',')[0] }}"
59+
{% else %}
60+
productVersion: "{{ test_scenario['values']['opa'] }}"
61+
{% endif %}
62+
pullPolicy: IfNotPresent
63+
clusterConfig:
64+
{% if lookup('env', 'VECTOR_AGGREGATOR') %}
65+
vectorAggregatorConfigMapName: vector-aggregator-discovery
66+
{% endif %}
67+
servers:
68+
config:
69+
logging:
70+
enableVectorAgent: {{ lookup('env', 'VECTOR_AGGREGATOR') | length > 0 }}
71+
envOverrides:
72+
SERVER_ROLE_LEVEL_ENV_VAR: "SERVER_ROLE_LEVEL_ENV_VAR"
73+
roleGroups:
74+
default:
75+
envOverrides:
76+
SERVER_ROLE_GROUP_LEVEL_ENV_VAR: "SERVER_ROLE_GROUP_LEVEL_ENV_VAR"

tests/templates/kuttl/smoke/11-assert.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ kind: TestAssert
55
timeout: 600
66
commands:
77
- script: |
8-
FIRST_OPA_POD=$(kubectl get -n $NAMESPACE pods --field-selector=status.phase=Running --selector app.kubernetes.io/instance=test-opa -o jsonpath='{.items[0].metadata.name}')
8+
FIRST_OPA_POD=$(kubectl get -n $NAMESPACE pods --field-selector=status.phase=Running --selector app.kubernetes.io/instance=test-opa-https -o jsonpath='{.items[0].metadata.name}')
9+
kubectl exec -n $NAMESPACE --container opa $FIRST_OPA_POD -- cat /stackable/log/containerdebug-state.json | jq --exit-status '"valid JSON"'
10+
- script: |
11+
FIRST_OPA_POD=$(kubectl get -n $NAMESPACE pods --field-selector=status.phase=Running --selector app.kubernetes.io/instance=test-opa-http -o jsonpath='{.items[0].metadata.name}')
912
kubectl exec -n $NAMESPACE --container opa $FIRST_OPA_POD -- cat /stackable/log/containerdebug-state.json | jq --exit-status '"valid JSON"'

tests/templates/kuttl/smoke/20-assert.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ metadata:
99
name: test-opa
1010
status:
1111
readyReplicas: 1
12-
replicas: 1
12+
replicas: 1

tests/templates/kuttl/smoke/30-assert.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ kind: TestAssert
44
metadata:
55
name: test-regorule
66
commands:
7-
- script: kubectl exec -n $NAMESPACE test-opa-0 -- python /tmp/30_test-regorule.py -u "https://test-opa-server.$NAMESPACE.svc.cluster.local:8443/v1/data/test"
7+
- script: kubectl exec -n $NAMESPACE test-opa-0 -- python /tmp/30_test-regorule.py -u "https://test-opa-https-server.$NAMESPACE.svc.cluster.local:8443/v1/data/test"
8+
- script: kubectl exec -n $NAMESPACE test-opa-0 -- python /tmp/30_test-regorule.py -u "http://test-opa-http-server.$NAMESPACE.svc.cluster.local:8081/v1/data/test"

tests/templates/kuttl/smoke/30_test-metrics.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44

55
if __name__ == "__main__":
66
all_args = argparse.ArgumentParser()
7-
all_args.add_argument(
8-
"-n", "--namespace", required=True, help="Kubernetes namespace"
9-
)
7+
all_args.add_argument("-u", "--url", required=True, help="OPA metrics url")
108
args = vars(all_args.parse_args())
119

12-
namespace = args["namespace"]
13-
metrics_url = f"https://test-opa-server-default-metrics.{namespace}.svc.cluster.local:8443/metrics"
10+
metrics_url = args["url"]
11+
12+
# Determine verification setting based on whether TLS is used
13+
if metrics_url.startswith("http://"):
14+
verify = False
15+
protocol = "HTTP"
16+
else:
17+
verify = "/tls/ca.crt"
18+
protocol = "HTTPS"
1419

15-
# Use the CA certificate for verification
16-
response = requests.get(metrics_url, verify="/tls/ca.crt")
20+
response = requests.get(metrics_url, verify=verify)
1721

1822
assert response.status_code == 200, "Metrics endpoint must return a 200 status code"
1923
assert "bundle_loaded_counter" in response.text, (
2024
f"Metric bundle_loaded_counter should exist in {metrics_url}"
2125
)
22-
print("Metrics test successful!")
26+
print(f"Metrics test ({protocol}) successful!")

tests/templates/kuttl/smoke/30_test-regorule.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,28 @@
2525
# --> {'result': {'hello': True}}
2626
# or https://<host>:8443/v1/data/test/hello
2727
# --> {'hello': True}
28+
# For HTTP: http://<host>:8081/v1/data/test
2829

29-
# url = 'https://test-opa-server.<namespace>.svc.cluster.local:8443/v1/data/test'
30-
response = requests.post(
31-
args["url"], json={"input": {}}, verify="/tls/ca.crt"
32-
).json()
30+
# Determine verification setting based on whether TLS is used
31+
if args["url"].startswith("http://"):
32+
verify = False
33+
protocol = "HTTP"
34+
else:
35+
verify = "/tls/ca.crt"
36+
protocol = "HTTPS"
37+
38+
response = requests.post(args["url"], json={"input": {}}, verify=verify).json()
3339

3440
if (
3541
"result" in response
3642
and "hello" in response["result"]
3743
and response["result"]["hello"]
3844
):
39-
print("Regorule test successful!")
45+
print(f"Regorule test ({protocol}) successful!")
4046
exit(0)
4147
else:
4248
print(
43-
"Error: received "
49+
f"Error ({protocol}): received "
4450
+ str(response)
4551
+ " - expected: {'result': {'hello': True}}"
4652
)

tests/templates/kuttl/smoke/31-assert.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ kind: TestAssert
44
metadata:
55
name: test-metrics
66
commands:
7-
- script: kubectl exec -n $NAMESPACE test-opa-0 -- python /tmp/30_test-metrics.py -n $NAMESPACE
7+
- script: kubectl exec -n $NAMESPACE test-opa-0 -- python /tmp/30_test-metrics.py -u "https://test-opa-https-server-default-metrics.$NAMESPACE.svc.cluster.local:8443/metrics"
8+
- script: kubectl exec -n $NAMESPACE test-opa-0 -- python /tmp/30_test-metrics.py -u "http://test-opa-http-server-default-metrics.$NAMESPACE.svc.cluster.local:8081/metrics"

tests/templates/kuttl/smoke/32-assert.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ metadata:
55
name: test-env-overrides
66
commands:
77
# Role level env var
8-
- script: kubectl exec -n $NAMESPACE -c opa svc/test-opa-server -- env | grep SERVER_ROLE_LEVEL_ENV_VAR
8+
- script: kubectl exec -n $NAMESPACE -c opa svc/test-opa-https-server -- env | grep SERVER_ROLE_LEVEL_ENV_VAR
9+
- script: kubectl exec -n $NAMESPACE -c opa svc/test-opa-http-server -- env | grep SERVER_ROLE_LEVEL_ENV_VAR
910
# RoleGroup level env var
10-
- script: kubectl exec -n $NAMESPACE -c opa svc/test-opa-server -- env | grep SERVER_ROLE_GROUP_LEVEL_ENV_VAR
11+
- script: kubectl exec -n $NAMESPACE -c opa svc/test-opa-https-server -- env | grep SERVER_ROLE_GROUP_LEVEL_ENV_VAR
12+
- script: kubectl exec -n $NAMESPACE -c opa svc/test-opa-http-server -- env | grep SERVER_ROLE_GROUP_LEVEL_ENV_VAR

0 commit comments

Comments
 (0)