Skip to content

Commit a9cf51d

Browse files
authored
Merge pull request #68 from scality/bugfix/COSI-74-remove-silent-errors
COSI 74, COSI 75: Brownfield use case (re-use existing S3 buckets in Kube)
2 parents 52e13ca + a3e7337 commit a9cf51d

18 files changed

+195
-33
lines changed

.github/scripts/cleanup_cosi_resources.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ for BUCKET_NAME in $BUCKET_NAMES; do
5252
done
5353

5454
log_and_run echo "Deleting Bucket Access Class..."
55-
log_and_run kubectl delete -f cosi-examples/bucketaccessclass.yaml --all || { echo "No BucketAccessClass resources found." | tee -a "$LOG_FILE"; }
55+
log_and_run kubectl delete -f cosi-examples/greenfield/bucketaccessclass.yaml --all || { echo "No BucketAccessClass resources found." | tee -a "$LOG_FILE"; }
5656

5757
log_and_run echo "Deleting Bucket Class and Bucket Claim..."
58-
log_and_run kubectl delete -f cosi-examples/bucketclass.yaml || { echo "Bucket Class not found." | tee -a "$LOG_FILE"; }
59-
log_and_run kubectl delete -f cosi-examples/bucketclaim.yaml || { echo "Bucket Claim not found." | tee -a "$LOG_FILE"; }
60-
log_and_run kubectl delete -f cosi-examples/bucketclass-delete-on-claim-removal.yaml || { echo "Bucket Class not found." | tee -a "$LOG_FILE"; }
58+
log_and_run kubectl delete -f cosi-examples/greenfield/bucketclass.yaml || { echo "Bucket Class not found." | tee -a "$LOG_FILE"; }
59+
log_and_run kubectl delete -f cosi-examples/greenfield/bucketclaim.yaml || { echo "Bucket Claim not found." | tee -a "$LOG_FILE"; }
60+
log_and_run kubectl delete -f cosi-examples/greenfield/bucketclass-deletion-policy.yaml || { echo "Bucket Class not found." | tee -a "$LOG_FILE"; }
6161

