Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 8 additions & 7 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- '*'
- 'release/*'
push:
branches:
- 'main'
Expand All @@ -15,17 +16,17 @@ jobs:
golangci-lint:
runs-on: ubuntu-latest
steps:
- name: setup golang
uses: actions/setup-go@v3
with:
go-version: '^1.18'

- name: checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: setup golang
uses: actions/setup-go@v4
with:
go-version: '^1.19'

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3.2.0
uses: golangci/golangci-lint-action@v3.6.0
with:
version: v1.45.2
skip-cache: true # actions/setup-go from v4 handles caching for us
158 changes: 135 additions & 23 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,51 +1,163 @@
name: tests

concurrency:
# Run only for most recent commit in PRs but for all tags and commits on main
# Ref: https://docs.github.com/en/actions/using-jobs/using-concurrency
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }}
cancel-in-progress: true

on:
pull_request:
branches:
- 'main'
- 'main'
- 'release/*'
push:
branches:
- 'main'
- 'main'
workflow_dispatch: {}

jobs:
tests-and-coverage:
environment: "integration-tests"

unit-tests:
runs-on: ubuntu-latest
steps:

- name: checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: setup golang
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: '^1.18'
go-version: '^1.19'

- name: cache go modules
uses: actions/cache@v3
- name: run unit tests
run: make test.unit

# We're using a retry mechanism for codecov to ensure we do get the reports
# uploaded. The alternative is to use fail_ci_if_error: false, but that
# somewhat defeats the purpose of uploading those reports. Why bother uploading
# if we don't care if the upload's successful?
- name: Upload coverage to Codecov
if: steps.detect_if_should_run.outputs.result == 'true'
uses: Wandalen/wretry.action@v1.3.0
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-build-codegen-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-build-codegen-
action: codecov/codecov-action@v3
with: |
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
flags: unit-test
files: unit.coverage.out
verbose: true
attempt_limit: 10
attempt_delay: 30000

setup-integration-tests:
runs-on: ubuntu-latest
outputs:
test_names: ${{ steps.set_test_names.outputs.test_names }}
steps:

- uses: actions/checkout@v3

