diff --git a/test/e2e/autoscaler.go b/test/e2e/autoscaler.go index cf7a59b34286..349373f264d6 100644 --- a/test/e2e/autoscaler.go +++ b/test/e2e/autoscaler.go @@ -61,6 +61,10 @@ type AutoscalerSpecInput struct { // Example: dockermachinetemplates. InfrastructureMachineTemplateKind string AutoscalerVersion string + + // Allows to inject a function to be run after test namespace is created. + // If not specified, this is a no-op. + PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) } // AutoscalerSpec implements a test for the autoscaler, and more specifically for the autoscaler @@ -88,7 +92,7 @@ func AutoscalerSpec(ctx context.Context, inputGetter func() AutoscalerSpecInput) Expect(input.E2EConfig.Variables).To(HaveKey(KubernetesVersion)) // Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. - namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) + namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated) clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult) }) diff --git a/test/e2e/cluster_upgrade.go b/test/e2e/cluster_upgrade.go index 81ee41180a8b..f5d67e62637f 100644 --- a/test/e2e/cluster_upgrade.go +++ b/test/e2e/cluster_upgrade.go @@ -62,6 +62,10 @@ type ClusterUpgradeConformanceSpecInput struct { // Flavor to use when creating the cluster for testing, "upgrades" is used if not specified. Flavor *string + + // Allows to inject a function to be run after test namespace is created. + // If not specified, this is a no-op. + PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) } // ClusterUpgradeConformanceSpec implements a spec that upgrades a cluster and runs the Kubernetes conformance suite. @@ -126,7 +130,7 @@ func ClusterUpgradeConformanceSpec(ctx context.Context, inputGetter func() Clust } // Setup a Namespace where to host objects for this spec and create a watcher for the Namespace events. - namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) + namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated) clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult) }) diff --git a/test/e2e/cluster_upgrade_runtimesdk.go b/test/e2e/cluster_upgrade_runtimesdk.go index 5d32e5d8af37..209361bbbec4 100644 --- a/test/e2e/cluster_upgrade_runtimesdk.go +++ b/test/e2e/cluster_upgrade_runtimesdk.go @@ -81,6 +81,10 @@ type clusterUpgradeWithRuntimeSDKSpecInput struct { // Flavor to use when creating the cluster for testing, "upgrades" is used if not specified. Flavor *string + + // Allows to inject a function to be run after test namespace is created. + // If not specified, this is a no-op. + PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) } // clusterUpgradeWithRuntimeSDKSpec implements a spec that upgrades a cluster and runs the Kubernetes conformance suite. @@ -130,7 +134,7 @@ func clusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() cl } // Set up a Namespace where to host objects for this spec and create a watcher for the Namespace events. - namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) + namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated) clusterName = fmt.Sprintf("%s-%s", specName, util.RandomString(6)) clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult) }) diff --git a/test/e2e/clusterclass_changes.go b/test/e2e/clusterclass_changes.go index 564ff083753e..45d4700dd3d5 100644 --- a/test/e2e/clusterclass_changes.go +++ b/test/e2e/clusterclass_changes.go @@ -106,6 +106,10 @@ type ClusterClassChangesSpecInput struct { // "spec.template.spec.path.to.field": , // } ModifyMachinePoolInfrastructureMachinePoolTemplateFields map[string]interface{} + + // Allows to inject a function to be run after test namespace is created. + // If not specified, this is a no-op. + PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) } // ClusterClassChangesSpec implements a test that verifies that ClusterClass changes are rolled out successfully. @@ -150,7 +154,7 @@ func ClusterClassChangesSpec(ctx context.Context, inputGetter func() ClusterClas Expect(input.ModifyControlPlaneFields).ToNot(BeEmpty(), "Invalid argument. input.ModifyControlPlaneFields can't be empty when calling %s spec", specName) // Set up a Namespace where to host objects for this spec and create a watcher for the namespace events. - namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) + namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated) clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult) }) diff --git a/test/e2e/clusterclass_rollout.go b/test/e2e/clusterclass_rollout.go index 6e1149949057..6d6a37289498 100644 --- a/test/e2e/clusterclass_rollout.go +++ b/test/e2e/clusterclass_rollout.go @@ -71,6 +71,10 @@ type ClusterClassRolloutSpecInput struct { // NOTE: The template must be using ClusterClass, KCP and CABPK as this test is specifically // testing ClusterClass and KCP rollout behavior. Flavor string + + // Allows to inject a function to be run after test namespace is created. + // If not specified, this is a no-op. + PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) } // ClusterClassRolloutSpec implements a test that verifies the ClusterClass rollout behavior. @@ -108,7 +112,7 @@ func ClusterClassRolloutSpec(ctx context.Context, inputGetter func() ClusterClas Expect(input.E2EConfig.Variables).To(HaveValidVersion(input.E2EConfig.GetVariable(KubernetesVersion))) // Set up a Namespace where to host objects for this spec and create a watcher for the namespace events. - namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) + namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated) clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult) }) diff --git a/test/e2e/clusterctl_upgrade.go b/test/e2e/clusterctl_upgrade.go index fbae892be0c3..b563b9ebb6d4 100644 --- a/test/e2e/clusterctl_upgrade.go +++ b/test/e2e/clusterctl_upgrade.go @@ -100,6 +100,9 @@ type ClusterctlUpgradeSpecInput struct { // multiple infrastructure providers (ex: CAPD + in-memory) are installed on the cluster as clusterctl will not be // able to identify the default. InfrastructureProvider *string + // Allows to inject a function to be run after test namespace is created. + // If not specified, this is a no-op. + PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) // PreWaitForCluster is a function that can be used as a hook to apply extra resources (that cannot be part of the template) in the generated namespace hosting the cluster // This function is called after applying the cluster template and before waiting for the cluster resources. PreWaitForCluster func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string, workloadClusterName string) @@ -214,7 +217,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg Expect(os.MkdirAll(input.ArtifactFolder, 0750)).To(Succeed(), "Invalid argument. input.ArtifactFolder can't be created for %s spec", specName) // Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. - managementClusterNamespace, managementClusterCancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) + managementClusterNamespace, managementClusterCancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated) managementClusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult) }) @@ -346,6 +349,11 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg LogFolder: filepath.Join(input.ArtifactFolder, "clusters", "bootstrap"), }) + if input.PostNamespaceCreated != nil { + log.Logf("Calling postNamespaceCreated for namespace %s", testNamespace.Name) + input.PostNamespaceCreated(managementClusterProxy, testNamespace.Name) + } + By("Creating a test workload cluster") // NOTE: This workload cluster is used to check the old management cluster works fine. diff --git a/test/e2e/common.go b/test/e2e/common.go index 2904700a1f79..0fa27c475197 100644 --- a/test/e2e/common.go +++ b/test/e2e/common.go @@ -30,6 +30,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" + "sigs.k8s.io/cluster-api/test/e2e/internal/log" "sigs.k8s.io/cluster-api/test/framework" "sigs.k8s.io/cluster-api/test/framework/clusterctl" "sigs.k8s.io/cluster-api/util" @@ -56,7 +57,7 @@ func Byf(format string, a ...interface{}) { By(fmt.Sprintf(format, a...)) } -func setupSpecNamespace(ctx context.Context, specName string, clusterProxy framework.ClusterProxy, artifactFolder string) (*corev1.Namespace, context.CancelFunc) { +func setupSpecNamespace(ctx context.Context, specName string, clusterProxy framework.ClusterProxy, artifactFolder string, postNamespaceCreated func(framework.ClusterProxy, string)) (*corev1.Namespace, context.CancelFunc) { Byf("Creating a namespace for hosting the %q test spec", specName) namespace, cancelWatches := framework.CreateNamespaceAndWatchEvents(ctx, framework.CreateNamespaceAndWatchEventsInput{ Creator: clusterProxy.GetClient(), @@ -65,6 +66,11 @@ func setupSpecNamespace(ctx context.Context, specName string, clusterProxy frame LogFolder: filepath.Join(artifactFolder, "clusters", clusterProxy.GetName()), }) + if postNamespaceCreated != nil { + log.Logf("Calling postNamespaceCreated for namespace %s", namespace.Name) + postNamespaceCreated(clusterProxy, namespace.Name) + } + return namespace, cancelWatches } diff --git a/test/e2e/k8s_conformance.go b/test/e2e/k8s_conformance.go index 689c972476e4..86c2422cce07 100644 --- a/test/e2e/k8s_conformance.go +++ b/test/e2e/k8s_conformance.go @@ -51,6 +51,10 @@ type K8SConformanceSpecInput struct { Flavor string ControlPlaneWaiters clusterctl.ControlPlaneWaiters + + // Allows to inject a function to be run after test namespace is created. + // If not specified, this is a no-op. + PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) } // K8SConformanceSpec implements a spec that creates a cluster and runs Kubernetes conformance suite. @@ -83,7 +87,7 @@ func K8SConformanceSpec(ctx context.Context, inputGetter func() K8SConformanceSp Expect(kubetestConfigFilePath).To(BeAnExistingFile(), "%s should be a valid kubetest config file") // Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. - namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) + namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated) clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult) }) diff --git a/test/e2e/kcp_adoption.go b/test/e2e/kcp_adoption.go index e6d7b6eeb11c..6ed2bbee756f 100644 --- a/test/e2e/kcp_adoption.go +++ b/test/e2e/kcp_adoption.go @@ -66,6 +66,10 @@ type KCPAdoptionSpecInput struct { // resources must have the kcp-adoption.step2: "" applied to them. // If not specified, "kcp-adoption" is used. Flavor *string + + // Allows to inject a function to be run after test namespace is created. + // If not specified, this is a no-op. + PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) } type ClusterProxy interface { @@ -98,7 +102,7 @@ func KCPAdoptionSpec(ctx context.Context, inputGetter func() KCPAdoptionSpecInpu Expect(input.E2EConfig.Variables).To(HaveKey(KubernetesVersion)) // Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. - namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) + namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated) }) It("Should adopt up-to-date control plane Machines without modification", func() { diff --git a/test/e2e/kcp_remediations.go b/test/e2e/kcp_remediations.go index 4dd28ff700db..bce6470697d1 100644 --- a/test/e2e/kcp_remediations.go +++ b/test/e2e/kcp_remediations.go @@ -81,6 +81,10 @@ type KCPRemediationSpecInput struct { // timeout: 10s // If not specified, "kcp-remediation" is used. Flavor *string + + // Allows to inject a function to be run after test namespace is created. + // If not specified, this is a no-op. + PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) } // KCPRemediationSpec implements a test that verifies that Machines are remediated by MHC during unhealthy conditions. @@ -103,7 +107,7 @@ func KCPRemediationSpec(ctx context.Context, inputGetter func() KCPRemediationSp Expect(input.E2EConfig.Variables).To(HaveKey(KubernetesVersion)) // Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. - namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) + namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated) }) It("Should replace unhealthy machines", func() { diff --git a/test/e2e/machine_pool.go b/test/e2e/machine_pool.go index f8f8e4bfee3c..56b90c9260db 100644 --- a/test/e2e/machine_pool.go +++ b/test/e2e/machine_pool.go @@ -54,6 +54,10 @@ type MachinePoolInput struct { // Flavor, if specified must refer to a template that contains a MachinePool resource. // If not specified, "machine-pool" is used Flavor *string + + // Allows to inject a function to be run after test namespace is created. + // If not specified, this is a no-op. + PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) } // MachinePoolSpec implements a test that verifies MachinePool create, scale up and scale down. @@ -77,7 +81,7 @@ func MachinePoolSpec(ctx context.Context, inputGetter func() MachinePoolInput) { Expect(input.E2EConfig.Variables).To(HaveValidVersion(input.E2EConfig.GetVariable(KubernetesVersion))) // Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. - namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) + namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated) clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult) }) diff --git a/test/e2e/md_remediations.go b/test/e2e/md_remediations.go index 65d27e6f2f8a..11d44ed190a4 100644 --- a/test/e2e/md_remediations.go +++ b/test/e2e/md_remediations.go @@ -54,6 +54,10 @@ type MachineDeploymentRemediationSpecInput struct { // condition with a short timeout. // If not specified, "md-remediation" is used. Flavor *string + + // Allows to inject a function to be run after test namespace is created. + // If not specified, this is a no-op. + PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) } // MachineDeploymentRemediationSpec implements a test that verifies that Machines are remediated by MHC during unhealthy conditions. @@ -76,7 +80,7 @@ func MachineDeploymentRemediationSpec(ctx context.Context, inputGetter func() Ma Expect(input.E2EConfig.Variables).To(HaveKey(KubernetesVersion)) // Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. - namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) + namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated) clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult) }) diff --git a/test/e2e/md_rollout.go b/test/e2e/md_rollout.go index eefc15eed203..b0f1ec383cc3 100644 --- a/test/e2e/md_rollout.go +++ b/test/e2e/md_rollout.go @@ -48,6 +48,10 @@ type MachineDeploymentRolloutSpecInput struct { // multiple infrastructure providers (ex: CAPD + in-memory) are installed on the cluster as clusterctl will not be // able to identify the default. InfrastructureProvider *string + + // Allows to inject a function to be run after test namespace is created. + // If not specified, this is a no-op. + PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) } // MachineDeploymentRolloutSpec implements a test that verifies that MachineDeployment rolling updates are successful. @@ -71,7 +75,7 @@ func MachineDeploymentRolloutSpec(ctx context.Context, inputGetter func() Machin Expect(input.E2EConfig.Variables).To(HaveValidVersion(input.E2EConfig.GetVariable(KubernetesVersion))) // Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. - namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) + namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated) clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult) }) diff --git a/test/e2e/md_scale.go b/test/e2e/md_scale.go index ee8feac02e86..994d2a500f7b 100644 --- a/test/e2e/md_scale.go +++ b/test/e2e/md_scale.go @@ -48,6 +48,10 @@ type MachineDeploymentScaleSpecInput struct { // multiple infrastructure providers (ex: CAPD + in-memory) are installed on the cluster as clusterctl will not be // able to identify the default. InfrastructureProvider *string + + // Allows to inject a function to be run after test namespace is created. + // If not specified, this is a no-op. + PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) } // MachineDeploymentScaleSpec implements a test that verifies that MachineDeployment scale operations are successful. @@ -71,7 +75,7 @@ func MachineDeploymentScaleSpec(ctx context.Context, inputGetter func() MachineD Expect(input.E2EConfig.Variables).To(HaveValidVersion(input.E2EConfig.GetVariable(KubernetesVersion))) // Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. - namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) + namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated) clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult) }) diff --git a/test/e2e/node_drain_timeout.go b/test/e2e/node_drain_timeout.go index 56a0ac06f6fa..0b4e0a36c646 100644 --- a/test/e2e/node_drain_timeout.go +++ b/test/e2e/node_drain_timeout.go @@ -58,6 +58,10 @@ type NodeDrainTimeoutSpecInput struct { // spec.template.spec.nodeDrainTimeout configured. // If not specified, "node-drain" is used. Flavor *string + + // Allows to inject a function to be run after test namespace is created. + // If not specified, this is a no-op. + PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) } func NodeDrainTimeoutSpec(ctx context.Context, inputGetter func() NodeDrainTimeoutSpecInput) { @@ -83,7 +87,7 @@ func NodeDrainTimeoutSpec(ctx context.Context, inputGetter func() NodeDrainTimeo Expect(input.E2EConfig.GetIntervals(specName, "wait-machine-deleted")).ToNot(BeNil()) // Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. - namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) + namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated) clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult) }) diff --git a/test/e2e/quick_start.go b/test/e2e/quick_start.go index 940b64413c1e..cb9fabf84d10 100644 --- a/test/e2e/quick_start.go +++ b/test/e2e/quick_start.go @@ -62,6 +62,10 @@ type QuickStartSpecInput struct { // which unblocks CNI installation, and for the control plane machines to be ready (after CNI installation). ControlPlaneWaiters clusterctl.ControlPlaneWaiters + // Allows to inject a function to be run after test namespace is created. + // If not specified, this is a no-op. + PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) + // Allows to inject a function to be run after machines are provisioned. // If not specified, this is a no-op. PostMachinesProvisioned func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace, workloadClusterName string) @@ -91,7 +95,7 @@ func QuickStartSpec(ctx context.Context, inputGetter func() QuickStartSpecInput) Expect(input.E2EConfig.Variables).To(HaveKey(KubernetesVersion)) // Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. - namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) + namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated) clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult) }) diff --git a/test/e2e/scale.go b/test/e2e/scale.go index c6d400e4c723..dbac69dc0155 100644 --- a/test/e2e/scale.go +++ b/test/e2e/scale.go @@ -115,6 +115,10 @@ type scaleSpecInput struct { // be MachineDeploymentCount*WorkerMachineCount (CAPI_SCALE_MACHINE_DEPLOYMENT_COUNT*CAPI_SCALE_WORKER_MACHINE_COUNT). MachineDeploymentCount *int64 + // Allows to inject a function to be run after test namespace is created. + // If not specified, this is a no-op. + PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) + // FailFast if set to true will return immediately after the first cluster operation fails. // If set to false, the test suite will not exit immediately after the first cluster operation fails. // Example: When creating clusters from c1 to c20 consider c6 fails creation. If FailFast is set to true @@ -168,6 +172,11 @@ func scaleSpec(ctx context.Context, inputGetter func() scaleSpecInput) { LogFolder: filepath.Join(input.ArtifactFolder, "clusters", input.BootstrapClusterProxy.GetName()), IgnoreAlreadyExists: true, }) + + if input.PostNamespaceCreated != nil { + log.Logf("Calling postNamespaceCreated for namespace %s", namespace.Name) + input.PostNamespaceCreated(input.BootstrapClusterProxy, namespace.Name) + } }) It("Should create and delete workload clusters", func() { diff --git a/test/e2e/self_hosted.go b/test/e2e/self_hosted.go index 5c8361642582..7f0455842085 100644 --- a/test/e2e/self_hosted.go +++ b/test/e2e/self_hosted.go @@ -74,6 +74,10 @@ type SelfHostedSpecInput struct { // worker machines is a multiple of WorkerMachineCount. // Default is 1. WorkerMachineCount *int64 + + // Allows to inject a function to be run after test namespace is created. + // If not specified, this is a no-op. + PostNamespaceCreated func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) } // SelfHostedSpec implements a test that verifies Cluster API creating a cluster, pivoting to a self-hosted cluster. @@ -128,7 +132,7 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput) } // Setup a Namespace where to host objects for this spec and create a watcher for the namespace events. - namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) + namespace, cancelWatches = setupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated) clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult) if input.ControlPlaneMachineCount == nil { @@ -205,6 +209,11 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput) LogFolder: filepath.Join(input.ArtifactFolder, "clusters", "bootstrap"), }) + if input.PostNamespaceCreated != nil { + log.Logf("Calling postNamespaceCreated for namespace %s", selfHostedNamespace.Name) + input.PostNamespaceCreated(selfHostedClusterProxy, selfHostedNamespace.Name) + } + By("Initializing the workload cluster") // watchesCtx is used in log streaming to be able to get canceld via cancelWatches after ending the test suite. watchesCtx, cancelWatches := context.WithCancel(ctx)