6262
log_and_run echo "Deleting s3-secret-for-cosi secret..."
6363
log_and_run kubectl delete secret s3-secret-for-cosi --namespace=default || { echo "Secret s3-secret-for-cosi not found." | tee -a "$LOG_FILE"; }
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/bin/bash
2+
set -e
3+
4+
LOG_FILE=".github/e2e_tests/artifacts/logs/e2e_tests/brownfield.log"
5+
mkdir -p "$(dirname "$LOG_FILE")"
6+
7+
HOST_IP=$(hostname -I | awk '{print $1}')
8+
SECRET_NAME="brownfield-bucket-secret"
9+
IAM_ENDPOINT="http://$HOST_IP:8600"
10+
S3_ENDPOINT="http://$HOST_IP:8000"
11+
BUCKET_NAME="brownfield-bucket"
12+
NAMESPACE="scality-object-storage"
13+
REGION="us-west-1"
14+
15+
# Error handling function
16+
error_handler() {
17+
echo "An error occurred during bucket creation tests. Check the log file for details." | tee -a "$LOG_FILE"
18+
echo "Failed command: $BASH_COMMAND" | tee -a "$LOG_FILE"
19+
exit 1
20+
}
21+
22+
# Trap errors and call the error handler
23+
trap 'error_handler' ERR
24+
25+
# Log command execution to the log file for debugging
26+
log_and_run() {
27+
"$@" 2>&1 | tee -a "$LOG_FILE"
28+
}
29+
30+
31+
# Create the bucket fir brownfield scenario
32+
log_and_run echo "Creating bucket: $BUCKET_NAME"
33+
log_and_run aws s3api create-bucket --bucket "$BUCKET_NAME" --region $REGION --endpoint-url "$S3_ENDPOINT"
34+
35+
# Check if the bucket exists
36+
log_and_run echo "Checking if bucket $BUCKET_NAME exists"
37+
aws --endpoint-url "$S3_ENDPOINT" s3api head-bucket --bucket "$BUCKET_NAME"
38+
log_and_run echo "Bucket $BUCKET_NAME exists!"
39+
40+
log_and_run echo "Applying Bucket Class to use existing bucket..."
41+
log_and_run kubectl apply -f cosi-examples/brownfield/bucketclass.yaml
42+
43+
log_and_run echo "Manually creating Bucket object with existing bucket..."
44+
log_and_run kubectl apply -f cosi-examples/brownfield/bucket.yaml
45+
46+
log_and_run echo "Applying Bucket Claim referencing the Bucket object..."
47+
log_and_run kubectl apply -f cosi-examples/brownfield/bucketclaim.yaml
48+
49+
log_and_run echo "Applying Bucket Access Class..."
50+
log_and_run kubectl apply -f cosi-examples/brownfield/bucketaccessclass.yaml
51+
52+
log_and_run echo "Applying Bucket Access..."
53+
log_and_run kubectl apply -f cosi-examples/brownfield/bucketaccess.yaml
54+
55+
log_and_run echo "Verifying brownfield-bucket-secret in the default namespace..."
56+
SECRET_JSON="$(kubectl get secret "$SECRET_NAME" --namespace "$NAMESPACE" -o json)"
57+
58+
# Decode the Base64 encoded BucketInfo
59+
BUCKET_INFO_BASE64="$(echo "$SECRET_JSON" | jq -r '.data.BucketInfo')"
60+
BUCKET_INFO_JSON="$(echo "$BUCKET_INFO_BASE64" | base64 --decode)"
61+
62+
log_and_run echo "Decoded BucketInfo: $BUCKET_INFO_JSON"
63+
64+
# Extract values to verify
65+
ACTUAL_BUCKET_NAME=$(echo "$BUCKET_INFO_JSON" | jq -r '.spec.bucketName')
66+
ACTUAL_ENDPOINT=$(echo "$BUCKET_INFO_JSON" | jq -r '.spec.secretS3.endpoint')
67+
ACTUAL_REGION=$(echo "$BUCKET_INFO_JSON" | jq -r '.spec.secretS3.region')
68+
ACTUAL_ACCESS_KEY_ID=$(echo "$BUCKET_INFO_JSON" | jq -r '.spec.secretS3.accessKeyID')
69+
ACTUAL_ACCESS_SECRET_KEY=$(echo "$BUCKET_INFO_JSON" | jq -r '.spec.secretS3.accessSecretKey')
70+
ACTUAL_PROTOCOLS=$(echo "$BUCKET_INFO_JSON" | jq -c '.spec.protocols')
71+
72+
# Verify bucketName
73+
if [[ "$ACTUAL_BUCKET_NAME" != "$BUCKET_NAME" ]]; then
74+
log_and_run echo "Bucket name mismatch! Expected: $BUCKET_NAME, Found: $ACTUAL_BUCKET_NAME"
75+
exit 1
76+
fi
77+
78+
# Verify endpoint
79+
EXPECTED_ENDPOINT="$S3_ENDPOINT"
80+
if [[ "$ACTUAL_ENDPOINT" != "$EXPECTED_ENDPOINT" ]]; then
81+
log_and_run echo "Endpoint mismatch! Expected: $EXPECTED_ENDPOINT, Found: $ACTUAL_ENDPOINT"
82+
exit 1
83+
fi
84+
85+
# Verify region
86+
if [[ "$ACTUAL_REGION" != "$REGION" ]]; then
87+
log_and_run echo "Region mismatch! Expected: $REGION, Found: $ACTUAL_REGION"
88+
exit 1
89+
fi
90+
91+
# Verify accessSecretKey exists
92+
if [[ -z "$ACTUAL_ACCESS_KEY_ID" ]]; then
93+
log_and_run echo "AccessSecretKey is empty!"
94+
exit 1
95+
fi
96+
97+
# Verify accessSecretKey exists
98+
if [[ -z "$ACTUAL_ACCESS_SECRET_KEY" ]]; then
99+
log_and_run echo "AccessSecretKey is empty!"
100+
exit 1
101+
fi
102+
103+
# Verify protocol
104+
EXPECTED_PROTOCOLS='["s3"]'
105+
if [[ "$ACTUAL_PROTOCOLS" != "$EXPECTED_PROTOCOLS" ]]; then
106+
log_and_run echo "Protocols mismatch! Expected: $EXPECTED_PROTOCOLS, Found: $ACTUAL_PROTOCOLS"
107+
exit 1
108+
fi
109+
110+
# cleanup
111+
log_and_run kubectl delete -f cosi-examples/brownfield/bucketaccess.yaml
112+
log_and_run kubectl delete -f cosi-examples/brownfield/bucketaccessclass.yaml
113+
log_and_run kubectl delete -f cosi-examples/brownfield/bucketclaim.yaml
114+
log_and_run kubectl delete -f cosi-examples/brownfield/bucketclass.yaml
115+
116+
# Check if the bucket is not deleted and Retain policy is respected
117+
log_and_run echo "Checking if bucket $BUCKET_NAME exists"
118+
aws --endpoint-url "$S3_ENDPOINT" s3api head-bucket --bucket "$BUCKET_NAME"
119+
log_and_run echo "Bucket $BUCKET_NAME has been retained!"

