From 4aa8c2e6fce09ad817dddac1d70e1ba23543cfed Mon Sep 17 00:00:00 2001 From: Camila Macedo <7708031+camilamacedo86@users.noreply.github.com> Date: Fri, 11 Jul 2025 18:41:50 +0100 Subject: [PATCH] (chore): Optmize CI time and usage of resources --- Makefile | 1 + test/e2e/alphagenerate/generate_test.go | 41 ++++++++++--------------- test/e2e/setup.sh | 2 -- test/e2e/utils/test_context.go | 22 ++++++++++--- test/features.sh | 34 ++++++++++++++++++++ 5 files changed, 69 insertions(+), 31 deletions(-) create mode 100755 test/features.sh diff --git a/Makefile b/Makefile index de3b391dd76..0bed2c6b59e 100644 --- a/Makefile +++ b/Makefile @@ -156,6 +156,7 @@ test-coverage: ## Run unit tests creating the output to report coverage .PHONY: test-integration test-integration: ## Run the integration tests ./test/integration.sh + ./test/features.sh .PHONY: check-testdata check-testdata: ## Run the script to ensure that the testdata is updated diff --git a/test/e2e/alphagenerate/generate_test.go b/test/e2e/alphagenerate/generate_test.go index 67e209fdd37..bee565f1637 100644 --- a/test/e2e/alphagenerate/generate_test.go +++ b/test/e2e/alphagenerate/generate_test.go @@ -74,21 +74,24 @@ var _ = Describe("kubebuilder", func() { validateProjectFile(kbc, filepath.Join(kbc.Dir, "PROJECT")) }) - It("should regenerate project with grafana plugin with success", func() { - generateProjectWithGrafanaPlugin(kbc) - regenerateProjectWith(kbc, projectOutputDir) - validateGrafanaPlugin(projectFilePath) - }) + It("should regenerate project with plugins with success", func() { + By("Enabling the Grafana plugin") + err := kbc.Edit("--plugins", "grafana.kubebuilder.io/v1-alpha") + Expect(err).NotTo(HaveOccurred(), "Failed to edit project to enable Grafana Plugin") - It("should regenerate project with DeployImage plugin with success", func() { - generateProjectWithDeployImagePlugin(kbc) - regenerateProjectWith(kbc, projectOutputDir) - validateDeployImagePlugin(projectFilePath) - }) + By("Generate API with Deploy Image plugin") + generateAPIWithDeployImage(kbc) + + By("Enabling Helm plugin") + err = kbc.Edit("--plugins", "helm.kubebuilder.io/v1-alpha") + Expect(err).NotTo(HaveOccurred(), "Failed to edit project to enable Helm Plugin") - It("should regenerate project with helm plugin with success", func() { - generateProjectWithHelmPlugin(kbc) + By("Re-generating the project with plugins") regenerateProjectWith(kbc, projectOutputDir) + + By("By validating the expected scaffolded files") + validateGrafanaPlugin(projectFilePath) + validateDeployImagePlugin(projectFilePath) validateHelmPlugin(projectFilePath) }) }) @@ -200,19 +203,7 @@ func regenerateProjectWith(kbc *utils.TestContext, projectOutputDir string) { Expect(err).NotTo(HaveOccurred(), "Failed to regenerate project") } -func generateProjectWithGrafanaPlugin(kbc *utils.TestContext) { - By("editing project to enable Grafana plugin") - err := kbc.Edit("--plugins", "grafana.kubebuilder.io/v1-alpha") - Expect(err).NotTo(HaveOccurred(), "Failed to edit project to enable Grafana Plugin") -} - -func generateProjectWithHelmPlugin(kbc *utils.TestContext) { - By("editing project to enable Helm plugin") - err := kbc.Edit("--plugins", "helm.kubebuilder.io/v1-alpha") - Expect(err).NotTo(HaveOccurred(), "Failed to edit project to enable Helm Plugin") -} - -func generateProjectWithDeployImagePlugin(kbc *utils.TestContext) { +func generateAPIWithDeployImage(kbc *utils.TestContext) { By("creating an API with DeployImage plugin") err := kbc.CreateAPI( "--group", "crew", diff --git a/test/e2e/setup.sh b/test/e2e/setup.sh index b023a791cda..231c335127d 100755 --- a/test/e2e/setup.sh +++ b/test/e2e/setup.sh @@ -64,8 +64,6 @@ function test_cluster { docker pull busybox:1.36.1 kind load docker-image --name $KIND_CLUSTER busybox:1.36.1 - go test $(dirname "$0")/grafana $flags -timeout 30m go test $(dirname "$0")/deployimage $flags -timeout 30m go test $(dirname "$0")/v4 $flags -timeout 30m - go test $(dirname "$0")/alphagenerate $flags -timeout 30m } diff --git a/test/e2e/utils/test_context.go b/test/e2e/utils/test_context.go index 1978c179d65..0b4f6a8108c 100644 --- a/test/e2e/utils/test_context.go +++ b/test/e2e/utils/test_context.go @@ -73,11 +73,25 @@ func NewTestContext(binaryName string, env ...string) (*TestContext, error) { ServiceAccount: fmt.Sprintf("e2e-%s-controller-manager", testSuffix), CmdContext: cc, } - k8sVersion, err := kubectl.Version() + var k8sVersion *KubernetesVersion + v, err := kubectl.Version() if err != nil { - return nil, fmt.Errorf("failed to get kubernetes version: %w", err) + _, _ = fmt.Fprintf(GinkgoWriter, "warning: failed to get kubernetes version: %v\n", err) + k8sVersion = &KubernetesVersion{ + ClientVersion: VersionInfo{ + Major: "1", + Minor: "0", + GitVersion: "v1.0.0-fake", + }, + ServerVersion: VersionInfo{ + Major: "1", + Minor: "0", + GitVersion: "v1.0.0-fake", + }, + } + } else { + k8sVersion = &v } - // Set CmdContext.Dir after running Kubectl.Version() because dir does not exist yet. if cc.Dir, err = filepath.Abs("e2e-" + testSuffix); err != nil { return nil, fmt.Errorf("failed to determine absolute path to %q: %w", "e2e-"+testSuffix, err) @@ -93,7 +107,7 @@ func NewTestContext(binaryName string, env ...string) (*TestContext, error) { ImageName: "e2e-test/controller-manager:" + testSuffix, CmdContext: cc, Kubectl: kubectl, - K8sVersion: &k8sVersion, + K8sVersion: k8sVersion, BinaryName: binaryName, }, nil } diff --git a/test/features.sh b/test/features.sh new file mode 100755 index 00000000000..16117ca71e5 --- /dev/null +++ b/test/features.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +# Copyright 2018 The Kubernetes Authors. +# +# 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 -euo pipefail + +source "$(dirname "$0")/common.sh" + +header_text "Running e2e tests that do not require a cluster" + +build_kb +fetch_tools + +pushd . >/dev/null + +header_text "Running Grafana Plugin E2E tests" +go test "$(dirname "$0")/e2e/grafana" ${flags:-} -timeout 30m + +header_text "Running Alpha Generate Command E2E tests" +go test "$(dirname "$0")/e2e/alphagenerate" ${flags:-} -timeout 30m + +popd >/dev/null