Skip to content

Commit 8dcfb84

Browse files
test: Extend snapshot-s3 test with complete backup and restore
1 parent 436c864 commit 8dcfb84

23 files changed

Lines changed: 1082 additions & 59 deletions

tests/templates/kuttl/snapshot-s3/10-install-s3-credentials-secret.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ kind: Secret
44
metadata:
55
name: s3-credentials
66
stringData:
7-
s3.client.default.access_key: opensearchAccessKey
8-
s3.client.default.secret_key: opensearchSecretKey
7+
s3.client.default.access_key: openSearchAccessKey
8+
s3.client.default.secret_key: openSearchSecretKey

tests/templates/kuttl/snapshot-s3/11-install-minio.yaml.j2 renamed to tests/templates/kuttl/snapshot-s3/11-install-minio.yaml

File renamed without changes.

tests/templates/kuttl/snapshot-s3/11_minio-values.yaml.j2 renamed to tests/templates/kuttl/snapshot-s3/11_minio-values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ persistence:
2525
provisioning:
2626
enabled: true
2727
buckets:
28-
- name: opensearch
28+
- name: opensearch-data
2929
users:
3030
- username: integrationtest
3131
password: integrationtest

tests/templates/kuttl/snapshot-s3/20-assert.yaml.j2 renamed to tests/templates/kuttl/snapshot-s3/20-assert.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ timeout: 600
66
apiVersion: apps/v1
77
kind: StatefulSet
88
metadata:
9-
name: opensearch-nodes-default
9+
name: opensearch-1-nodes-default
1010
status:
1111
readyReplicas: 1
1212
replicas: 1

