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

feat: add chainsaw based e2e tests #506

Merged
merged 38 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a8d7895
feat: add chainsaw based e2e tests
eddycharly Nov 14, 2024
f2d7e99
Add kyverno-chainsaw from nixpkgs:unstable to flake.nix
hjkatz Nov 15, 2024
733375c
rename make target
eddycharly Nov 15, 2024
6d3903f
spacing formatting
hjkatz Nov 22, 2024
5fc9a33
Add specific deploy target for e2e tests
hjkatz Nov 22, 2024
5a6f16a
Rename job to build-and-test
hjkatz Nov 22, 2024
a1af691
Add tests/ dir to changes detection
hjkatz Nov 22, 2024
e99bcb0
Add Makefile to changes detection
hjkatz Nov 22, 2024
2e482ad
Trigger Makefile changes
hjkatz Nov 22, 2024
deeeaa6
Update changes outputs
hjkatz Nov 22, 2024
cc1f594
Trigger change in Makefile
hjkatz Nov 22, 2024
a510747
Update changes triggers for build-and-test
hjkatz Nov 22, 2024
01e5f1e
Trigger Makefile changes
hjkatz Nov 22, 2024
76473d4
Adjust make target
hjkatz Nov 22, 2024
9482f87
Adjust make target
hjkatz Nov 22, 2024
87de8ba
Adjust ci envars
hjkatz Nov 22, 2024
d68ec47
Trigger change in Makefile
hjkatz Nov 22, 2024
77333f9
Change workflows to trigger on both the main repo and branch repo
hjkatz Nov 22, 2024
152e2cc
Add fake-api-key and fake-authtoken where necesarry
hjkatz Nov 22, 2024
89e8fbf
Use correct variable
hjkatz Nov 22, 2024
41657b3
Try with no quotes
hjkatz Nov 22, 2024
9839386
Separate out composite actions
hjkatz Nov 25, 2024
3440c3d
With proper directory
hjkatz Nov 25, 2024
e367319
With local paths
hjkatz Nov 25, 2024
be2e25a
With checkout prior
hjkatz Nov 25, 2024
5881ef6
With local path
hjkatz Nov 25, 2024
92940b7
With .yaml
hjkatz Nov 25, 2024
a8d0e29
With directories
hjkatz Nov 26, 2024
69b13ca
With correct outputs syntax
hjkatz Nov 26, 2024
080193a
With changes id
hjkatz Nov 26, 2024
2d57f10
Test with no if conditional
hjkatz Nov 26, 2024
eae599e
Without env key
hjkatz Nov 26, 2024
0d7684d
With required shell field
hjkatz Nov 26, 2024
b2cca68
With secrets as inputs
hjkatz Nov 26, 2024
9bb6a63
With proper if statements
hjkatz Nov 26, 2024
226725c
With if conditional back
hjkatz Nov 26, 2024
5ce981a
Test with echo
hjkatz Nov 26, 2024
0be0024
With outputs on job too
hjkatz Nov 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions .github/actions/build-and-test/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Action - Build and Test
description: "Build and test the operator (with optional e2e tests)"

inputs:
run-e2e:
description: "Run e2e tests"
required: false
default: "false"
go-version:
description: "Go version to use"
required: true
ngrok-api-key:
description: "NGROK_API_KEY for e2e tests, if enabled"
required: false
default: "fake-api-key"
ngrok-authtoken:
description: "NGROK_AUTHTOKEN for e2e tests, if enabled"
required: false
default: "fake-authtoken"

runs:
using: "composite"
steps:
- uses: debianmaster/actions-k3s@master
id: k3s
with:
version: 'latest'

- shell: bash
run: |
kubectl get nodes
kubectl get pods -A

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ inputs.go-version }}

- name: Build
shell: bash
run: make build

- name: Lint
shell: bash
run: make lint

- name: Setup Envtest
shell: bash
run: make envtest

- name: Test
shell: bash
run: make test

- name: Build the Docker image
shell: bash
run: make docker-build

