From 55e31cc507467668ec0cb46ec59ef467891dc97f Mon Sep 17 00:00:00 2001 From: Christian Schlotter Date: Thu, 11 Apr 2024 19:21:58 +0200 Subject: [PATCH] test: fix kubetest to allow parallel execution on different clusters --- test/e2e/cluster_upgrade.go | 1 + test/e2e/k8s_conformance.go | 1 + test/e2e/quick_start_test.go | 2 ++ test/framework/kubetest/run.go | 13 +++++++++++-- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/test/e2e/cluster_upgrade.go b/test/e2e/cluster_upgrade.go index cda2bfe0c0d1..cb53fb6c84ae 100644 --- a/test/e2e/cluster_upgrade.go +++ b/test/e2e/cluster_upgrade.go @@ -252,6 +252,7 @@ func ClusterUpgradeConformanceSpec(ctx context.Context, inputGetter func() Clust ArtifactsDirectory: input.ArtifactFolder, ConfigFilePath: kubetestConfigFilePath, GinkgoNodes: int(clusterResources.ExpectedWorkerNodes()), + ClusterName: clusterResources.Cluster.GetName(), }, ) Expect(err).ToNot(HaveOccurred(), "Failed to run Kubernetes conformance") diff --git a/test/e2e/k8s_conformance.go b/test/e2e/k8s_conformance.go index e376403b5cb4..7c820d3bbe18 100644 --- a/test/e2e/k8s_conformance.go +++ b/test/e2e/k8s_conformance.go @@ -144,6 +144,7 @@ func K8SConformanceSpec(ctx context.Context, inputGetter func() K8SConformanceSp ArtifactsDirectory: input.ArtifactFolder, ConfigFilePath: kubetestConfigFilePath, GinkgoNodes: ginkgoNodes, + ClusterName: clusterResources.Cluster.GetName(), }, ) Expect(err).ToNot(HaveOccurred(), "Failed to run Kubernetes conformance") diff --git a/test/e2e/quick_start_test.go b/test/e2e/quick_start_test.go index 335b6a0c9a3d..af41a216eee9 100644 --- a/test/e2e/quick_start_test.go +++ b/test/e2e/quick_start_test.go @@ -143,6 +143,7 @@ var _ = Describe("When following the Cluster API quick-start with dualstack and ClusterProxy: proxy.GetWorkloadCluster(ctx, namespace, clusterName), ArtifactsDirectory: artifactFolder, ConfigFilePath: "./data/kubetest/dualstack.yaml", + ClusterName: clusterName, }, )).To(Succeed()) }, @@ -169,6 +170,7 @@ var _ = Describe("When following the Cluster API quick-start with dualstack and ClusterProxy: proxy.GetWorkloadCluster(ctx, namespace, clusterName), ArtifactsDirectory: artifactFolder, ConfigFilePath: "./data/kubetest/dualstack.yaml", + ClusterName: clusterName, }, )).To(Succeed()) }, diff --git a/test/framework/kubetest/run.go b/test/framework/kubetest/run.go index afed7a6878cd..eb1c39e8d326 100644 --- a/test/framework/kubetest/run.go +++ b/test/framework/kubetest/run.go @@ -30,6 +30,7 @@ import ( "github.com/onsi/ginkgo/v2" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/rand" "k8s.io/client-go/discovery" "k8s.io/client-go/tools/clientcmd" "sigs.k8s.io/yaml" @@ -72,6 +73,8 @@ type RunInput struct { // KubeTestRepoListPath is optional file for specifying custom image repositories // https://github.com/kubernetes/kubernetes/blob/master/test/images/README.md#testing-the-new-image KubeTestRepoListPath string + // ClusterName is the name of the cluster to run the test at + ClusterName string } // Run executes kube-test given an artifact directory, and sets settings @@ -81,6 +84,12 @@ func Run(ctx context.Context, input RunInput) error { if input.ClusterProxy == nil { return errors.New("ClusterProxy must be provided") } + // If input.ClusterName is not set use a random string to allow parallel execution + // of kubetest on different clusters. + if input.ClusterName == "" { + input.ClusterName = rand.String(10) + } + if input.GinkgoNodes == 0 { input.GinkgoNodes = DefaultGinkgoNodes } @@ -102,7 +111,7 @@ func Run(ctx context.Context, input RunInput) error { input.KubernetesVersion = discoveredVersion } input.ArtifactsDirectory = framework.ResolveArtifactsDirectory(input.ArtifactsDirectory) - reportDir := path.Join(input.ArtifactsDirectory, "kubetest") + reportDir := path.Join(input.ArtifactsDirectory, "kubetest", input.ClusterName) outputDir := path.Join(reportDir, "e2e-output") kubetestConfigDir := path.Join(reportDir, "config") if err := os.MkdirAll(outputDir, 0o750); err != nil { @@ -132,7 +141,7 @@ func Run(ctx context.Context, input RunInput) error { "report-dir": "/output", "e2e-output-dir": "/output/e2e-output", "dump-logs-on-failure": "false", - "report-prefix": "kubetest.", + "report-prefix": fmt.Sprintf("kubetest.%s.", input.ClusterName), "num-nodes": strconv.FormatInt(int64(input.NumberOfNodes), 10), } ginkgoArgs := buildArgs(ginkgoVars, "-")