Skip to content

Commit

Permalink
Refactor to use empty CC namespace
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <[email protected]>
  • Loading branch information
Danil-Grigorev committed Dec 4, 2024
1 parent 865ffd1 commit 2d4a64e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 156 deletions.
2 changes: 1 addition & 1 deletion test/e2e/cluster_upgrade_runtimesdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ var _ = Describe("When upgrading a workload cluster using ClusterClass in a diff
framework.ValidateResourceVersionStable(ctx, proxy, namespace, clusterctlcluster.FilterClusterObjectsWithNameFilter(clusterName))
},
// "upgrades" is the same as the "topology" flavor but with an additional MachinePool.
Flavor: ptr.To("cross-ns-upgrades-runtimesdk"),
Flavor: ptr.To("upgrades-runtimesdk"),
ClassNamespace: true,
// The runtime extension gets deployed to the test-extension-system namespace and is exposed
// by the test-extension-webhook-service.
Expand Down
138 changes: 0 additions & 138 deletions test/e2e/cross-ns-quick-start.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spec:
serviceDomain: '${DOCKER_SERVICE_DOMAIN}'
topology:
class: "quick-start"
classNamespace: '${CLUSTER_CLASS_NAMESPACE}'
version: "${KUBERNETES_VERSION}"
controlPlane:
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ spec:
serviceDomain: '${DOCKER_SERVICE_DOMAIN}'
topology:
class: "quick-start-runtimesdk"
classNamespace: '${CLUSTER_CLASS_NAMESPACE}'
version: "${KUBERNETES_VERSION}"
controlPlane:
metadata: {}
Expand Down
35 changes: 30 additions & 5 deletions test/e2e/quick_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type QuickStartSpecInput struct {
// If not set, a random one will be generated.
ClusterName *string

// ClassNamespace is an optional class namespace reference, configuring cross-namespace cluster class reference
ClassNamespace *string

// InfrastructureProvider allows to specify the infrastructure provider to be used when looking for
// cluster templates.
// If not set, clusterctl will look at the infrastructure provider installed in the management cluster;
Expand Down Expand Up @@ -81,11 +84,12 @@ type QuickStartSpecInput struct {
// NOTE: This test works with Clusters with and without ClusterClass.
func QuickStartSpec(ctx context.Context, inputGetter func() QuickStartSpecInput) {
var (
specName = "quick-start"
input QuickStartSpecInput
namespace *corev1.Namespace
cancelWatches context.CancelFunc
clusterResources *clusterctl.ApplyClusterTemplateAndWaitResult
specName = "quick-start"
input QuickStartSpecInput
namespace *corev1.Namespace
clusterClassNamespace *corev1.Namespace
cancelWatches context.CancelFunc
clusterResources *clusterctl.ApplyClusterTemplateAndWaitResult
)

BeforeEach(func() {
Expand All @@ -100,6 +104,12 @@ func QuickStartSpec(ctx context.Context, inputGetter func() QuickStartSpecInput)

// Setup a Namespace where to host objects for this spec and create a watcher for the namespace events.
namespace, cancelWatches = framework.SetupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, input.PostNamespaceCreated)

if input.ClassNamespace != nil {
clusterClassNamespace = framework.CreateNamespace(ctx, framework.CreateNamespaceInput{Creator: input.BootstrapClusterProxy.GetClient(), Name: *input.ClassNamespace}, "40s", "10s")
Expect(clusterClassNamespace).ToNot(BeNil(), "Failed to create namespace %q", *input.ClassNamespace)
}

clusterResources = new(clusterctl.ApplyClusterTemplateAndWaitResult)
})

Expand Down Expand Up @@ -130,11 +140,19 @@ func QuickStartSpec(ctx context.Context, inputGetter func() QuickStartSpecInput)
if input.ClusterName != nil {
clusterName = *input.ClusterName
}

variables := map[string]string{}
if input.ClassNamespace != nil {
variables["CLUSTER_CLASS_NAMESPACE"] = *input.ClassNamespace
}

By("Creating a cluster referencing a clusterClass from another namespace")
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
ClusterProxy: input.BootstrapClusterProxy,
ConfigCluster: clusterctl.ConfigClusterInput{
LogFolder: filepath.Join(input.ArtifactFolder, "clusters", input.BootstrapClusterProxy.GetName()),
ClusterctlConfigPath: input.ClusterctlConfigPath,
ClusterctlVariables: variables,
KubeconfigPath: input.BootstrapClusterProxy.GetKubeconfigPath(),
InfrastructureProvider: infrastructureProvider,
Flavor: flavor,
Expand All @@ -154,11 +172,18 @@ func QuickStartSpec(ctx context.Context, inputGetter func() QuickStartSpecInput)
}
},
}, clusterResources)

By("PASSED!")
})

AfterEach(func() {
// Dumps all the resources in the spec namespace, then cleanups the cluster object and the spec namespace itself.
framework.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder, namespace, cancelWatches, clusterResources.Cluster, input.E2EConfig.GetIntervals, input.SkipCleanup)
if input.ClassNamespace != nil {
framework.DeleteNamespace(ctx, framework.DeleteNamespaceInput{
Deleter: input.BootstrapClusterProxy.GetClient(),
Name: clusterClassNamespace.Name,
})
}
})
}
24 changes: 13 additions & 11 deletions test/e2e/quick_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ limitations under the License.
package e2e

import (
"fmt"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/utils/ptr"

clusterctlcluster "sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/test/framework/kubetest"
"sigs.k8s.io/cluster-api/util"
)

var _ = Describe("When following the Cluster API quick-start", func() {
Expand Down Expand Up @@ -125,17 +128,16 @@ var _ = Describe("When following the Cluster API quick-start with ClusterClass [
})

var _ = Describe("When following the Cluster API quick-start with a cross-ns referenced ClusterClass [PR-Blocking] [ClusterClass]", func() {
CrossNsSpecQuickstart(ctx, func() CrossNsSpecInput {
return CrossNsSpecInput{
QuickStartSpecInput: QuickStartSpecInput{
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
BootstrapClusterProxy: bootstrapClusterProxy,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
Flavor: ptr.To("cross-ns-topology"),
InfrastructureProvider: ptr.To("docker"),
},
QuickStartSpec(ctx, func() QuickStartSpecInput {
return QuickStartSpecInput{
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
BootstrapClusterProxy: bootstrapClusterProxy,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
Flavor: ptr.To("topology"),
InfrastructureProvider: ptr.To("docker"),
ClassNamespace: ptr.To(fmt.Sprintf("quick-start-%s", util.RandomString(6))),
}
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/framework/clusterctl/clusterctl_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ func ApplyCustomClusterTemplateAndWait(ctx context.Context, input ApplyCustomClu
if result.Cluster.Spec.Topology != nil {
result.ClusterClass = framework.GetClusterClassByName(ctx, framework.GetClusterClassByNameInput{
Getter: input.ClusterProxy.GetClient(),
Namespace: result.Cluster.GetInfrastructureNamespace(),
Namespace: result.Cluster.GetClassKey().Namespace,
Name: result.Cluster.Spec.Topology.Class,
})
}
Expand Down

0 comments on commit 2d4a64e

Please sign in to comment.