- name: Deploy controller to local cluster
shell: bash
env:
# deploy with 1-click demo mode when not running e2e tests
DEPLOY_ONE_CLICK_DEMO_MODE: ${{ inputs.run-e2e == 'true' && 'false' || 'true' }}
NGROK_API_KEY: ${{ inputs.ngrok-api-key }}
NGROK_AUTHTOKEN: ${{ inputs.ngrok-authtoken }}
E2E_BINDING_NAME: k8s/e2e-${{ github.run_id }}
run: |
# create some namespaces for bindings tests
kubectl create ns e2e || true

# deploy ngrok-op for e2e tests
make deploy_for_e2e

- name: Check if controller is up
shell: bash
run: |
kubectl get nodes
kubectl get pods -A

- name: Install cosign
if: ${{ inputs.run-e2e == 'true' }}
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da # v3.7.0
- name: Install chainsaw
if: ${{ inputs.run-e2e == 'true' }}
uses: kyverno/action-install-chainsaw@d311eacde764f806c9658574ff64c9c3b21f8397 # v0.2.11
with:
verify: true

- name: Run e2e tests
shell: bash
if: ${{ inputs.run-e2e == 'true' }}
run: |
make e2e-tests

# best effort to remove ngrok k8s resources from cluster
# this allows our finalizers to delete upstream ngrok API resources too
# that hopefully helps not pollute our ngrok-operator-ci account
- name: Cleanup e2e tests
shell: bash
if: ${{ inputs.run-e2e == 'true' }}
run: |
make e2e-clean
52 changes: 52 additions & 0 deletions .github/actions/changes/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Action - Changes
description: "Detect changes in the repository"

outputs:
charts:
description: "If any part of Helm charts have changed"
value: ${{ steps.filter.outputs.charts }}
chartyaml:
description: "If the Helm Chart.yaml has changed"
value: ${{ steps.filter.outputs.chartyaml }}
go:
description: "If the go (build) files have changed"
value: ${{ steps.filter.outputs.go }}
tag:
description: "If the tag (VERSION) has changed"
value: ${{ steps.filter.outputs.tag }}
tests:
description: "If the tests have changed"
value: ${{ steps.filter.outputs.tests }}
make:
description: "If the Makefile has changed"
value: ${{ steps.filter.outputs.make }}

runs:
using: "composite"
steps:
- name: filter
id: filter
uses: dorny/[email protected]
with:
filters: |
chartyaml:
- 'helm/ngrok-operator/Chart.yaml'
charts:
- 'helm/ngrok-operator/**'
- 'scripts/e2e.sh'
go:
- '**.go'
- 'go.mod'
- 'go.sum'
- 'cmd/**'
- 'internal/**'
- 'pkg/**'
- 'Dockerfile'
- 'scripts/e2e.sh'
- 'VERSION'
tests:
- 'test/**'
make:
- 'Makefile'
tag:
- 'VERSION'
100 changes: 36 additions & 64 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
pull_request_target:
branches: [ "main" ]

env:
GO_VERSION: '1.23'
Expand All @@ -13,38 +15,20 @@ jobs:

changes:
runs-on: ubuntu-latest
outputs:
charts: ${{ steps.filter.outputs.charts }}
chartyaml: ${{ steps.filter.outputs.chartyaml }}
go: ${{ steps.filter.outputs.go }}
tag: ${{ steps.filter.outputs.tag }}
permissions:
contents: read
pull-requests: read
outputs:
charts: ${{ steps.changes.outputs.charts }}
chartyaml: ${{ steps.changes.outputs.chartyaml }}
go: ${{ steps.changes.outputs.go }}
tag: ${{ steps.changes.outputs.tag }}
tests: ${{ steps.changes.outputs.tests }}
make: ${{ steps.changes.outputs.make }}
steps:
- name: Checkout repo
uses: actions/checkout@v3
- id: filter
uses: dorny/[email protected]
with:
filters: |
chartyaml:
- 'helm/ngrok-operator/Chart.yaml'
charts:
- 'helm/ngrok-operator/**'
- 'scripts/e2e.sh'
go:
- '**.go'
- 'go.mod'
- 'go.sum'
- 'cmd/**'
- 'internal/**'
- 'pkg/**'
- 'Dockerfile'
- 'scripts/e2e.sh'
- 'VERSION'
tag:
- 'VERSION'
- uses: actions/checkout@v3
- uses: "./.github/actions/changes"
id: changes

