Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.

Commit 4537562

Browse files
shanduurshanduur-akamai
authored andcommitted
test(e2e): add test suite for S3 Key authentication
Signed-off-by: Mateusz Urbanek <[email protected]>
1 parent 7aa96a5 commit 4537562

12 files changed

+355
-0
lines changed
+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
3+
apiVersion: chainsaw.kyverno.io/v1alpha1
4+
kind: Test
5+
metadata:
6+
name: test-s3-iam-delete
7+
labels:
8+
sample: "true"
9+
protocol: "S3"
10+
authenticationType: "Key"
11+
deletionPolicy: "Delete"
12+
spec:
13+
template: true
14+
steps:
15+
- name: Check if COSI Controller exist
16+
try:
17+
- assert:
18+
file: ../../../tests/controller.yaml
19+
- name: Create test BucketClass and BucketAccessClass
20+
try:
21+
- apply:
22+
file: ./resources/BucketClass.yaml
23+
- apply:
24+
file: ./resources/BucketAccessClass.yaml
25+
- name: Create BucketClaim
26+
try:
27+
- apply:
28+
file: ./resources/BucketClaim.yaml
29+
- name: Check if BucketClaim is ready
30+
try:
31+
- assert:
32+
resource:
33+
apiVersion: objectstorage.k8s.io/v1alpha1
34+
kind: BucketClaim
35+
metadata:
36+
name: test-s3-iam-delete
37+
status:
38+
bucketReady: true
39+
- name: Create BucketAccess
40+
try:
41+
- apply:
42+
file: ./resources/BucketAccess.yaml
43+
- name: Check if BucketAccess is granted
44+
try:
45+
- assert:
46+
resource:
47+
apiVersion: objectstorage.k8s.io/v1alpha1
48+
kind: BucketAccess
49+
metadata:
50+
name: test-s3-iam-delete
51+
status:
52+
accessGranted: true
53+
- name: Check if Secret exists
54+
try:
55+
- assert:
56+
resource:
57+
apiVersion: v1
58+
kind: Secret
59+
metadata:
60+
name: test-s3-iam-delete
61+
- name: Run ObjectStorage validation tool
62+
# TODO: This should be either a standalone test tool developed by us, to run test suite:
63+
# - validate Secret format;
64+
# - validate connectivity to the Object Storage server;
65+
# Right now it is using busybox to check if the secret has correct format.
66+
try:
67+
- apply:
68+
file: ../../../tests/validator.yaml
69+
- create:
70+
resource:
71+
apiVersion: batch/v1
72+
kind: Job
73+
metadata:
74+
name: test-s3-iam-delete
75+
spec:
76+
ttlSecondsAfterFinished: 100
77+
template:
78+
spec:
79+
restartPolicy: Never
80+
containers:
81+
- name: secret-test
82+
image: docker.io/library/python:3.12
83+
command: [ "sh", "/validation/validation.sh" ]
84+
volumeMounts:
85+
- mountPath: /validator
86+
name: validator
87+
- mountPath: /conf
88+
name: secret-vol
89+
volumes:
90+
- name: validator
91+
configMap:
92+
name: validator
93+
- name: secret-vol
94+
secret:
95+
secretName: test-retain-secret
96+
items:
97+
- iam: BucketInfo
98+
path: BucketInfo.json
99+
- name: Check if ObjectStorage validation tool completed succesfully
100+
try:
101+
- assert:
102+
resource:
103+
apiVersion: batch/v1
104+
kind: Job
105+
metadata:
106+
name: test-s3-iam-delete
107+
status:
108+
succeeded: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: objectstorage.k8s.io/v1alpha1
2+
kind: BucketAccess
3+
metadata:
4+
name: test-s3-iam-delete
5+
spec:
6+
bucketClaimName: test-s3-iam-delete
7+
protocol: S3
8+
bucketAccessClassName: test-s3-iam-delete
9+
credentialsSecretName: test-s3-iam-delete
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: objectstorage.k8s.io/v1alpha1
2+
kind: BucketAccessClass
3+
metadata:
4+
name: test-s3-iam-delete
5+
driverName: sample-driver.objectstorage.k8s.io
6+
authenticationType: IAM
7+
parameters: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: objectstorage.k8s.io/v1alpha1
2+
kind: BucketClaim
3+
metadata:
4+
name: test-s3-iam-delete
5+
spec:
6+
bucketClassName: test-s3-iam-delete
7+
protocols: [ 'S3' ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: objectstorage.k8s.io/v1alpha1
2+
kind: BucketClass
3+
metadata:
4+
name: test-s3-iam-delete
5+
driverName: sample-driver.objectstorage.k8s.io
6+
deletionPolicy: Delete
7+
parameters: {}
+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
3+
apiVersion: chainsaw.kyverno.io/v1alpha1
4+
kind: Test
5+
metadata:
6+
name: test-s3-key-retain
7+
labels:
8+
sample: "true"
9+
protocol: "S3"
10+
authenticationType: "Key"
11+
deletionPolicy: "Retain"
12+
spec:
13+
template: true
14+
steps:
15+
- name: Check if COSI Controller exist
16+
try:
17+
- assert:
18+
file: ../../../tests/controller.yaml
19+
- name: Create test BucketClass and BucketAccessClass
20+
try:
21+
- apply:
22+
file: ./resources/BucketClass.yaml
23+
- apply:
24+
file: ./resources/BucketAccessClass.yaml
25+
- name: Create BucketClaim
26+
try:
27+
- apply:
28+
file: ./resources/BucketClaim.yaml
29+
- name: Check if BucketClaim is ready
30+
try:
31+
- assert:
32+
resource:
33+
apiVersion: objectstorage.k8s.io/v1alpha1
34+
kind: BucketClaim
35+
metadata:
36+
name: test-s3-key-retain
37+
status:
38+
bucketReady: true
39+
- name: Create BucketAccess
40+
try:
41+
- apply:
42+
file: ./resources/BucketAccess.yaml
43+
- name: Check if BucketAccess is granted
44+
try:
45+
- assert:
46+
resource:
47+
apiVersion: objectstorage.k8s.io/v1alpha1
48+
kind: BucketAccess
49+
metadata:
50+
name: test-s3-key-retain
51+
status:
52+
accessGranted: true
53+
- name: Check if Secret exists
54+
try:
55+
- assert:
56+
resource:
57+
apiVersion: v1
58+
kind: Secret
59+
metadata:
60+
name: test-s3-key-retain
61+
- name: Run ObjectStorage validation tool
62+
# TODO: This should be either a standalone test tool developed by us, to run test suite:
63+
# - validate Secret format;
64+
# - validate connectivity to the Object Storage server;
65+
# Right now it is using busybox to check if the secret has correct format.
66+
try:
67+
- apply:
68+
file: ../../../tests/validator.yaml
69+
- create:
70+
resource:
71+
apiVersion: batch/v1
72+
kind: Job
73+
metadata:
74+
name: test-s3-key-retain
75+
spec:
76+
ttlSecondsAfterFinished: 100
77+
template:
78+
spec:
79+
restartPolicy: Never
80+
containers:
81+
- name: secret-test
82+
image: docker.io/library/python:3.12
83+
command: [ "sh", "/validation/validation.sh" ]
84+
volumeMounts:
85+
- mountPath: /validator
86+
name: validator
87+
- mountPath: /conf
88+
name: secret-vol
89+
volumes:
90+
- name: validator
91+
configMap:
92+
name: validator
93+
- name: secret-vol
94+
secret:
95+
secretName: test-s3-key-retain
96+
items:
97+
- iam: BucketInfo
98+
path: BucketInfo.json
99+
- name: Check if ObjectStorage validation tool completed succesfully
100+
try:
101+
- assert:
102+
resource:
103+
apiVersion: batch/v1
104+
kind: Job
105+
metadata:
106+
name: test-s3-key-retain
107+
status:
108+
succeeded: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: objectstorage.k8s.io/v1alpha1
2+
kind: BucketAccess
3+
metadata:
4+
name: test-s3-key-retain
5+
spec:
6+
bucketClaimName: test-s3-key-retain
7+
protocol: S3
8+
bucketAccessClassName: test-s3-key-retain
9+
credentialsSecretName: test-s3-key-retain
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: objectstorage.k8s.io/v1alpha1
2+
kind: BucketAccessClass
3+
metadata:
4+
name: test-s3-key-retain
5+
driverName: sample-driver.objectstorage.k8s.io
6+
authenticationType: IAM
7+
parameters: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: objectstorage.k8s.io/v1alpha1
2+
kind: BucketClaim
3+
metadata:
4+
name: test-s3-key-retain
5+
spec:
6+
bucketClassName: test-s3-key-retain
7+
protocols: [ 'S3' ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: objectstorage.k8s.io/v1alpha1
2+
kind: BucketClass
3+
metadata:
4+
name: test-s3-key-retain
5+
driverName: sample-driver.objectstorage.k8s.io
6+
deletionPolicy: Retain
7+
parameters: {}

test/e2e/tests/controller.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: objectstorage-controller
5+
namespace: default
6+
status:
7+
availableReplicas: 1

test/e2e/tests/validator.yaml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: validator
5+
data:
6+
schema.json: |
7+
{
8+
"$schema": "http://json-schema.org/draft-07/schema#",
9+
"type": "object",
10+
"properties": {
11+
"spec": {
12+
"type": "object",
13+
"properties": {
14+
"bucketName": {
15+
"type": "string"
16+
},
17+
"authenticationType": {
18+
"type": "string",
19+
"enum": ["IAM", "Key"]
20+
},
21+
"protocols": {
22+
"type": "array",
23+
"items": {
24+
"type": "string",
25+
"enum": ["S3", "Azure", "GCP"]
26+
},
27+
"minItems": 1
28+
},
29+
"secretS3": {
30+
"type": "object",
31+
"properties": {
32+
"endpoint": {
33+
"type": "string"
34+
},
35+
"region": {
36+
"type": "string"
37+
},
38+
"accessKeyID": {
39+
"type": "string"
40+
},
41+
"accessSecretKey": {
42+
"type": "string"
43+
}
44+
},
45+
"required": ["endpoint", "region", "accessKeyID", "accessSecretKey"]
46+
},
47+
"secretAzure": {
48+
"type": "object",
49+
"properties": {
50+
"accessToken": {
51+
"type": "string"
52+
},
53+
"expiryTimeStamp": {
54+
"type": "string"
55+
}
56+
},
57+
"required": ["accessToken", "expiryTimeStamp"]
58+
}
59+
},
60+
"required": ["bucketName", "authenticationType", "protocols"],
61+
"oneOf": [
62+
{ "required": ["secretS3"] },
63+
{ "required": ["secretAzure"] }
64+
]
65+
}
66+
},
67+
"required": ["spec"]
68+
}
69+
validator.sh: |
70+
#!/usr/bin/env sh
71+
pip install check-jsonschema
72+
check-jsonschema --schema /validator/schema.json /conf/BucketInfo.json

0 commit comments

Comments
 (0)