diff --git a/.github/workflows/build-test-artifacts.yml b/.github/workflows/build-test-artifacts.yml index e5fdb5cfd9..5509982f33 100644 --- a/.github/workflows/build-test-artifacts.yml +++ b/.github/workflows/build-test-artifacts.yml @@ -16,6 +16,11 @@ on: - '!.github/workflows/integration-test.yml' - '!.github/workflows/application-signals-e2e-test.yml' workflow_dispatch: + inputs: + test-image-before-upload: + description: "Run Test on the new container image" + default: true + type: boolean workflow_call: inputs: test-image-before-upload: @@ -93,7 +98,7 @@ jobs: StartIntegrationTests: needs: [ BuildAndUploadPackages, BuildAndUploadITAR, BuildAndUploadCN, BuildDocker ] - if: ${{inputs.test-image-before-upload == null || inputs.test-image-before-upload}} + if: ${{ inputs.test-image-before-upload }} runs-on: ubuntu-latest steps: - run: gh workflow run integration-test.yml --ref ${{ github.ref_name }} --repo $GITHUB_REPOSITORY -f build_run_id=${{ github.run_id }} -f build_sha=${{ github.sha }} @@ -103,7 +108,7 @@ jobs: StartApplicationSignalsE2ETests: needs: [ BuildAndUploadPackages, BuildAndUploadITAR, BuildAndUploadCN, BuildDocker ] # Workflow only runs against main - if: ${{ contains(github.ref_name, 'main') && (inputs.test-image-before-upload == null ||inputs.test-image-before-upload) }} + if: ${{ contains(github.ref_name, 'main') && inputs.test-image-before-upload }} runs-on: ubuntu-latest steps: - run: gh workflow run application-signals-e2e-test.yml --ref ${{ github.ref_name }} --repo $GITHUB_REPOSITORY -f build_run_id=${{ github.run_id }} -f build_sha=${{ github.sha }} diff --git a/.github/workflows/e2e-build.yml b/.github/workflows/e2e-build.yml deleted file mode 100644 index 3acba7112f..0000000000 --- a/.github/workflows/e2e-build.yml +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -# SPDX-License-Identifier: MIT - -name: Build End-to-End Test Artifacts -env: - OPERATOR_GITHUB_REPO_NAME: "aws/amazon-cloudwatch-agent-operator" -on: - workflow_dispatch: - inputs: - operator-branch: - required: false - type: string - description: 'Branch of the operator to test' - default: 'main' - workflow_call: - inputs: - operator-branch: - required: false - type: string - description: 'Branch of the operator to test' - default: 'main' - -jobs: - GetLatestOperatorCommitSHA: - runs-on: ubuntu-latest - outputs: - operator_commit_sha: ${{steps.get_latest_sha.outputs.operator_sha}} - operator_repo_name: ${{env.OPERATOR_GITHUB_REPO_NAME}} - steps: - - name: Checkout the target repo - uses: actions/checkout@v3 - with: - repository: ${{env.OPERATOR_GITHUB_REPO_NAME}} - ref: ${{inputs.operator-branch}} - path: operator-repo - - - name: Get latest commit SHA - id: get_latest_sha - run: | - cd operator-repo - latest_sha=$(git rev-parse HEAD) - echo "::set-output name=operator_sha::$latest_sha" - BuildAgent: - uses: ./.github/workflows/build-test-artifacts.yml - concurrency: - group: "Build-Test-Artifacts-${{github.ref_name}}" - cancel-in-progress: true - secrets: inherit - permissions: - id-token: write - contents: read - with: - test-image-before-upload: false - BuildOperator: - needs: [GetLatestOperatorCommitSHA] - uses: aws/amazon-cloudwatch-agent-operator/.github/workflows/build-and-upload.yml@main - concurrency: - group: ${{ github.workflow }}-operator-${{ inputs.operator-branch}} - cancel-in-progress: true - secrets: inherit - with: - tag: ${{needs.GetLatestOperatorCommitSHA.outputs.operator_commit_sha}} - target-sha: ${{needs.GetLatestOperatorCommitSHA.outputs.operator_commit_sha}} - repository: ${{needs.GetLatestOperatorCommitSHA.outputs.operator_repo_name}} - test-image-before-upload: false - - - diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml new file mode 100644 index 0000000000..2ae0342a81 --- /dev/null +++ b/.github/workflows/e2e-test.yml @@ -0,0 +1,151 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: MIT + +name: Run E2E Tests +env: + TERRAFORM_AWS_ASSUME_ROLE: ${{ vars.TERRAFORM_AWS_ASSUME_ROLE }} + TERRAFORM_AWS_ASSUME_ROLE_DURATION: 14400 # 4 hours + ECR_INTEGRATION_TEST_REPO: "cwagent-integration-test" + CWA_GITHUB_TEST_REPO_NAME: "aws/amazon-cloudwatch-agent-test" + CWA_GITHUB_TEST_REPO_URL: "https://github.com/aws/amazon-cloudwatch-agent-test.git" + CWA_GITHUB_TEST_REPO_BRANCH: "main" + TERRAFORM_AWS_ASSUME_ROLE_ITAR: ${{ vars.TERRAFORM_AWS_ASSUME_ROLE_ITAR }} + TERRAFORM_AWS_ASSUME_ROLE_CN: ${{ vars.TERRAFORM_AWS_ASSUME_ROLE_CN }} + OPERATOR_GITHUB_REPO_NAME: "aws/amazon-cloudwatch-agent-operator" + +on: + workflow_dispatch: + inputs: + region: + required: false + type: string + description: 'AWS Region to run tests in' + default: 'us-west-2' + operator-branch: + required: false + type: string + description: 'Branch of the operator to test' + default: 'main' + helm-charts-branch: + required: false + type: string + description: 'Branch of the helm charts to test' + default: 'main' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }}-parent + cancel-in-progress: true + +jobs: + GetLatestOperatorCommitSHA: + runs-on: ubuntu-latest + outputs: + operator_commit_sha: ${{steps.get_latest_sha.outputs.operator_sha}} + operator_repo_name: ${{env.OPERATOR_GITHUB_REPO_NAME}} + steps: + - name: Checkout the target repo + uses: actions/checkout@v3 + with: + repository: ${{env.OPERATOR_GITHUB_REPO_NAME}} + ref: ${{inputs.operator-branch}} + path: operator-repo + + - name: Get latest commit SHA + id: get_latest_sha + run: | + cd operator-repo + latest_sha=$(git rev-parse HEAD) + echo "::set-output name=operator_sha::$latest_sha" + + BuildAgent: + uses: ./.github/workflows/build-test-artifacts.yml + concurrency: + group: "Build-Test-Artifacts-${{github.ref_name}}" + cancel-in-progress: true + secrets: inherit + permissions: + id-token: write + contents: read + with: + test-image-before-upload: false + + BuildOperator: + needs: [GetLatestOperatorCommitSHA] + uses: aws/amazon-cloudwatch-agent-operator/.github/workflows/build-and-upload.yml@main + concurrency: + group: ${{ github.workflow }}-operator-${{ inputs.operator-branch}} + cancel-in-progress: true + secrets: inherit + with: + tag: ${{needs.GetLatestOperatorCommitSHA.outputs.operator_commit_sha}} + target-sha: ${{needs.GetLatestOperatorCommitSHA.outputs.operator_commit_sha}} + repository: ${{needs.GetLatestOperatorCommitSHA.outputs.operator_repo_name}} + test-image-before-upload: false + + OutputEnvVariables: + needs: [ BuildAgent, BuildOperator ] + name: 'OutputEnvVariables' + runs-on: ubuntu-latest + outputs: + CWA_GITHUB_TEST_REPO_NAME: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_NAME }} + CWA_GITHUB_TEST_REPO_URL: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_URL }} + CWA_GITHUB_TEST_REPO_BRANCH: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_BRANCH }} + ECR_INTEGRATION_TEST_REPO: ${{ steps.set-outputs.outputs.ECR_INTEGRATION_TEST_REPO }} + ECR_OPERATOR_REPO: ${{ steps.set-outputs.outputs.ECR_OPERATOR_REPO }} + ECR_TARGET_ALLOCATOR_REPO: ${{ steps.set-outputs.outputs.ECR_TARGET_ALLOCATOR_REPO }} + steps: + - uses: actions/checkout@v3 + with: + repository: ${{env.CWA_GITHUB_TEST_REPO_NAME}} + ref: ${{env.CWA_GITHUB_TEST_REPO_BRANCH}} + + - name: Set up Go 1.x + uses: actions/setup-go@v4 + with: + go-version: ~1.22.2 + + - name: SetOutputs + id: set-outputs + run: | + echo "::set-output name=CWA_GITHUB_TEST_REPO_NAME::${{ env.CWA_GITHUB_TEST_REPO_NAME }}" + echo "::set-output name=CWA_GITHUB_TEST_REPO_URL::${{ env.CWA_GITHUB_TEST_REPO_URL }}" + echo "::set-output name=CWA_GITHUB_TEST_REPO_BRANCH::${{ env.CWA_GITHUB_TEST_REPO_BRANCH }}" + echo "::set-output name=ECR_INTEGRATION_TEST_REPO::cwagent-integration-test" + echo "::set-output name=ECR_OPERATOR_REPO::$(echo "${{ vars.ECR_OPERATOR_STAGING_REPO }}" | awk -F'/' '{print $NF}')" + echo "::set-output name=ECR_TARGET_ALLOCATOR_REPO::$(echo "${{ vars.ECR_TARGET_ALLOCATOR_STAGING_REPO }}" | awk -F'/' '{print $NF}')" + + - name: Echo test variables + run: | + echo "CWA_GITHUB_TEST_REPO_NAME: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_NAME }}" + echo "CWA_GITHUB_TEST_REPO_URL: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_URL }}" + echo "CWA_GITHUB_TEST_REPO_BRANCH: ${{ steps.set-outputs.outputs.CWA_GITHUB_TEST_REPO_BRANCH }}" + echo "ECR_INTEGRATION_TEST_REPO: ${{ steps.set-outputs.outputs.ECR_INTEGRATION_TEST_REPO }}" + echo "ECR_OPERATOR_REPO: ${{ steps.set-outputs.outputs.ECR_OPERATOR_REPO }}" + echo "ECR_TARGET_ALLOCATOR_REPO: ${{ steps.set-outputs.outputs.ECR_TARGET_ALLOCATOR_REPO }}" + + GenerateTestMatrix: + needs: [BuildAgent, BuildOperator] + name: 'GenerateTestMatrix' + runs-on: ubuntu-latest + outputs: + eks_e2e_matrix: ${{ steps.set-matrix.outputs.eks_e2e_matrix }} + steps: + - uses: actions/checkout@v3 + with: + repository: ${{env.CWA_GITHUB_TEST_REPO_NAME}} + ref: ${{env.CWA_GITHUB_TEST_REPO_BRANCH}} + + - name: Set up Go 1.x + uses: actions/setup-go@v4 + with: + go-version: ~1.22.2 + + - name: Generate matrix + id: set-matrix + run: | + go run generator/test_case_generator.go -e2e + echo "::set-output name=eks_e2e_matrix::$(echo $(cat generator/resources/eks_e2e_complete_test_matrix.json))" + + - name: Echo test plan matrix + run: | + echo "eks_e2e_matrix: ${{ steps.set-matrix.outputs.eks_e2e_matrix }}" \ No newline at end of file diff --git a/.github/workflows/eks-e2e-test.yml b/.github/workflows/eks-e2e-test.yml new file mode 100644 index 0000000000..31edb07b0a --- /dev/null +++ b/.github/workflows/eks-e2e-test.yml @@ -0,0 +1,160 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: MIT + +name: Reusable EKS E2E Test + +env: + TERRAFORM_AWS_ASSUME_ROLE_DURATION: 14400 # 4 hours + +on: + workflow_call: + inputs: + terraform_dir: + required: true + type: string + job_id: + required: true + type: string + test_props: + required: true + type: string + test_repo_name: + required: true + type: string + test_repo_url: + required: true + type: string + test_repo_branch: + required: true + type: string + cloudwatch_agent_repository: + required: true + type: string + cloudwatch_agent_tag: + required: true + type: string + cloudwatch_agent_operator_repository: + required: true + type: string + cloudwatch_agent_target_allocator_repository: + required: false + type: string + cloudwatch_agent_operator_tag: + required: true + type: string + region: + required: true + type: string + helm_charts_branch: + required: true + type: string + terraform_assume_role: + required: true + type: string + agent_config: + required: true + type: string + prometheus_config: + required: false + type: string + default: "" + otel_config: + required: false + type: string + default: "" + sample_app: + required: true + type: string + +jobs: + EKSE2ETest: + name: 'EKSE2ETest' + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + arrays: ${{ fromJson(inputs.test_props) }} + permissions: + id-token: write + contents: read + steps: + - uses: actions/checkout@v3 + with: + repository: ${{inputs.test_repo_name}} + ref: ${{inputs.test_repo_branch}} + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + role-to-assume: ${{ inputs.terraform_assume_role }} + aws-region: ${{ inputs.region }} + role-duration-seconds: ${{ env.TERRAFORM_AWS_ASSUME_ROLE_DURATION }} + + - name: Cache if success + id: cache_if_success + uses: actions/cache@v3 + with: + path: go.mod + key: ${{inputs.region}}-${{ github.sha }}-${{ matrix.arrays.os }}-${{ matrix.arrays.arc }}-${{ matrix.arrays.test_dir }} + + - name: Login ECR + id: login-ecr + if: steps.cache_if_success.outputs.cache-hit != 'true' + uses: aws-actions/amazon-ecr-login@v2 + + - name: Verify Terraform version + if: steps.cache_if_success.outputs.cache-hit != 'true' + run: terraform --version + + - name: Terraform apply + if: steps.cache_if_success.outputs.cache-hit != 'true' + uses: nick-fields/retry@v2 + with: + max_attempts: 3 + timeout_minutes: 60 + retry_wait_seconds: 5 + command: | + if [ "${{ inputs.terraform_dir }}" != "" ]; then + cd "${{ inputs.terraform_dir }}" + else + cd terraform/eks/e2e + fi + + terraform init + if terraform apply --auto-approve \ + -var="region=${{ inputs.region }}" \ + -var="k8s_version=${{ matrix.arrays.k8s_version }}" \ + -var="helm_charts_branch=${{ inputs.helm_charts_branch }}" \ + -var="cloudwatch_agent_repository_url=${{ steps.login-ecr.outputs.registry }}" \ + -var="cloudwatch_agent_repository=${{ inputs.cloudwatch_agent_repository }}" \ + -var="cloudwatch_agent_tag=${{ inputs.cloudwatch_agent_tag }}" \ + -var="cloudwatch_agent_operator_repository_url=${{ steps.login-ecr.outputs.registry }}" \ + -var="cloudwatch_agent_operator_repository=${{ inputs.cloudwatch_agent_operator_repository }}" \ + -var="cloudwatch_agent_operator_tag=${{ inputs.cloudwatch_agent_operator_tag }}" \ + -var="cloudwatch_agent_target_allocator_repository_url=${{ steps.login-ecr.outputs.registry }}" \ + -var="cloudwatch_agent_target_allocator_repository=${{ inputs.cloudwatch_agent_target_allocator_repository }}" \ + -var="cloudwatch_agent_target_allocator_tag=${{ inputs.cloudwatch_agent_operator_tag }}" \ + -var="test_dir=${{ matrix.arrays.test_dir }}" \ + -var="agent_config=${{ inputs.agent_config }}" \ + -var="prometheus_config=${{ inputs.prometheus_config }}" \ + -var="otel_config=${{ inputs.otel_config }}" \ + -var="sample_app=${{ inputs.sample_app }}"; then + terraform destroy --auto-approve + else + terraform destroy --auto-approve && exit 1 + fi + + - name: Terraform destroy + if: ${{ cancelled() || failure() }} + uses: nick-fields/retry@v2 + with: + max_attempts: 3 + timeout_minutes: 8 + retry_wait_seconds: 5 + command: | + if [ "${{ inputs.terraform_dir }}" != "" ]; then + cd "${{ inputs.terraform_dir }}" + else + cd terraform/eks/e2e + fi + terraform destroy --auto-approve