# Make sure that Kubebuilder autogenerated files are up to date.
kubebuilder-diff:
Expand Down Expand Up @@ -105,54 +89,42 @@ jobs:
- run: git diff --exit-code go.mod
- run: git diff --exit-code go.sum

echo:
runs-on: ubuntu-latest
needs: [changes]
steps:
- uses: actions/checkout@v3
- run: |
echo "go: ${{ needs.changes.outputs.go }}"
echo "charts: ${{ needs.changes.outputs.charts }}"
echo "chartyaml: ${{ needs.changes.outputs.chartyaml }}"
echo "tests: ${{ needs.changes.outputs.tests }}"
echo "make: ${{ needs.changes.outputs.make }}"

build:
build-and-test:
runs-on: ubuntu-latest
needs:
- changes
- kubebuilder-diff
if: |
(needs.changes.outputs.go == 'true') ||
(needs.changes.outputs.charts == 'true')
(needs.changes.outputs.charts == 'true') ||
(needs.changes.outputs.chartyaml == 'true') ||
(needs.changes.outputs.tests == 'true') ||
(needs.changes.outputs.make == 'true')
permissions:
contents: read
pull-requests: read
steps:
- uses: actions/checkout@v3

- uses: debianmaster/actions-k3s@master
id: k3s
with:
version: 'latest'
- run: |
kubectl get nodes
kubectl get pods -A

- name: Set up Go
uses: actions/setup-go@v3
- uses: "./.github/actions/build-and-test"
with:
# this workflow is for incoming PRs, so we want to skip e2e tests
# and deploy the demo mode because our api keys are not available
# on contributor's forks
run-e2e: false
go-version: ${{ env.GO_VERSION }}

- name: Build
run: make build

- name: Lint
run: make lint

- name: Setup Envtest
run: make envtest

- name: Test
run: make test

- name: Build the Docker image
run: make docker-build

- name: Deploy controller to local cluster
run: make deploy NGROK_API_KEY=fake-ci-key NGROK_AUTHTOKEN=fake-ci-token

- name: Check if controller is up
run: |
kubectl get nodes
kubectl get pods -A

helm:
runs-on: ubuntu-latest
timeout-minutes: 15
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Tests
on:
push:
branches: [ "main" ]
pull_request_target:
branches: [ "main" ]

env:
GO_VERSION: '1.23'
DOCKER_BUILDX_PLATFORMS: linux/amd64,linux/arm64

jobs:
changes:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
outputs:
charts: ${{ steps.changes.outputs.charts }}
chartyaml: ${{ steps.changes.outputs.chartyaml }}
go: ${{ steps.changes.outputs.go }}
tag: ${{ steps.changes.outputs.tag }}
tests: ${{ steps.changes.outputs.tests }}
make: ${{ steps.changes.outputs.make }}
steps:
- uses: actions/checkout@v3
- uses: "./.github/actions/changes"
id: changes

build-and-test:
runs-on: ubuntu-latest
needs:
- changes
- kubebuilder-diff
if: |
(needs.changes.outputs.go == 'true') ||
(needs.changes.outputs.charts == 'true') ||
(needs.changes.outputs.chartyaml == 'true') ||
(needs.changes.outputs.tests == 'true') ||
(needs.changes.outputs.make == 'true')
permissions:
contents: read
pull-requests: read
steps:
- uses: actions/checkout@v3
- uses: "./.github/actions/build-and-test"
with:
run-e2e: true
go-version: ${{ env.GO_VERSION }}
ngrok-api-key: ${{ secrets.NGROK_CI_API_KEY }}
ngrok-authtoken: ${{ secrets.NGROK_CI_AUTHTOKEN }}
Loading