Skip to content
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

Update CI to use Github Environments #326

Merged
merged 10 commits into from
Jan 7, 2025
20 changes: 20 additions & 0 deletions .github/workflows/e2e-test-trusted.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "E2E Tests (Trusted)"

on:
push:
branches: [ "main", "feature/**", "release-**", "workflow/**" ]
merge_group:
jiaeenie marked this conversation as resolved.
Show resolved Hide resolved
types: [ "checks_requested" ]

permissions:
id-token: write
contents: read

jobs:
e2e:
name: E2E Tests
uses: ./.github/workflows/e2e-tests.yaml
with:
environment: "trusted"
ref: ${{ github.event_name == 'push' && github.sha || github.event.pull_request.head.sha }}
jiaeenie marked this conversation as resolved.
Show resolved Hide resolved
secrets: inherit
17 changes: 17 additions & 0 deletions .github/workflows/e2e-test-untrusted.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "E2E Tests (Untrusted)"

on:
pull_request_target:

permissions:
id-token: write
contents: read

jobs:
e2e:
name: E2E Tests
uses: ./.github/workflows/e2e-tests.yaml
with:
environment: "untrusted"
ref: ${{ github.event.pull_request.head.sha }}
secrets: inherit
unexge marked this conversation as resolved.
Show resolved Hide resolved
180 changes: 69 additions & 111 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,72 +1,58 @@
name: E2E Tests

on:
push:
branches: ["main", "release-**", "feature/*"]
pull_request:
branches: ["main", "feature/*"]
paths:
- "tests/**"
- "pkg/**"
- "cmd/**"
- "charts/**"
- ".github/workflows/**"
- "Dockerfile"
workflow_call:
inputs:
environment:
required: true
type: string
ref:
required: true
type: string

