-
Notifications
You must be signed in to change notification settings - Fork 0
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
COSI 74, COSI 75: Brownfield use case (re-use existing S3 buckets in Kube) #68
Changes from all commits
0ed07f5
0df0e54
921135b
a3e7337
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
LOG_FILE=".github/e2e_tests/artifacts/logs/e2e_tests/brownfield.log" | ||
mkdir -p "$(dirname "$LOG_FILE")" | ||
|
||
HOST_IP=$(hostname -I | awk '{print $1}') | ||
SECRET_NAME="brownfield-bucket-secret" | ||
IAM_ENDPOINT="http://$HOST_IP:8600" | ||
S3_ENDPOINT="http://$HOST_IP:8000" | ||
BUCKET_NAME="brownfield-bucket" | ||
NAMESPACE="scality-object-storage" | ||
REGION="us-west-1" | ||
|
||
# Error handling function | ||
error_handler() { | ||
echo "An error occurred during bucket creation tests. Check the log file for details." | tee -a "$LOG_FILE" | ||
echo "Failed command: $BASH_COMMAND" | tee -a "$LOG_FILE" | ||
exit 1 | ||
} | ||
|
||
# Trap errors and call the error handler | ||
trap 'error_handler' ERR | ||
|
||
# Log command execution to the log file for debugging | ||
log_and_run() { | ||
"$@" 2>&1 | tee -a "$LOG_FILE" | ||
} | ||
|
||
|
||
# Create the bucket fir brownfield scenario | ||
log_and_run echo "Creating bucket: $BUCKET_NAME" | ||
log_and_run aws s3api create-bucket --bucket "$BUCKET_NAME" --region $REGION --endpoint-url "$S3_ENDPOINT" | ||
|
||
# Check if the bucket exists | ||
log_and_run echo "Checking if bucket $BUCKET_NAME exists" | ||
aws --endpoint-url "$S3_ENDPOINT" s3api head-bucket --bucket "$BUCKET_NAME" | ||
log_and_run echo "Bucket $BUCKET_NAME exists!" | ||
|
||
log_and_run echo "Applying Bucket Class to use existing bucket..." | ||
log_and_run kubectl apply -f cosi-examples/brownfield/bucketclass.yaml | ||
|
||
log_and_run echo "Manually creating Bucket object with existing bucket..." | ||
log_and_run kubectl apply -f cosi-examples/brownfield/bucket.yaml | ||
|
||
log_and_run echo "Applying Bucket Claim referencing the Bucket object..." | ||
log_and_run kubectl apply -f cosi-examples/brownfield/bucketclaim.yaml | ||
|
||
log_and_run echo "Applying Bucket Access Class..." | ||
log_and_run kubectl apply -f cosi-examples/brownfield/bucketaccessclass.yaml | ||
|
||
log_and_run echo "Applying Bucket Access..." | ||
log_and_run kubectl apply -f cosi-examples/brownfield/bucketaccess.yaml | ||
|
||
log_and_run echo "Verifying brownfield-bucket-secret in the default namespace..." | ||
SECRET_JSON="$(kubectl get secret "$SECRET_NAME" --namespace "$NAMESPACE" -o json)" | ||
|
||
# Decode the Base64 encoded BucketInfo | ||
BUCKET_INFO_BASE64="$(echo "$SECRET_JSON" | jq -r '.data.BucketInfo')" | ||
BUCKET_INFO_JSON="$(echo "$BUCKET_INFO_BASE64" | base64 --decode)" | ||
|
||
log_and_run echo "Decoded BucketInfo: $BUCKET_INFO_JSON" | ||
|
||
# Extract values to verify | ||
ACTUAL_BUCKET_NAME=$(echo "$BUCKET_INFO_JSON" | jq -r '.spec.bucketName') | ||
ACTUAL_ENDPOINT=$(echo "$BUCKET_INFO_JSON" | jq -r '.spec.secretS3.endpoint') | ||
ACTUAL_REGION=$(echo "$BUCKET_INFO_JSON" | jq -r '.spec.secretS3.region') | ||
ACTUAL_ACCESS_KEY_ID=$(echo "$BUCKET_INFO_JSON" | jq -r '.spec.secretS3.accessKeyID') | ||
ACTUAL_ACCESS_SECRET_KEY=$(echo "$BUCKET_INFO_JSON" | jq -r '.spec.secretS3.accessSecretKey') | ||
ACTUAL_PROTOCOLS=$(echo "$BUCKET_INFO_JSON" | jq -c '.spec.protocols') | ||
|
||
# Verify bucketName | ||
if [[ "$ACTUAL_BUCKET_NAME" != "$BUCKET_NAME" ]]; then | ||
log_and_run echo "Bucket name mismatch! Expected: $BUCKET_NAME, Found: $ACTUAL_BUCKET_NAME" | ||
exit 1 | ||
fi | ||
|
||
# Verify endpoint | ||
EXPECTED_ENDPOINT="$S3_ENDPOINT" | ||
if [[ "$ACTUAL_ENDPOINT" != "$EXPECTED_ENDPOINT" ]]; then | ||
log_and_run echo "Endpoint mismatch! Expected: $EXPECTED_ENDPOINT, Found: $ACTUAL_ENDPOINT" | ||
exit 1 | ||
fi | ||
|
||
# Verify region | ||
if [[ "$ACTUAL_REGION" != "$REGION" ]]; then | ||
log_and_run echo "Region mismatch! Expected: $REGION, Found: $ACTUAL_REGION" | ||
exit 1 | ||
fi | ||
|
||
# Verify accessSecretKey exists | ||
if [[ -z "$ACTUAL_ACCESS_KEY_ID" ]]; then | ||
log_and_run echo "AccessSecretKey is empty!" | ||
exit 1 | ||
fi | ||
|
||
# Verify accessSecretKey exists | ||
if [[ -z "$ACTUAL_ACCESS_SECRET_KEY" ]]; then | ||
log_and_run echo "AccessSecretKey is empty!" | ||
exit 1 | ||
fi | ||
|
||
# Verify protocol | ||
EXPECTED_PROTOCOLS='["s3"]' | ||
if [[ "$ACTUAL_PROTOCOLS" != "$EXPECTED_PROTOCOLS" ]]; then | ||
log_and_run echo "Protocols mismatch! Expected: $EXPECTED_PROTOCOLS, Found: $ACTUAL_PROTOCOLS" | ||
exit 1 | ||
fi | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we could perform some action on the bucket since we have everything we need at this stage, even just a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a test in the lastest review commit |
||
# cleanup | ||
log_and_run kubectl delete -f cosi-examples/brownfield/bucketaccess.yaml | ||
log_and_run kubectl delete -f cosi-examples/brownfield/bucketaccessclass.yaml | ||
log_and_run kubectl delete -f cosi-examples/brownfield/bucketclaim.yaml | ||
log_and_run kubectl delete -f cosi-examples/brownfield/bucketclass.yaml | ||
|
||
# Check if the bucket is not deleted and Retain policy is respected | ||
log_and_run echo "Checking if bucket $BUCKET_NAME exists" | ||
aws --endpoint-url "$S3_ENDPOINT" s3api head-bucket --bucket "$BUCKET_NAME" | ||
log_and_run echo "Bucket $BUCKET_NAME has been retained!" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: objectstorage.k8s.io/v1alpha1 | ||
kind: Bucket | ||
metadata: | ||
name: brownfield-bucket # should be same as bucket name | ||
namespace: scality-object-storage | ||
spec: | ||
bucketClaim: {} | ||
bucketClassName: brownfield-bucket-class | ||
driverName: cosi.scality.com | ||
deletionPolicy: Retain | ||
existingBucketID: brownfield-bucket # name of pre-existing bucket in S3 | ||
parameters: | ||
objectStorageSecretName: s3-secret-for-cosi | ||
objectStorageSecretNamespace: default | ||
protocols: | ||
- S3 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: objectstorage.k8s.io/v1alpha1 | ||
kind: BucketAccess | ||
metadata: | ||
name: brownfield-bucket-access | ||
namespace: scality-object-storage | ||
spec: | ||
bucketAccessClassName: brownfield-bucket-access-class | ||
bucketClaimName: brownfield-bucket-claim | ||
credentialsSecretName: brownfield-bucket-secret | ||
protocol: s3 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
kind: BucketAccessClass | ||
apiVersion: objectstorage.k8s.io/v1alpha1 | ||
metadata: | ||
name: brownfield-bucket-access-class | ||
namespace: scality-object-storage | ||
driverName: cosi.scality.com | ||
authenticationType: KEY | ||
parameters: | ||
objectStorageSecretName: s3-secret-for-cosi | ||
objectStorageSecretNamespace: default |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: objectstorage.k8s.io/v1alpha1 | ||
kind: BucketClaim | ||
metadata: | ||
name: brownfield-bucket-claim | ||
namespace: scality-object-storage | ||
spec: | ||
bucketClassName: brownfield-bucket-class | ||
existingBucketName: brownfield-bucket # name of Bucket object | ||
protocols: | ||
- S3 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: objectstorage.k8s.io/v1alpha1 | ||
kind: BucketClass | ||
metadata: | ||
name: brownfield-bucket-class | ||
namespace: scality-object-storage | ||
driverName: cosi.scality.com | ||
deletionPolicy: Delete | ||
parameters: | ||
objectStorageSecretName: s3-secret-for-cosi | ||
objectStorageSecretNamespace: default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this line the name and directory was changed.
This check-in went unchecked in an older PR with the old name of the yaml file