.github/scripts/e2e_tests.sh renamed to .github/scripts/e2e_tests_greenfield_use_case.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -e
33

44
# Define log file for debugging
5-
LOG_FILE=".github/e2e_tests/artifacts/logs/e2e_tests/bucket_creation_test.log"
5+
LOG_FILE=".github/e2e_tests/artifacts/logs/e2e_tests/greenfield.log"
66
mkdir -p "$(dirname "$LOG_FILE")" # Ensure the log directory exists
77

88
CONTAINER_NAME=s3_and_iam_deployment-iam-1
@@ -83,19 +83,19 @@ EOF
8383

8484
# Step 4: Apply Bucket Class
8585
log_and_run echo "Applying Bucket Class..."
86-
log_and_run kubectl apply -f cosi-examples/bucketclass.yaml
86+
log_and_run kubectl apply -f cosi-examples/greenfield/bucketclass.yaml
8787

8888
# Step 5: Apply Bucket Claim
8989
log_and_run echo "Applying Bucket Claim..."
90-
log_and_run kubectl apply -f cosi-examples/bucketclaim.yaml
90+
log_and_run kubectl apply -f cosi-examples/greenfield/bucketclaim.yaml
9191

9292
# Step 6: Apply Bucket Access Class
9393
log_and_run echo "Applying Bucket Access Class..."
94-
log_and_run kubectl apply -f cosi-examples/bucketaccessclass.yaml
94+
log_and_run kubectl apply -f cosi-examples/greenfield/bucketaccessclass.yaml
9595

9696
# Step 7: Apply Bucket Access
9797
log_and_run echo "Applying Bucket Access..."
98-
log_and_run kubectl apply -f cosi-examples/bucketaccess.yaml
98+
log_and_run kubectl apply -f cosi-examples/greenfield/bucketaccess.yaml
9999

100100
# Step 8: Verify Bucket Creation with Retry
101101
log_and_run echo "Listing all S3 buckets before verification..."
@@ -213,7 +213,7 @@ fi
213213

214214
# Step 11: Delete Bucket Access Resource
215215
log_and_run echo "Deleting Bucket Access Resource..."
216-
log_and_run kubectl delete -f cosi-examples/bucketaccess.yaml
216+
log_and_run kubectl delete -f cosi-examples/greenfield/bucketaccess.yaml
217217

218218
# Step 12: Verify IAM User Deletion
219219
log_and_run echo "Verifying IAM user '$IAM_USER_NAME' deletion..."
@@ -230,8 +230,8 @@ fi
230230
# Step 13: Test deletion bucket with deletion policy set
231231

