From a10bfd4997d3e912f3c19d40fbfc6507e450dc23 Mon Sep 17 00:00:00 2001 From: Anurag Mittal Date: Wed, 6 Nov 2024 09:44:56 +0100 Subject: [PATCH] COSI-15: Add bucket creation E2E tests and cleanup --- .github/scripts/cleanup_cosi_resources.sh | 54 +++++++++++ .github/scripts/e2e_test_bucket_creation.sh | 102 ++++++++++++++++++++ .github/workflows/ci-e2e-tests.yml | 12 +++ cosi-examples/bucketclaim.yaml | 4 +- cosi-examples/bucketclass.yaml | 4 +- cosi-examples/s3-secret-for-cosi.yaml | 4 +- 6 files changed, 174 insertions(+), 6 deletions(-) create mode 100644 .github/scripts/cleanup_cosi_resources.sh create mode 100644 .github/scripts/e2e_test_bucket_creation.sh diff --git a/.github/scripts/cleanup_cosi_resources.sh b/.github/scripts/cleanup_cosi_resources.sh new file mode 100644 index 0000000..ceaa8d0 --- /dev/null +++ b/.github/scripts/cleanup_cosi_resources.sh @@ -0,0 +1,54 @@ +#!/bin/bash +set -e + +LOG_FILE=".github/e2e_tests/artifacts/logs/kind_cluster_logs/cosi_deployment/cleanup_debug.log" +mkdir -p "$(dirname "$LOG_FILE")" # Ensure the log directory exists + +error_handler() { + echo "An error occurred during the COSI cleanup. Check the log file for details." | tee -a "$LOG_FILE" + echo "Failed command: $BASH_COMMAND" | tee -a "$LOG_FILE" + exit 1 +} + +trap 'error_handler' ERR + +log_and_run() { + echo "Running: $*" | tee -a "$LOG_FILE" + "$@" | tee -a "$LOG_FILE" +} + +log_and_run echo "Removing COSI driver manifests and namespace..." +log_and_run kubectl delete -k . || echo "COSI driver manifests not found." | tee -a "$LOG_FILE" +log_and_run kubectl delete namespace scality-object-storage || echo "Namespace scality-object-storage not found." | tee -a "$LOG_FILE" + +log_and_run echo "Verifying namespace deletion..." +if kubectl get namespace scality-object-storage &>/dev/null; then + echo "Warning: Namespace scality-object-storage was not deleted." | tee -a "$LOG_FILE" + exit 1 +fi + +log_and_run echo "Removing Finalizers from Bucket Claim and Bucket" +log_and_run kubectl patch bucketclaim my-bucket-claim -p '{"metadata":{"finalizers":[]}}' --type=merge || echo "Bucket Claim finalizers not found." | tee -a "$LOG_FILE" + +BUCKET_NAMES=$(kubectl get bucket -o jsonpath='{.items[*].metadata.name}') + +for BUCKET_NAME in $BUCKET_NAMES; do + log_and_run echo "Removing finalizers from bucket: $BUCKET_NAME" + log_and_run kubectl patch bucket "$BUCKET_NAME" -p '{"metadata":{"finalizers":[]}}' --type=merge || echo "Finalizers not found for bucket: $BUCKET_NAME" | tee -a "$LOG_FILE" +done + +log_and_run echo "Deleting Bucket Claim and Bucket Class..." +log_and_run kubectl delete -f cosi-examples/bucketclass.yaml || echo "Bucket Class not found." | tee -a "$LOG_FILE" +log_and_run kubectl delete -f cosi-examples/bucketclaim.yaml || echo "Bucket Claim not found." | tee -a "$LOG_FILE" + +log_and_run echo "Deleting COSI CRDs..." +log_and_run kubectl delete -k github.com/kubernetes-sigs/container-object-storage-interface-api || echo "COSI API CRDs not found." | tee -a "$LOG_FILE" +log_and_run kubectl delete -k github.com/kubernetes-sigs/container-object-storage-interface-controller || echo "COSI Controller CRDs not found." | tee -a "$LOG_FILE" + +log_and_run echo "Verifying COSI CRDs deletion..." +if kubectl get crd | grep 'container-object-storage-interface' &>/dev/null; then + echo "Warning: Some COSI CRDs were not deleted." | tee -a "$LOG_FILE" + exit 1 +fi + +log_and_run echo "COSI cleanup completed successfully." diff --git a/.github/scripts/e2e_test_bucket_creation.sh b/.github/scripts/e2e_test_bucket_creation.sh new file mode 100644 index 0000000..fcc0a37 --- /dev/null +++ b/.github/scripts/e2e_test_bucket_creation.sh @@ -0,0 +1,102 @@ +#!/bin/bash +set -e + +# Define log file for debugging +LOG_FILE=".github/e2e_tests/artifacts/logs/e2e_tests/bucket_creation_test.log" +mkdir -p "$(dirname "$LOG_FILE")" # Ensure the log directory exists + +# Error handling function +error_handler() { + echo "An error occurred during the COSI setup. 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() { + echo "Running: $*" | tee -a "$LOG_FILE" + "$@" | tee -a "$LOG_FILE" +} + +# Step 1: Create Account in Vault +log_and_run echo "Creating account in Vault container..." +CONTAINER_ID=$(docker ps -qf "name=s3_and_iam_deployment-iam-1") +log_and_run docker exec "$CONTAINER_ID" sh -c "ADMIN_ACCESS_KEY_ID=D4IT2AWSB588GO5J9T00 ADMIN_SECRET_ACCESS_KEY=UEEu8tYlsOGGrgf4DAiSZD6apVNPUWqRiPG0nTB6 ./node_modules/vaultclient/bin/vaultclient create-account --name cosi-account --email cosi-account@scality.local" +log_and_run docker exec "$CONTAINER_ID" sh -c "ADMIN_ACCESS_KEY_ID=D4IT2AWSB588GO5J9T00 ADMIN_SECRET_ACCESS_KEY=UEEu8tYlsOGGrgf4DAiSZD6apVNPUWqRiPG0nTB6 ./node_modules/vaultclient/bin/vaultclient generate-account-access-key --name=cosi-account --accesskey=PBUOB68AVF39EVVAFNFL --secretkey=P+PK+uMB9spUc21huaQoOexqdJoV00tSnl+pc7t7" + +# Retrieve the Host IP Address +HOST_IP=$(hostname -I | awk '{print $1}') +log_and_run echo "Using Host IP: $HOST_IP" + +# Step 2: Configure AWS CLI in Home Directory +log_and_run echo "Configuring AWS CLI in home directory..." +log_and_run mkdir -p ~/.aws # Ensure the ~/.aws directory exists + +# Create the AWS credentials file +cat < ~/.aws/credentials +[default] +aws_access_key_id = PBUOB68AVF39EVVAFNFL +aws_secret_access_key = P+PK+uMB9spUc21huaQoOexqdJoV00tSnl+pc7t7 +EOF + +# Create the AWS config file +cat < ~/.aws/config +[default] +region = us-east-1 +output = json +EOF + +# Step 3: Apply S3 Secret for COSI with Host IP +log_and_run echo "Applying S3 Secret for COSI with updated endpoint..." +cat <