# This workflow runs e2e tests and relies on existence of EKS cluster with a `s3-csi-driver-sa` service account
# already deployed to it, which provides the driver with access to s3.
#
# Since we have a single cluster for e2e tests, we ensure that no more than one instance of this workflow is
# running by `concurrency: e2e-cluster` option.
#
# Successful workflows triggered by push to main will upload tested image to the private repository "PROMOTED_IMAGE_NAME":
# - uploaded images will be tagged with main branch commit number
# - uploaded images will be later promoted to public repository by "release" workflow
concurrency: e2e-cluster
env:
AWS_REGION: "us-east-1"
COMMIT_ID: ${{ github.event_name == 'push' && github.sha || github.event.pull_request.head.sha }}
TMP_IMAGE_NAME: "s3-csi-driver-tmp"
PROMOTED_IMAGE_NAME: "s3-csi-driver"
BENCHMARK_RESULTS_BUCKET: "s3://mountpoint-s3-csi-driver-benchmark"
BENCHMARK_RESULTS_REGION: "us-east-1"
IMAGE_NAME: "s3-csi-driver"
BENCHMARK_ARTIFACTS_FOLDER: ".github/artifacts"
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
KOPS_STATE_FILE: "s3://${{ vars.KOPS_STATE_FILE }}"
BENCHMARK_BUCKET: "s3://${{ vars.BENCHMARK_BUCKET }}"
TAG_UNTESTED: "untested_${{ inputs.ref }}"
TAG_PASSED: "test_passed_${{ inputs.ref }}"
jobs:
build:
# this is to prevent the job to run at forked projects
if: github.repository == 'awslabs/mountpoint-s3-csi-driver'
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@master
with:
role-to-assume: ${{ secrets.TEST_IAM_ROLE }}
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ vars.IAM_ROLE }}
aws-region: ${{ vars.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build, tag, and push docker image to Amazon ECR Private Repository
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_NAME: ${{ env.TMP_IMAGE_NAME }}
PLATFORM: "linux/amd64,linux/arm64"
TAG: "${{ env.TAG_UNTESTED }}"
run: |
export PLATFORM=linux/amd64,linux/arm64
export TAG=${{ env.COMMIT_ID }}
make -j `nproc` all-push
make -j `nproc` all-push-skip-if-present
test:
needs: build
strategy:
Expand Down Expand Up @@ -113,12 +99,26 @@ jobs:
- cluster-type: "kops"
kubernetes-version: "1.31.0"
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
permissions:
id-token: write
contents: read
env:
unexge marked this conversation as resolved.
Show resolved Hide resolved
AWS_REGION: "${{ vars.AWS_REGION }}"
CLUSTER_TYPE: "${{ matrix.cluster-type }}"
ARCH: "${{ matrix.arch }}"
AMI_FAMILY: "${{ matrix.family }}"
TAG: "untested_${{ inputs.ref }}"
unexge marked this conversation as resolved.
Show resolved Hide resolved
# envtest doesn't support all versions, here K8S_VERSION is a full version like 1.28.13,
# and in order to get latest supported version by envtest we convert it to 1.28.
K8S_VERSION: "${{ matrix.kubernetes-version }}"
ENVTEST_K8S_VERSION: "${K8S_VERSION%.*}"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@v4
with:
Expand All @@ -127,77 +127,49 @@ jobs:
with:
python-version: "3.10"
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@master
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.TEST_IAM_ROLE }}
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ vars.IAM_ROLE }}
aws-region: ${{ vars.AWS_REGION }}
- name: Install tools
env:
ACTION: "install_tools"
run: |
export ACTION=install_tools
export K8S_VERSION=${{ matrix.kubernetes-version }}
tests/e2e-kubernetes/scripts/run.sh
- name: Run Controller Tests
run: |
# envtest doesn't support all versions, here K8S_VERSION is a full version like 1.28.13,
# and in order to get latest supported version by envtest we convert it to 1.28.
export K8S_VERSION=${{ matrix.kubernetes-version }}
export ENVTEST_K8S_VERSION="${K8S_VERSION%.*}"
make e2e-controller
- name: Create cluster
env:
ACTION: "create_cluster"
run: |
export ACTION=create_cluster
export AWS_REGION=${{ env.AWS_REGION }}
export CLUSTER_TYPE=${{ matrix.cluster-type }}
export ARCH=${{ matrix.arch }}
export AMI_FAMILY=${{ matrix.family }}
export K8S_VERSION=${{ matrix.kubernetes-version }}
tests/e2e-kubernetes/scripts/run.sh
- name: Update kubeconfig
env:
ACTION: "update_kubeconfig"
run: |
export ACTION=update_kubeconfig
export AWS_REGION=${{ env.AWS_REGION }}
export CLUSTER_TYPE=${{ matrix.cluster-type }}
export ARCH=${{ matrix.arch }}
export AMI_FAMILY=${{ matrix.family }}
export K8S_VERSION=${{ matrix.kubernetes-version }}
tests/e2e-kubernetes/scripts/run.sh
- name: Install the driver
env:
ACTION: "install_driver"
run: |
export ACTION=install_driver
export AWS_REGION=${{ env.AWS_REGION }}
export CLUSTER_TYPE=${{ matrix.cluster-type }}
export IMAGE_NAME=${{ env.TMP_IMAGE_NAME }}
export TAG=${{ env.COMMIT_ID }}
export ARCH=${{ matrix.arch }}
export AMI_FAMILY=${{ matrix.family }}
export K8S_VERSION=${{ matrix.kubernetes-version }}
tests/e2e-kubernetes/scripts/run.sh
- name: Run E2E Tests
env:
ACTION: "run_tests"
run: |
export ACTION=run_tests
export AWS_REGION=${{ env.AWS_REGION }}
export CLUSTER_TYPE=${{ matrix.cluster-type }}
export TAG=${{ env.COMMIT_ID }}
export ARCH=${{ matrix.arch }}
export AMI_FAMILY=${{ matrix.family }}
export K8S_VERSION=${{ matrix.kubernetes-version }}
tests/e2e-kubernetes/scripts/run.sh
- name: Run Performance Tests
if: (env.BRANCH_NAME == 'main' || env.BRANCH_NAME == 'bench') && matrix.cluster-type == 'kops' && matrix.arch == 'x86'
env:
ACTION: "run_perf"
run: |
export ACTION=run_perf
export AWS_REGION=${{ env.AWS_REGION }}
export CLUSTER_TYPE=${{ matrix.cluster-type }}
export TAG=${{ env.COMMIT_ID }}
export ARCH=${{ matrix.arch }}
export AMI_FAMILY=${{ matrix.family }}
export K8S_VERSION=${{ matrix.kubernetes-version }}
tests/e2e-kubernetes/scripts/run.sh
- name: Download previous benchmark results
if: (env.BRANCH_NAME == 'main' || env.BRANCH_NAME == 'bench') && matrix.cluster-type == 'kops' && matrix.arch == 'x86'
run: |
mkdir -p ${{ env.BENCHMARK_ARTIFACTS_FOLDER }}
aws s3 cp --region ${{ env.BENCHMARK_RESULTS_REGION }} ${{ env.BENCHMARK_RESULTS_BUCKET }}/benchmark-data.json ${{ env.BENCHMARK_ARTIFACTS_FOLDER }}/benchmark-data.json || true
aws s3 cp --region ${{ vars.BENCHMARK_RESULTS_REGION }} ${{ vars.BENCHMARK_BUCKET }}/benchmark-data.json ${{ env.BENCHMARK_ARTIFACTS_FOLDER }}/benchmark-data.json || true
- name: Update benchmark result file
if: (env.BRANCH_NAME == 'main' || env.BRANCH_NAME == 'bench') && matrix.cluster-type == 'kops' && matrix.arch == 'x86'
uses: benchmark-action/github-action-benchmark@v1
Expand All @@ -212,59 +184,45 @@ jobs:
if: (env.BRANCH_NAME == 'main' || env.BRANCH_NAME == 'bench') && matrix.cluster-type == 'kops' && matrix.arch == 'x86'
run: |
tests/e2e-kubernetes/scripts/format_benchmark_data.py ${{ env.BENCHMARK_ARTIFACTS_FOLDER }}/benchmark-data.json ${{ env.BENCHMARK_ARTIFACTS_FOLDER }}/quicksight-data.json
aws s3 cp ${{ env.BENCHMARK_ARTIFACTS_FOLDER }} s3://mountpoint-s3-csi-driver-benchmark --recursive
aws s3 cp ${{ env.BENCHMARK_ARTIFACTS_FOLDER }} ${{ env.BENCHMARK_BUCKET }} --recursive
- name: Post e2e cleanup
if: always()
env:
ACTION: "e2e_cleanup"
run: |
export ACTION=e2e_cleanup
export AWS_REGION=${{ env.AWS_REGION }}
export CLUSTER_TYPE=${{ matrix.cluster-type }}
export ARCH=${{ matrix.arch }}
export AMI_FAMILY=${{ matrix.family }}
export K8S_VERSION=${{ matrix.kubernetes-version }}
tests/e2e-kubernetes/scripts/run.sh
- name: Uninstall the driver
if: always()
env:
ACTION: "uninstall_driver"
run: |
export ACTION=uninstall_driver
export AWS_REGION=${{ env.AWS_REGION }}
export CLUSTER_TYPE=${{ matrix.cluster-type }}
export ARCH=${{ matrix.arch }}
export AMI_FAMILY=${{ matrix.family }}
export K8S_VERSION=${{ matrix.kubernetes-version }}
tests/e2e-kubernetes/scripts/run.sh
- name: Delete cluster
if: always()
env:
ACTION: "delete_cluster"
run: |
export ACTION=delete_cluster
export AWS_REGION=${{ env.AWS_REGION }}
export CLUSTER_TYPE=${{ matrix.cluster-type }}
export ARCH=${{ matrix.arch }}
export AMI_FAMILY=${{ matrix.family }}
export K8S_VERSION=${{ matrix.kubernetes-version }}
tests/e2e-kubernetes/scripts/run.sh
promote:
if: startsWith(github.ref_name, 'release')
post_test:
unexge marked this conversation as resolved.
Show resolved Hide resolved
needs: test
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
permissions:
id-token: write
contents: read
steps:
- name: Set up crane
uses: imjasonh/setup-[email protected]
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@master
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.TEST_IAM_ROLE }}
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ vars.IAM_ROLE }}
aws-region: ${{ vars.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Promote image for release branch
- name: Mark tests as passed
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: "${{ steps.login-ecr.outputs.registry }}/${{ env.IMAGE_NAME }}"
run: |
export TMP_IMAGE_NAME=${REGISTRY}/${{ env.TMP_IMAGE_NAME }}:${{ env.COMMIT_ID }}
export NEW_IMAGE_NAME=${REGISTRY}/${{ env.PROMOTED_IMAGE_NAME }}:${{ env.COMMIT_ID }}
crane copy ${TMP_IMAGE_NAME} ${NEW_IMAGE_NAME}
docker buildx imagetools create --tag ${REPOSITORY}:${TAG_PASSED} ${REPOSITORY}:${TAG_UNTESTED}
Loading
Loading