- id: set_test_names
name: Set test names
working-directory: test/integration/
# grep magic described in https://unix.stackexchange.com/a/13472
# sed to add the extra $ is because some of our test names overlap. we need it so the -run regex only matches one test
run: |
echo "test_names=$(grep -shoP "(?<=^func )(Test[a-zA-z_0-9]+)(?=\(t \*testing.T\) {)" * | sed -e "s/$/\$/"| jq -R . | jq -cs .)" >> $GITHUB_OUTPUT

- name: Print test names
run: echo "Test names ${{ steps.set_test_names.outputs.test_names }}"

integration-tests:
needs:
- setup-integration-tests
strategy:
fail-fast: false
matrix:
test: ${{ fromJSON(needs.setup-integration-tests.outputs.test_names) }}
runs-on: ubuntu-latest
steps:
# This step is needed to avoid running the integration tests requiring an enterprise license
# if the secrets are not available.
- name: Detect if we should run test cases requring an enterprise license (have required secrets)
id: detect_if_should_run_enterprise
run: echo "result=${{ secrets.PULP_PASSWORD != '' }}" >> $GITHUB_OUTPUT

- name: Set environment variable to enable test cases requiring an enterprise license
if: steps.detect_if_should_run_enterprise.outputs.result == 'true'
id: set_run_enterprise_env
run: echo "KTF_TEST_RUN_ENTERPRISE_CASES=true" >> $GITHUB_ENV

- name: checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: run unit tests
run: make test.unit
- uses: Kong/kong-license@master
if: steps.detect_if_should_run_enterprise.outputs.result == 'true'
id: license
with:
password: ${{ secrets.PULP_PASSWORD }}

- name: setup golang
uses: actions/setup-go@v4
with:
go-version: '^1.19'

- name: run integration tests
- name: run integration test ${{ matrix.test }}
run: make test.integration
env:
KONG_LICENSE_DATA: ${{ secrets.KONG_LICENSE_DATA }}
NCPU: 2 # it was found that github actions (specifically) did not seem to perform well when spawning
# multiple kind clusters within a single job so this is hardcoded to 2 to ensure a limit of 2 clusters at any one point.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
KTF_TEST_KONG_PULL_USERNAME: ${{ secrets.GHA_DOCKERHUB_PULL_USER }}
KTF_TEST_KONG_PULL_PASSWORD: ${{ secrets.GHA_KONG_ORG_DOCKERHUB_PUBLIC_TOKEN }}
KONG_LICENSE_DATA: ${{ steps.license.outputs.license }}
TEST_RUN: ${{ matrix.test }}
NCPU: 1

# We're using a retry mechanism for codecov to ensure we do get the reports
# uploaded. The alternative is to use fail_ci_if_error: false, but that
# somewhat defeats the purpose of uploading those reports. Why bother uploading
# if we don't care if the upload's successful?
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: Wandalen/wretry.action@v1.3.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
files: unit.coverage.out,integration.coverage.out
verbose: true
action: codecov/codecov-action@v3
with: |
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
flags: integration-test
files: integration.coverage.out
verbose: true
attempt_limit: 10
attempt_delay: 30000

integration-tests-passed:
needs: integration-tests
if: always() && !contains(needs.*.result, 'failure')
runs-on: ubuntu-latest
steps:
- name: integrations tests pased
run: echo all integrations tests passed

setup-e2e-tests:
runs-on: ubuntu-latest
outputs:
test_names: ${{ steps.set_test_names.outputs.test_names }}
steps:

- uses: actions/checkout@v3

- id: set_test_names
name: Set test names
working-directory: test/e2e/
# grep magic described in https://unix.stackexchange.com/a/13472
# sed to add the extra $ is because some of our test names overlap. we need it so the -run regex only matches one test
run: |
echo "test_names=$(grep -shoP "(?<=^func )(Test[a-zA-z_0-9]+)(?=\(t \*testing.T\) {)" * | sed -e "s/$/\$/"| jq -R . | jq -cs .)" >> $GITHUB_OUTPUT

- name: Print test names
run: echo "Test names ${{ steps.set_test_names.outputs.test_names }}"
63 changes: 59 additions & 4 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ linters:
enable:
- asciicheck
- bodyclose
- deadcode
- depguard
- dogsled
- durationcheck
- errcheck
- exhaustive
- exportloopref
- forbidigo
- gochecknoinits
- gofmt
- goimports
- gomnd
- gomodguard
- gosec
- gci
- gosimple
- govet
- importas
Expand All @@ -27,9 +28,63 @@ linters:
- predeclared
- revive
- staticcheck
- structcheck
- typecheck
- unconvert
- unparam
- varcheck
- unused
- wastedassign

linters-settings:
gci:
sections:
- standard
- default
- prefix(github.com/kong/kubernetes-testing-framework)
gomodguard:
blocked:
modules:
- github.com/ghodss/yaml:
recommendations:
- sigs.k8s.io/yaml
- gopkg.in/yaml.v2:
recommendations:
- sigs.k8s.io/yaml
- gopkg.in/yaml.v3:
recommendations:
- sigs.k8s.io/yaml
- github.com/pkg/errors:
recommendations:
- fmt
- errors
- golang.org/x/net/context:
recommendations:
- context
importas:
no-unaliased: true
alias:
- pkg: k8s.io/api/core/v1
alias: corev1
- pkg: k8s.io/api/apps/v1
alias: appsv1
- pkg: k8s.io/api/networking/v1
alias: netv1
- pkg: k8s.io/api/networking/v1beta1
alias: netv1beta1
- pkg: k8s.io/api/discovery/v1
alias: discoveryv1
- pkg: k8s.io/api/extensions/v1beta1
alias: extv1beta1
- pkg: k8s.io/api/rbac/v1
alias: rbacv1

- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
alias: metav1
- pkg: sigs.k8s.io/gateway-api/apis/(v[\w\d]+)
alias: gateway${1}
forbidigo:
exclude_godoc_examples: false
forbid:
- 'CoreV1\(\)\.Endpoints(# use DiscoveryV1 EndpointSlices API instead)?'
- 'corev1\.Endpoint(# use DiscoveryV1 EndpointSlices API instead)?'
issues:
fix: true
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v0.15.2

- Upgraded the metallb implementation to match the implementation from
0.31.

## v0.15.1

- Added missing Kuma addon CLI entry.
Expand Down
14 changes: 12 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.5.0
github.com/spf13/viper v1.12.0
github.com/stretchr/testify v1.8.0
github.com/stretchr/testify v1.8.2
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect
golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2
golang.org/x/text v0.3.7 // indirect
Expand All @@ -34,7 +34,12 @@ require (

require github.com/docker/go-connections v0.4.0 // indirect

require sigs.k8s.io/controller-runtime v0.12.2
require (
github.com/avast/retry-go/v4 v4.3.4
sigs.k8s.io/controller-runtime v0.12.2
sigs.k8s.io/kustomize/api v0.10.1
sigs.k8s.io/kustomize/kyaml v0.13.0
)

require (
cloud.google.com/go/compute v1.7.0 // indirect
Expand All @@ -47,6 +52,7 @@ require (
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-logr/logr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
Expand All @@ -58,6 +64,7 @@ require (
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.1.0 // indirect
github.com/googleapis/gax-go/v2 v2.4.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand All @@ -70,6 +77,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
Expand All @@ -85,7 +93,9 @@ require (
github.com/tidwall/gjson v1.14.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
go.opencensus.io v0.23.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/sys v0.0.0-20220624220833-87e55d714810 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
Expand Down
Loading