232232
log_and_run echo "Applying Bucket Class with deletion policy and respective Bucket Claim..."
233-
log_and_run kubectl apply -f cosi-examples/bucketclass-deletion-policy.yaml
234-
log_and_run kubectl apply -f cosi-examples/bucketclaim-deletion-policy.yaml
233+
log_and_run kubectl apply -f cosi-examples/greenfield/bucketclass-deletion-policy.yaml
234+
log_and_run kubectl apply -f cosi-examples/greenfield/bucketclaim-deletion-policy.yaml
235235

236236
log_and_run echo "Listing all S3 buckets before deletion..."
237237
log_and_run aws s3 ls --endpoint-url "$S3_ENDPOINT"
@@ -259,7 +259,7 @@ if [ -z "$BUCKET_TO_BE_DELETED" ]; then
259259
fi
260260

261261
log_and_run echo "Deleting Bucket Claim..."
262-
log_and_run kubectl delete -f cosi-examples/bucketclaim-deletion-policy.yaml
262+
log_and_run kubectl delete -f cosi-examples/greenfield/bucketclaim-deletion-policy.yaml
263263

264264
# Check if the bucket with name $BUCKET_TO_BE_DELETED exists by doing a head bucket.
265265
# If bucket exists, retry with ATTEMPTS and DELAY. If bucket is not found, test success.

.github/workflows/ci-e2e-tests.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,13 @@ jobs:
9696
docker save "$CLOUDSERVER_IMAGE" -o /tmp/.docker_cache/cloudserver_image.tar
9797
shell: bash
9898

99-
- name: E2E tests for COSI driver using kustomize
99+
- name: E2E tests for greenfield use case using kustomize
100100
run: |
101-
pwd
102-
.github/scripts/e2e_tests.sh
101+
.github/scripts/e2e_tests_greenfield_use_case.sh
102+
103+
- name: E2E tests for brownfield use case using kustomize
104+
run: |
105+
.github/scripts/e2e_tests_brownfield_use_case.sh
103106
104107
- name: "Delay completion"
105108
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: objectstorage.k8s.io/v1alpha1
2+
kind: Bucket
3+
metadata:
4+
name: brownfield-bucket # should be same as bucket name
5+
namespace: scality-object-storage
6+
spec:
7+
bucketClaim: {}
8+
bucketClassName: brownfield-bucket-class
9+
driverName: cosi.scality.com
10+
deletionPolicy: Retain
11+
existingBucketID: brownfield-bucket # name of pre-existing bucket in S3
12+
parameters:
13+
objectStorageSecretName: s3-secret-for-cosi
14+
objectStorageSecretNamespace: default
15+
protocols:
16+
- S3
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: objectstorage.k8s.io/v1alpha1
2+
kind: BucketAccess
3+
metadata:
4+
name: brownfield-bucket-access
5+
namespace: scality-object-storage
6+
spec:
7+
bucketAccessClassName: brownfield-bucket-access-class
8+
bucketClaimName: brownfield-bucket-claim
9+
credentialsSecretName: brownfield-bucket-secret
10+
protocol: s3
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
kind: BucketAccessClass
2+
apiVersion: objectstorage.k8s.io/v1alpha1
3+
metadata:
4+
name: brownfield-bucket-access-class
5+
namespace: scality-object-storage
6+
driverName: cosi.scality.com
7+
authenticationType: KEY
8+
parameters:
9+
objectStorageSecretName: s3-secret-for-cosi
10+
objectStorageSecretNamespace: default
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: objectstorage.k8s.io/v1alpha1
2+
kind: BucketClaim
3+
metadata:
4+
name: brownfield-bucket-claim
5+
namespace: scality-object-storage
6+
spec:
7+
bucketClassName: brownfield-bucket-class
8+
existingBucketName: brownfield-bucket # name of Bucket object
9+
protocols:
10+
- S3
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: objectstorage.k8s.io/v1alpha1
2+
kind: BucketClass
3+
metadata:
4+
name: brownfield-bucket-class
5+
namespace: scality-object-storage
6+
driverName: cosi.scality.com
7+
deletionPolicy: Delete
8+
parameters:
9+
objectStorageSecretName: s3-secret-for-cosi
10+
objectStorageSecretNamespace: default
File renamed without changes.

0 commit comments

Comments
 (0)