Skip to content

Commit

Permalink
ci: allow making tests workflow green for external contributors (#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
czeslavo authored Mar 22, 2023
1 parent ba1dcf6 commit 238e12e
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ jobs:

- name: Run golangci-lint
uses: golangci/[email protected]
with:
skip-cache: true # actions/setup-go from v4 handles caching for us
13 changes: 13 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,32 @@ jobs:
test: ${{ fromJSON(needs.setup-integration-tests.outputs.test_names) }}
runs-on: ubuntu-latest
steps:
# This step is needed to avoid running the integration tests if the secrets are not available.
# TODO: remove this step once we have a way to run integration tests on forks.
# https://github.com/Kong/kubernetes-testing-framework/issues/596
- name: Detect if we should run (have required secrets)
id: detect_if_should_run
run: echo "result=${{ secrets.PULP_PASSWORD != '' }}" >> $GITHUB_OUTPUT

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

- uses: Kong/kong-license@master
if: steps.detect_if_should_run.outputs.result == 'true'
id: license
with:
password: ${{ secrets.PULP_PASSWORD }}

- name: setup golang
if: steps.detect_if_should_run.outputs.result == 'true'
uses: actions/setup-go@v4
with:
go-version: '^1.19'

- name: run integration test ${{ matrix.test }}
if: steps.detect_if_should_run.outputs.result == 'true'
run: make test.integration
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -112,6 +121,7 @@ jobs:
NCPU: 1

- name: Upload coverage to Codecov
if: steps.detect_if_should_run.outputs.result == 'true'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -132,6 +142,9 @@ jobs:
environment: gcloud
runs-on: ubuntu-latest
steps:
# This step is needed to avoid running the e2e tests if the secrets are not available.
# TODO: remove this step once we have a way to run integration tests on forks.
# https://github.com/Kong/kubernetes-testing-framework/issues/596
- name: Detect if we should run (have required secrets)
id: detect_if_should_run
run: echo "result=${{ secrets.PULP_PASSWORD != '' && secrets.GOOGLE_APPLICATION_CREDENTIALS != '' }}" >> $GITHUB_OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion pkg/clusters/addons/certmanager/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (a *Addon) Ready(ctx context.Context, cluster clusters.Cluster) ([]runtime.
return nil, true, nil
}

func (a *Addon) DumpDiagnostics(ctx context.Context, cluster clusters.Cluster) (map[string][]byte, error) {
func (a *Addon) DumpDiagnostics(context.Context, clusters.Cluster) (map[string][]byte, error) {
diagnostics := make(map[string][]byte)
return diagnostics, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/clusters/addons/httpbin/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (a *Addon) Ready(ctx context.Context, cluster clusters.Cluster) (waitForObj
return utils.IsNamespaceAvailable(ctx, cluster, a.namespace)
}

func (a *Addon) DumpDiagnostics(ctx context.Context, cluster clusters.Cluster) (map[string][]byte, error) {
func (a *Addon) DumpDiagnostics(context.Context, clusters.Cluster) (map[string][]byte, error) {
diagnostics := make(map[string][]byte)
return diagnostics, nil
}
2 changes: 1 addition & 1 deletion pkg/clusters/addons/istio/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (a *Addon) Ready(ctx context.Context, cluster clusters.Cluster) (waitForObj
return utils.IsNamespaceAvailable(ctx, cluster, Namespace)
}

func (a *Addon) DumpDiagnostics(ctx context.Context, cluster clusters.Cluster) (map[string][]byte, error) {
func (a *Addon) DumpDiagnostics(context.Context, clusters.Cluster) (map[string][]byte, error) {
diagnostics := make(map[string][]byte)
return diagnostics, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/clusters/addons/knative/knative.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (a *Addon) Ready(ctx context.Context, cluster clusters.Cluster) ([]runtime.
return nil, true, nil
}

func (a *Addon) DumpDiagnostics(ctx context.Context, cluster clusters.Cluster) (map[string][]byte, error) {
func (a *Addon) DumpDiagnostics(context.Context, clusters.Cluster) (map[string][]byte, error) {
diagnostics := make(map[string][]byte)
return diagnostics, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/clusters/addons/kong/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (a *Addon) Name() clusters.AddonName {
return AddonName
}

func (a *Addon) Dependencies(ctx context.Context, cluster clusters.Cluster) []clusters.AddonName {
func (a *Addon) Dependencies(_ context.Context, cluster clusters.Cluster) []clusters.AddonName {
if _, ok := cluster.(*kind.Cluster); ok {
if a.proxyAdminServiceTypeLoadBalancer {
return []clusters.AddonName{
Expand Down Expand Up @@ -361,7 +361,7 @@ func (a *Addon) Delete(ctx context.Context, cluster clusters.Cluster) error {

// delete the chart release from the cluster
stderr := new(bytes.Buffer)
cmd := exec.Command("helm", "--kubeconfig", kubeconfig.Name(), "uninstall", DefaultDeploymentName, "--namespace", a.namespace) //nolint:gosec
cmd := exec.CommandContext(ctx, "helm", "--kubeconfig", kubeconfig.Name(), "uninstall", DefaultDeploymentName, "--namespace", a.namespace) //nolint:gosec
cmd.Stdout = io.Discard
cmd.Stderr = stderr
if err := cmd.Run(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/clusters/addons/kuma/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (a *Addon) Delete(ctx context.Context, cluster clusters.Cluster) error {

// delete the chart release from the cluster
stderr := new(bytes.Buffer)
cmd := exec.Command("helm", "--kubeconfig", kubeconfig.Name(), "uninstall", DefaultReleaseName, "--namespace", Namespace) //nolint:gosec
cmd := exec.CommandContext(ctx, "helm", "--kubeconfig", kubeconfig.Name(), "uninstall", DefaultReleaseName, "--namespace", Namespace) //nolint:gosec
cmd.Stdout = io.Discard
cmd.Stderr = stderr
if err := cmd.Run(); err != nil {
Expand All @@ -195,7 +195,7 @@ func (a *Addon) Ready(ctx context.Context, cluster clusters.Cluster) (waitForObj
return utils.IsNamespaceAvailable(ctx, cluster, Namespace)
}

func (a *Addon) DumpDiagnostics(ctx context.Context, cluster clusters.Cluster) (map[string][]byte, error) {
func (a *Addon) DumpDiagnostics(context.Context, clusters.Cluster) (map[string][]byte, error) {
diagnostics := make(map[string][]byte)
return diagnostics, nil
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/clusters/addons/loadimage/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (a *Addon) Dependencies(_ context.Context, _ clusters.Cluster) []clusters.A
func (a *Addon) Deploy(ctx context.Context, cluster clusters.Cluster) error {
switch ctype := cluster.Type(); ctype {
case kind.KindClusterType:
if err := a.loadIntoKind(cluster); err != nil {
if err := a.loadIntoKind(ctx, cluster); err != nil {
return err
}
default:
Expand All @@ -53,7 +53,7 @@ func (a *Addon) Deploy(ctx context.Context, cluster clusters.Cluster) error {
return nil
}

func (a *Addon) Delete(ctx context.Context, cluster clusters.Cluster) error {
func (a *Addon) Delete(_ context.Context, cluster clusters.Cluster) error {
switch ctype := cluster.Type(); ctype {
case kind.KindClusterType:
// per https://github.com/kubernetes-sigs/kind/issues/658 this is basically impossible
Expand All @@ -66,12 +66,12 @@ func (a *Addon) Delete(ctx context.Context, cluster clusters.Cluster) error {
}
}

func (a *Addon) Ready(ctx context.Context, cluster clusters.Cluster) ([]runtime.Object, bool, error) {
func (a *Addon) Ready(context.Context, clusters.Cluster) ([]runtime.Object, bool, error) {
// no way to verify this, we rely on Deploy's cmd.Run() not failing
return nil, a.loaded, nil
}

func (a *Addon) DumpDiagnostics(ctx context.Context, cluster clusters.Cluster) (map[string][]byte, error) {
func (a *Addon) DumpDiagnostics(context.Context, clusters.Cluster) (map[string][]byte, error) {
diagnostics := make(map[string][]byte)
return diagnostics, nil
}
5 changes: 3 additions & 2 deletions pkg/clusters/addons/loadimage/cluster_implementations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package loadimage

import (
"bytes"
"context"
"fmt"
"io"
"os/exec"

"github.com/kong/kubernetes-testing-framework/pkg/clusters"
)

func (a *Addon) loadIntoKind(cluster clusters.Cluster) error {
func (a *Addon) loadIntoKind(ctx context.Context, cluster clusters.Cluster) error {
if len(a.images) == 0 {
return fmt.Errorf("no images provided")
}
Expand All @@ -22,7 +23,7 @@ func (a *Addon) loadIntoKind(cluster clusters.Cluster) error {
deployArgs = append(deployArgs, a.images...)

stderr := new(bytes.Buffer)
cmd := exec.Command("kind", deployArgs...)
cmd := exec.CommandContext(ctx, "kind", deployArgs...)
cmd.Stdout = io.Discard
cmd.Stderr = stderr

Expand Down
4 changes: 2 additions & 2 deletions pkg/clusters/addons/metallb/metallb.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (a *addon) Delete(ctx context.Context, cluster clusters.Cluster) error {

func (a *addon) Ready(ctx context.Context, cluster clusters.Cluster) ([]runtime.Object, bool, error) {
deployment, err := cluster.Client().AppsV1().Deployments(DefaultNamespace).
Get(context.TODO(), "controller", metav1.GetOptions{})
Get(ctx, "controller", metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return nil, false, nil
Expand All @@ -132,7 +132,7 @@ func (a *addon) Ready(ctx context.Context, cluster clusters.Cluster) ([]runtime.
return nil, true, nil
}

func (a *addon) DumpDiagnostics(ctx context.Context, cluster clusters.Cluster) (map[string][]byte, error) {
func (a *addon) DumpDiagnostics(context.Context, clusters.Cluster) (map[string][]byte, error) {
diagnostics := make(map[string][]byte)
return diagnostics, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/clusters/addons/registry/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ func (a *Addon) Ready(ctx context.Context, cluster clusters.Cluster) (waitForObj
return utils.IsNamespaceAvailable(ctx, cluster, Namespace)
}

func (a *Addon) DumpDiagnostics(ctx context.Context, cluster clusters.Cluster) (map[string][]byte, error) {
func (a *Addon) DumpDiagnostics(context.Context, clusters.Cluster) (map[string][]byte, error) {
diagnostics := make(map[string][]byte)
return diagnostics, nil
}
2 changes: 1 addition & 1 deletion pkg/clusters/cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestFixupObjKinds(t *testing.T) {
}
}

func TestCleanerCanBeUsedConcurrently(t *testing.T) {
func TestCleanerCanBeUsedConcurrently(*testing.T) {
cleaner := NewCleaner(nil)
for i := 0; i < 100; i++ {
i := i
Expand Down
2 changes: 1 addition & 1 deletion pkg/clusters/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func GetIngressLoadbalancerStatus(ctx context.Context, c Cluster, namespace stri
// CreateNamespace creates a new namespace in the given cluster provided a name.
func CreateNamespace(ctx context.Context, cluster Cluster, namespace string) error {
nsName := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}
_, err := cluster.Client().CoreV1().Namespaces().Create(context.Background(), nsName, metav1.CreateOptions{})
_, err := cluster.Client().CoreV1().Namespaces().Create(ctx, nsName, metav1.CreateOptions{})
if err != nil {
if !errors.IsAlreadyExists(err) {
return err
Expand Down

0 comments on commit 238e12e

Please sign in to comment.