diff --git a/.github/workflows/presubmit.yaml b/.github/workflows/presubmit.yaml index 028e56cc5a..6691c2d7f9 100644 --- a/.github/workflows/presubmit.yaml +++ b/.github/workflows/presubmit.yaml @@ -73,7 +73,7 @@ jobs: - uses: actions/setup-go@v4 with: go-version-file: 'go.mod' - - name: "Run mock tests" + - name: "Run mock samples tests" run: | ./scripts/github-actions/tests-e2e-samples env: @@ -91,7 +91,7 @@ jobs: - uses: actions/setup-go@v4 with: go-version-file: 'go.mod' - - name: "Run mock tests" + - name: "Run mock fixtures tests" run: | ./scripts/github-actions/tests-e2e-fixtures env: @@ -101,6 +101,42 @@ jobs: with: name: artifacts path: /tmp/artifacts/ + tests-e2e-fixtures-compute: + runs-on: ubuntu-latest + timeout-minutes: 60 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version-file: 'go.mod' + - name: "Run mock fixtures tests for compute service" + run: | + ./scripts/github-actions/tests-e2e-fixtures-compute + env: + ARTIFACTS: /tmp/artifacts + - name: "Upload artifacts" + uses: actions/upload-artifact@v3 + with: + name: artifacts + path: /tmp/artifacts/ + tests-e2e-fixtures-gkehub: + runs-on: ubuntu-latest + timeout-minutes: 60 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version-file: 'go.mod' + - name: "Run mock fixtures tests for gkehub service" + run: | + ./scripts/github-actions/tests-e2e-fixtures-gkehub + env: + ARTIFACTS: /tmp/artifacts + - name: "Upload artifacts" + uses: actions/upload-artifact@v3 + with: + name: artifacts + path: /tmp/artifacts/ pause-tests: runs-on: ubuntu-22.04 timeout-minutes: 60 diff --git a/scripts/github-actions/tests-e2e-fixtures b/scripts/github-actions/tests-e2e-fixtures index 30c33324f3..88a76d70ef 100755 --- a/scripts/github-actions/tests-e2e-fixtures +++ b/scripts/github-actions/tests-e2e-fixtures @@ -29,6 +29,8 @@ export KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-en echo "Running fixtures in tests/e2e..." +export SKIP_TEST_APIGROUP="compute.cnrm.cloud.google.com,gkehub.cnrm.cloud.google.com" + RUN_E2E=1 \ GOLDEN_OBJECT_CHECKS=1 \ GOLDEN_REQUEST_CHECKS=1 \ diff --git a/scripts/github-actions/tests-e2e-fixtures-compute b/scripts/github-actions/tests-e2e-fixtures-compute new file mode 100755 index 0000000000..987fea4af9 --- /dev/null +++ b/scripts/github-actions/tests-e2e-fixtures-compute @@ -0,0 +1,35 @@ +#!/bin/bash +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o nounset +set -o pipefail + +REPO_ROOT="$(git rev-parse --show-toplevel)" + +cd ${REPO_ROOT}/ + +echo "Downloading envtest assets..." +export KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use -p path) + +echo "Running compute fixtures in tests/e2e..." + +RUN_E2E=1 \ +GOLDEN_OBJECT_CHECKS=1 \ +GOLDEN_REQUEST_CHECKS=1 \ +E2E_KUBE_TARGET=envtest \ +E2E_GCP_TARGET=mock \ +ONLY_TEST_APIGROUP="compute.cnrm.cloud.google.com" \ + go test -test.count=1 -timeout 3600s -v ./tests/e2e -run TestAllInSeries/fixtures \ No newline at end of file diff --git a/scripts/github-actions/tests-e2e-fixtures-gkehub b/scripts/github-actions/tests-e2e-fixtures-gkehub new file mode 100755 index 0000000000..b48899e63d --- /dev/null +++ b/scripts/github-actions/tests-e2e-fixtures-gkehub @@ -0,0 +1,35 @@ +#!/bin/bash +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o nounset +set -o pipefail + +REPO_ROOT="$(git rev-parse --show-toplevel)" + +cd ${REPO_ROOT}/ + +echo "Downloading envtest assets..." +export KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use -p path) + +echo "Running gkehub fixtures in tests/e2e for gkehub..." + +RUN_E2E=1 \ +GOLDEN_OBJECT_CHECKS=1 \ +GOLDEN_REQUEST_CHECKS=1 \ +E2E_KUBE_TARGET=envtest \ +E2E_GCP_TARGET=mock \ +ONLY_TEST_APIGROUP="gkehub.cnrm.cloud.google.com" \ + go test -test.count=1 -timeout 3600s -v ./tests/e2e -run TestAllInSeries/fixtures \ No newline at end of file diff --git a/scripts/github-actions/tests-e2e-scenarios.sh b/scripts/github-actions/tests-e2e-scenarios.sh index 1a56e045e4..907c26bb9e 100755 --- a/scripts/github-actions/tests-e2e-scenarios.sh +++ b/scripts/github-actions/tests-e2e-scenarios.sh @@ -24,6 +24,6 @@ cd ${REPO_ROOT}/ echo "Downloading envtest assets..." export KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use -p path) -echo "Running scenarios tests for LoggingLogMetric direct reconciliation..." +echo "Running scenarios tests..." GOLDEN_REQUEST_CHECKS=1 E2E_KUBE_TARGET=envtest E2E_GCP_TARGET=mock RUN_E2E=1 \ go test -test.count=1 -timeout 360s -v ./tests/e2e -run TestE2EScript/scenarios/fields diff --git a/tests/e2e/unified_test.go b/tests/e2e/unified_test.go index c1f18c5db2..82699bfa7f 100644 --- a/tests/e2e/unified_test.go +++ b/tests/e2e/unified_test.go @@ -22,6 +22,7 @@ import ( "hash/fnv" "io" "io/ioutil" + "k8s.io/utils/strings/slices" "net/http" "net/url" "os" @@ -31,6 +32,8 @@ import ( "testing" "time" + "k8s.io/klog/v2" + "github.com/GoogleCloudPlatform/k8s-config-connector/config/tests/samples/create" opcorev1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/operator/pkg/apis/core/v1beta1" "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test" @@ -146,8 +149,21 @@ func testFixturesInSeries(ctx context.Context, t *testing.T, testPause bool, can fixtures := resourcefixture.Load(t) for _, fixture := range fixtures { fixture := fixture + group := fixture.GVK.Group + if s := os.Getenv("SKIP_TEST_APIGROUP"); s != "" { + skippedGroups := strings.Split(s, ",") + if slices.Contains(skippedGroups, group) { + klog.Infof("skipping test %s because group %q matched entries in SKIP_TEST_APIGROUP=%s", fixture.Name, group, s) + continue + } + } + if s := os.Getenv("ONLY_TEST_APIGROUP"); s != "" { + if group != s { + klog.Infof("skipping test %s because group %q did not match ONLY_TEST_APIGROUP=%s", fixture.Name, group, s) + continue + } + } // TODO(b/259496928): Randomize the resource names for parallel execution when/if needed. - t.Run(fixture.Name, func(t *testing.T) { ctx := addTestTimeout(ctx, t, subtestTimeout) @@ -192,20 +208,13 @@ func runScenario(ctx context.Context, t *testing.T, testPause bool, fixture reso // Quickly load the fixture with a dummy project, just to see if we should skip it { - primaryObject, opt := loadFixture(testgcp.GCPProject{ProjectID: "test-skip", ProjectNumber: 123456789}, uniqueID) + _, opt := loadFixture(testgcp.GCPProject{ProjectID: "test-skip", ProjectNumber: 123456789}, uniqueID) create.MaybeSkip(t, fixture.Name, opt.Create) if testPause && containsCCOrCCC(opt.Create) { t.Skipf("test case %q contains ConfigConnector or ConfigConnectorContext object(s): "+ "pause test should not run against test cases already contain ConfigConnector "+ "or ConfigConnectorContext objects", fixture.Name) } - - if s := os.Getenv("ONLY_TEST_APIGROUP"); s != "" { - group := primaryObject.GroupVersionKind().Group - if group != s { - t.Skipf("skipping test because group %q did not match ONLY_TEST_APIGROUP=%s", group, s) - } - } } // Create test harness