From a31cbd446a5bd230f7035e3eb2837206d948b2ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Thu, 26 Sep 2024 09:57:33 +0000 Subject: [PATCH] fix: no-cluster option (#2014) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Charles-Edouard Brétéché --- .github/workflows/tests.yaml | 15 +++++++++++++++ Makefile | 9 ++++++++- pkg/runner/processors/context.go | 6 ++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 00a7a2a42..05163c8c4 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -82,6 +82,21 @@ jobs: set -e make e2e-tests + e2e-tests-no-cluster: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - name: Setup Go + uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 + with: + go-version-file: go.mod + cache-dependency-path: go.sum + - name: Run tests + run: | + set -e + make e2e-tests-no-cluster + e2e-test-ko: runs-on: ubuntu-latest steps: diff --git a/Makefile b/Makefile index 02c44a929..24d2078b7 100644 --- a/Makefile +++ b/Makefile @@ -298,7 +298,14 @@ tests: $(CLI_BIN) e2e-tests: ## Run e2e tests e2e-tests: $(CLI_BIN) @echo Running e2e tests... >&2 - @./$(CLI_BIN) test --test-dir ./testdata/e2e --remarshal --config ./testdata/e2e/config.yaml --values ./testdata/e2e/values.yaml + @./$(CLI_BIN) test ./testdata/e2e --remarshal --config ./testdata/e2e/config.yaml --values ./testdata/e2e/values.yaml + +.PHONY: e2e-tests-no-cluster +e2e-tests-no-cluster: ## Run e2e tests with --no-cluster +e2e-tests-no-cluster: $(CLI_BIN) + @echo Running e2e tests with --no-cluster... >&2 + @./$(CLI_BIN) test testdata/e2e/examples/script-env --no-cluster --remarshal --config ./testdata/e2e/config.yaml --values ./testdata/e2e/values.yaml + @./$(CLI_BIN) test testdata/e2e/examples/dynamic-clusters --no-cluster --remarshal --config ./testdata/e2e/config.yaml --values ./testdata/e2e/values.yaml .PHONY: e2e-tests-ko e2e-tests-ko: ## Run e2e tests from a docker container diff --git a/pkg/runner/processors/context.go b/pkg/runner/processors/context.go index 7678fc5cc..d24a8c35e 100644 --- a/pkg/runner/processors/context.go +++ b/pkg/runner/processors/context.go @@ -44,7 +44,7 @@ func setupContextData(ctx context.Context, tc engine.Context, data contextData) return tc, nil, err } else if _, clusterClient, err := tc.CurrentClusterClient(); err != nil { return tc, nil, err - } else { + } else if clusterClient != nil { if err := clusterClient.Get(ctx, client.Key(namespace), namespace.DeepCopy()); err != nil { if !errors.IsNotFound(err) { return tc, nil, err @@ -56,7 +56,9 @@ func setupContextData(ctx context.Context, tc engine.Context, data contextData) } ns = namespace } - tc = engine.WithNamespace(ctx, tc, ns.GetName()) + if ns != nil { + tc = engine.WithNamespace(ctx, tc, ns.GetName()) + } } if _tc, err := engine.WithBindings(ctx, tc, data.bindings...); err != nil { return tc, ns, err