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 c181e3e
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 186 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,6 @@ generate-e2e-templates-main: $(KUSTOMIZE)
$(KUSTOMIZE) build $(DOCKER_TEMPLATES)/main/cluster-template-topology --load-restrictor LoadRestrictionsNone > $(DOCKER_TEMPLATES)/main/cluster-template-topology.yaml
$(KUSTOMIZE) build $(DOCKER_TEMPLATES)/main/cluster-template-ignition --load-restrictor LoadRestrictionsNone > $(DOCKER_TEMPLATES)/main/cluster-template-ignition.yaml
$(KUSTOMIZE) build $(DOCKER_TEMPLATES)/main/clusterclass-quick-start-kcp-only --load-restrictor LoadRestrictionsNone > $(DOCKER_TEMPLATES)/main/clusterclass-quick-start-kcp-only.yaml
$(KUSTOMIZE) build $(DOCKER_TEMPLATES)/main/cluster-template-cross-ns-topology --load-restrictor LoadRestrictionsNone > $(DOCKER_TEMPLATES)/main/cluster-template-cross-ns-topology.yaml
$(KUSTOMIZE) build $(DOCKER_TEMPLATES)/main/cluster-template-cross-ns-upgrades-runtimesdk --load-restrictor LoadRestrictionsNone > $(DOCKER_TEMPLATES)/main/cluster-template-cross-ns-upgrades-runtimesdk.yaml
$(KUSTOMIZE) build $(INMEMORY_TEMPLATES)/main/cluster-template --load-restrictor LoadRestrictionsNone > $(INMEMORY_TEMPLATES)/main/cluster-template.yaml

.PHONY: generate-metrics-config
Expand Down
7 changes: 7 additions & 0 deletions cmd/clusterctl/cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ func printVariablesOutput(template client.Template, options client.GetClusterTem
} else if val, ok := os.LookupEnv("KUBERNETES_VERSION"); ok {
variableMap[name] = ptr.To(val)
}
case "CLUSTER_CLASS_NAMESPACE":
// Namespace name from the cmd flags or from the kubeconfig is used instead of template default.
if val, ok := os.LookupEnv("CLUSTER_CLASS_NAMESPACE"); ok {
variableMap[name] = ptr.To(val)
} else {
variableMap[name] = ptr.To("")
}
}

if variableMap[name] != nil {
Expand Down
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
2 changes: 0 additions & 2 deletions test/e2e/config/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,6 @@ providers:
- sourcePath: "../data/infrastructure-docker/main/cluster-template-topology-autoscaler.yaml"
- sourcePath: "../data/infrastructure-docker/main/cluster-template-topology.yaml"
- sourcePath: "../data/infrastructure-docker/main/cluster-template-ignition.yaml"
- sourcePath: "../data/infrastructure-docker/main/cluster-template-cross-ns-topology.yaml"
- sourcePath: "../data/infrastructure-docker/main/cluster-template-cross-ns-upgrades-runtimesdk.yaml"
- sourcePath: "../data/infrastructure-docker/main/clusterclass-quick-start.yaml"
- sourcePath: "../data/infrastructure-docker/main/clusterclass-quick-start-kcp-only.yaml"
- sourcePath: "../data/infrastructure-docker/main/clusterclass-quick-start-runtimesdk.yaml"
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

This file was deleted.

This file was deleted.

This file was deleted.

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-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 c181e3e

Please sign in to comment.