tests/templates/kuttl/snapshot-s3/20-install-opensearch.yaml.j2 renamed to tests/templates/kuttl/snapshot-s3/20-install-opensearch-1.yaml.j2

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
apiVersion: opensearch.stackable.tech/v1alpha1
33
kind: OpenSearchCluster
44
metadata:
5-
name: opensearch
5+
name: opensearch-1
66
spec:
77
image:
88
{% if test_scenario['values']['opensearch'].find(",") > 0 %}
@@ -33,6 +33,9 @@ spec:
3333
# not be created even if enough disk space would be available.
3434
cluster.routing.allocation.disk.threshold_enabled: "false"
3535
plugins.security.allow_default_init_securityindex: "true"
36+
# TODO This is insecure. Use a proper certificate!
37+
plugins.security.authcz.admin_dn: CN=generated certificate for pod
38+
plugins.security.restapi.roles_enabled: all_access
3639
plugins.security.ssl.transport.enabled: "true"
3740
plugins.security.ssl.transport.pemcert_filepath: /stackable/opensearch/config/tls/tls.crt
3841
plugins.security.ssl.transport.pemkey_filepath: /stackable/opensearch/config/tls/tls.key
@@ -127,7 +130,7 @@ spec:
127130
defaultMode: 0o660
128131
- name: security-config
129132
secret:
130-
secretName: opensearch-security-config
133+
secretName: opensearch-1-security-config
131134
defaultMode: 0o660
132135
- name: system-trust-store
133136
emptyDir:
@@ -137,7 +140,7 @@ spec:
137140
volumeClaimTemplate:
138141
metadata:
139142
annotations:
140-
secrets.stackable.tech/scope: node,pod,service=opensearch,service=opensearch-nodes-default-headless
143+
secrets.stackable.tech/scope: node,pod,service=opensearch-1,service=opensearch-1-nodes-default,service=opensearch-1-nodes-default-headless,listener-volume=listener
141144
secrets.stackable.tech/class: tls
142145
spec:
143146
storageClassName: secrets.stackable.tech
@@ -150,7 +153,7 @@ spec:
150153
apiVersion: v1
151154
kind: Secret
152155
metadata:
153-
name: opensearch-security-config
156+
name: opensearch-1-security-config
154157
stringData:
155158
action_groups.yml: |
156159
---
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestAssert
4+
timeout: 600
5+
---
6+
apiVersion: batch/v1
7+
kind: Job
8+
metadata:
9+
name: create-testuser
10+
status:
11+
succeeded: 1
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
apiVersion: batch/v1
3+
kind: Job
4+
metadata:
5+
name: create-testuser
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- name: create-testuser
11+
image: oci.stackable.tech/sdp/testing-tools:0.2.0-stackable0.0.0-dev
12+
command:
13+
- /bin/bash
14+
- -euxo
15+
- pipefail
16+
- -c
17+
args:
18+
- |
19+
pip install opensearch-py==3.0.0
20+
python scripts/create-testuser.py
21+
env:
22+
# required for pip install
23+
- name: HOME
24+
value: /stackable
25+
- name: NAMESPACE
26+
valueFrom:
27+
fieldRef:
28+
fieldPath: metadata.namespace
29+
volumeMounts:
30+
- name: script
31+
mountPath: /stackable/scripts
32+
- name: tls
33+
mountPath: /stackable/tls
34+
securityContext:
35+
allowPrivilegeEscalation: false
36+
capabilities:
37+
drop:
38+
- ALL
39+
runAsNonRoot: true
40+
resources:
41+
requests:
42+
memory: 128Mi
43+
cpu: 100m
44+
limits:
45+
memory: 128Mi
46+
cpu: 400m
47+
volumes:
48+
- name: script
49+
configMap:
50+
name: create-testuser-script
51+
- name: tls
52+
ephemeral:
53+
volumeClaimTemplate:
54+
metadata:
55+
annotations:
56+
secrets.stackable.tech/class: tls
57+
spec:
58+
storageClassName: secrets.stackable.tech
59+
accessModes:
60+
- ReadWriteOnce
61+
resources:
62+
requests:
63+
storage: "1"
64+
serviceAccountName: test-service-account
65+
securityContext:
66+
fsGroup: 1000
67+
restartPolicy: OnFailure
68+
---
69+
apiVersion: v1
70+
kind: ConfigMap
71+
metadata:
72+
name: create-testuser-script
73+
data:
74+
create-testuser.py: |
75+
import os
76+
from opensearchpy import OpenSearch
77+
from opensearchpy.exceptions import RequestError
78+
79+
namespace = os.environ['NAMESPACE']
80+
81+
# Login as admin
82+
client = OpenSearch(
83+
http_auth=('admin', 'AJVFsGJBbpT6mChn'),
84+
hosts=[{
85+
'host': f'opensearch-1-nodes-default.{namespace}.svc.cluster.local',
86+
'port': 9200
87+
}],
88+
http_compress=True,
89+
use_ssl=True,
90+
verify_certs=True,
91+
ca_certs='/stackable/tls/ca.crt'
92+
)
93+
94+
# Create a test user and grant all access
95+
response = client.security.create_user(
96+
username='testuser',
97+
body={
98+
'password': 'L9hUHtLVVEsrcLzZ',
99+
'opendistro_security_roles': ['all_access']
100+
}
101+
)
102+
103+
print(f'Creating test user; {response=}')
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestAssert
4+
timeout: 600
5+
---
6+
apiVersion: batch/v1
7+
kind: Job
8+
metadata:
9+
name: create-testuser
10+
status:
11+
succeeded: 1
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
apiVersion: batch/v1
3+
kind: Job
4+
metadata:
5+
name: create-data
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- name: create-data
11+
image: oci.stackable.tech/sdp/testing-tools:0.2.0-stackable0.0.0-dev
12+
command:
13+
- /bin/bash
14+
- -euxo
15+
- pipefail
16+
- -c
17+
args:
18+
- |
19+
pip install opensearch-py==3.0.0
20+
python scripts/create-data.py
21+
env:
22+
# required for pip install
23+
- name: HOME
24+
value: /stackable
25+
- name: NAMESPACE
26+
valueFrom:
27+
fieldRef:
28+
fieldPath: metadata.namespace
29+
volumeMounts:
30+
- name: script
31+
mountPath: /stackable/scripts
32+
- name: tls
33+
mountPath: /stackable/tls
34+
securityContext:
35+
allowPrivilegeEscalation: false
36+
capabilities:
37+
drop:
38+
- ALL
39+
runAsNonRoot: true
40+
resources:
41+
requests:
42+
memory: 128Mi
43+
cpu: 100m
44+
limits:
45+
memory: 128Mi
46+
cpu: 400m
47+
volumes:
48+
- name: script
49+
configMap:
50+
name: create-data-script
51+
- name: tls
52+
ephemeral:
53+
volumeClaimTemplate:
54+
metadata:
55+
annotations:
56+
secrets.stackable.tech/class: tls
57+
spec:
58+
storageClassName: secrets.stackable.tech
59+
accessModes:
60+
- ReadWriteOnce
61+
resources:
62+
requests:
63+
storage: "1"
64+
serviceAccountName: test-service-account
65+
securityContext:
66+
fsGroup: 1000
67+
restartPolicy: OnFailure
68+
---
69+
apiVersion: v1
70+
kind: ConfigMap
71+
metadata:
72+
name: create-data-script
73+
data:
74+
create-data.py: |
75+
import os
76+
from opensearchpy import OpenSearch
77+
from opensearchpy.exceptions import RequestError
78+
79+
namespace = os.environ['NAMESPACE']
80+
81+
# Login as test user
82+
client = OpenSearch(
83+
http_auth=('testuser', 'L9hUHtLVVEsrcLzZ'),
84+
hosts=[{
85+
'host': f'opensearch-1-nodes-default.{namespace}.svc.cluster.local',
86+
'port': 9200
87+
}],
88+
http_compress=True,
89+
use_ssl=True,
90+
verify_certs=True,
91+
ca_certs='/stackable/tls/ca.crt'
92+
)
93+
94+
# Create an index
95+
index_name = 'test-index'
96+
97+
try:
98+
response = client.indices.create(index=index_name)
99+
print(f'Creating index; {response=}')
100+
except RequestError as err:
101+
if err.error == 'resource_already_exists_exception':
102+
print(f'The index was already created in a prior test run; {index_name=}')
103+
else:
104+
raise
105+
106+
# Add a document to the index
107+
response = client.index(
108+
index=index_name,
109+
body={
110+
'name': 'Stackable'
111+
},
112+
id=1,
113+
)
114+
115+
print(f'Adding document; {response=}')

tests/templates/kuttl/snapshot-s3/30-assert.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ timeout: 600
66
apiVersion: batch/v1
77
kind: Job
88
metadata:
9-
name: test-snapshot
9+
name: create-snapshot
1010
status:
1111
succeeded: 1

0 commit comments

Comments
 (0)