From 80715880a24e427df69e56ced7e2a778eff6a977 Mon Sep 17 00:00:00 2001 From: Sean Zatz Date: Thu, 11 Apr 2024 21:09:01 +0000 Subject: [PATCH] Add script + instructions for in-place upgrade test. --- test/e2e/README.md | 54 +++++++++++++++++++ test/e2e/upgrade_driver_version.sh | 86 ++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100755 test/e2e/upgrade_driver_version.sh diff --git a/test/e2e/README.md b/test/e2e/README.md index 9836d44bb..8fef6a8a2 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -26,3 +26,57 @@ go test -v -timeout 0 ./... -report-dir=$ARTIFACTS -ginkgo.focus="\[efs-csi\]" - ``` The E2E flags that you can pass to `go test` are defined in [e2e_test.go](https://github.com/kubernetes-sigs/aws-efs-csi-driver/blob/master/test/e2e/e2e_test.go#L66-L75). + + +### Running Upgrade Test +In order to test upgrades from previous releases to the current development version of the driver, the following steps can be followed: + +1. Ensure the EFS CSI Driver is not currently deployed on your cluster. +2. Ensure that the EFS CSI Node and Controller service accounts are deployed on your cluster. Ex: +``` +$ cat ~/efs-service-account.yaml +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + labels: + app.kubernetes.io/name: aws-efs-csi-driver + name: efs-csi-controller-sa + namespace: kube-system + annotations: + eks.amazonaws.com/role-arn: arn:aws:iam::123456789:role/test-cluster-iam-sa-role +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + labels: + app.kubernetes.io/name: aws-efs-csi-driver + name: efs-csi-node-sa + namespace: kube-system + annotations: + eks.amazonaws.com/role-arn: arn:aws:iam::123456789:role/test-cluster-iam-sa-role + +$ kubectl apply -f ~/efs-service-account.yaml +``` +3. Run the upgrade script, for example: +```sh +# The release version of the driver you would like to test upgrading from. +# Pulls most recent image from the release-$PREV_RELEASE branch +PREV_RELEASE=1.7 +# Region of private ECR +REGION=us-east-1 +# Account of private ECR +ACCOUNT=123456789 +chmod +x ./upgrade_driver_version.sh +./upgrade_driver_version.sh $PREV_RELEASE $REGION $ACCOUNT +``` +4. Run the e2e tests, note that $REGION should be that of the EKS cluster. +```sh +export KUBECONFIG=$HOME/.kube/config +go test -v -timeout 0 ./... -report-dir=$ARTIFACTS -ginkgo.focus="\[efs-csi\]" -ginkgo.skip="\[Disruptive\]" \ + --file-system-id=$FS_ID --create-file-system=false --deploy-driver=false --region=$REGION +``` +5. Clean Up: The driver + kubernetes service accounts can be cleaned up via the following command: +```sh +kubectl delete -k github.com/kubernetes-sigs/aws-efs-csi-driver/deploy/kubernetes/overlays/stable/?ref=master +``` \ No newline at end of file diff --git a/test/e2e/upgrade_driver_version.sh b/test/e2e/upgrade_driver_version.sh new file mode 100755 index 000000000..c42569792 --- /dev/null +++ b/test/e2e/upgrade_driver_version.sh @@ -0,0 +1,86 @@ +#!/bin/sh +set -eux + +# Check for dependencies +if ! command -v kubectl &> /dev/null; then + echo "kubectl is not installed." + exit 1 +fi +if ! command -v docker &> /dev/null; then + echo "Docker is not installed." + exit 1 +fi +if ! command -v aws &> /dev/null; then + echo "AWS CLI is not installed." + exit 1 +fi + +prevRelease=$1 +region=$2 +account=$3 + +# The private ECR Repo is expected to take the following format: +# $account.dkr.ecr.$region.amazonaws.com/aws-efs-csi-driver +ecrRegistry="$account.dkr.ecr.$region.amazonaws.com" +ecrRepo="aws-efs-csi-driver" + +# Make temp folder for temp files +mkdir ./temp +publicDriverManifest="./temp/public-driver-manifest.yaml" + +# Build & push image of driver's development version +cd ../.. && make +aws ecr get-login-password --region $region | docker login --username AWS --password-stdin $ecrRegistry +docker build --pull --no-cache -t aws-efs-csi-driver . +docker tag aws-efs-csi-driver:latest $ecrRegistry/$ecrRepo:latest +docker push $ecrRegistry/$ecrRepo:latest +cd ./test/e2e + +# Download starting version manifest +kubectl kustomize \ + "github.com/kubernetes-sigs/aws-efs-csi-driver/deploy/kubernetes/overlays/stable/?ref=release-$prevRelease" > $publicDriverManifest + +# Remove the predefined service accounts +awk ' + /apiVersion: v1/ {recording=1} + recording && /app.kubernetes.io\/name: aws-efs-csi-driver/ {found=1} + recording && /name: efs-csi-controller-sa/ {controller_sa=1} + recording && /name: efs-csi-node-sa/ {node_sa=1} + recording && /---/ { + if (found && (controller_sa || node_sa)) { + recording=0; found=0; controller_sa=0; node_sa=0; next + } + } + !recording {print} +' $publicDriverManifest > ./temp/temp.yaml && mv ./temp/temp.yaml $publicDriverManifest + +# Deploy starting version of driver for the upgrade test +kubectl apply -f $publicDriverManifest + +# Tear down starting version +kubectl delete -f $publicDriverManifest + +# Create private manifest file & modify to use the private ecr repo +privateDriverManifest="./temp/private-driver-manifest.yaml" +kubectl kustomize \ + "github.com/kubernetes-sigs/aws-efs-csi-driver/deploy/kubernetes/overlays/stable/ecr/?ref=release-$prevRelease" > $privateDriverManifest + +sed -i -e "s|602401143452.dkr.ecr.us-west-2.amazonaws.com/eks/aws-efs-csi-driver:v[0-9]\+\.[0-9]\+\.[0-9]\+|$account.dkr.ecr.$region.amazonaws.com/aws-efs-csi-driver:latest|" $privateDriverManifest + +# Remove the predefined service accounts +awk ' + /apiVersion: v1/ {recording=1} + recording && /app.kubernetes.io\/name: aws-efs-csi-driver/ {found=1} + recording && /name: efs-csi-controller-sa/ {controller_sa=1} + recording && /name: efs-csi-node-sa/ {node_sa=1} + recording && /---/ { + if (found && (controller_sa || node_sa)) { + recording=0; found=0; controller_sa=0; node_sa=0; next + } + } + !recording {print} +' $privateDriverManifest > ./temp/temp.yaml && mv ./temp/temp.yaml $privateDriverManifest + +kubectl apply -f $privateDriverManifest + +rm -rf ./temp \ No newline at end of file