diff --git a/pkg/webhook/addons/registry/autoenabler.go b/pkg/webhook/addons/registry/autoenabler.go index 199b42eb1..36ee1b767 100644 --- a/pkg/webhook/addons/registry/autoenabler.go +++ b/pkg/webhook/addons/registry/autoenabler.go @@ -95,6 +95,10 @@ func (a *workloadClusterAutoEnabler) defaulter( if managementCluster == nil { return admission.Allowed("") } + // Check if the management cluster is a ClusterClass based cluster, just return if it is not. + if managementCluster.Spec.Topology == nil { + return admission.Allowed("") + } // Check if the addon is enabled in the management cluster, if not just return. managementClusterRegistry, err := variables.RegistryAddon(managementCluster) if err != nil { diff --git a/pkg/webhook/addons/registry/webhook_test.go b/pkg/webhook/addons/registry/webhook_test.go index 61f47d05d..6b671cd44 100644 --- a/pkg/webhook/addons/registry/webhook_test.go +++ b/pkg/webhook/addons/registry/webhook_test.go @@ -265,6 +265,44 @@ func TestDefaultingShouldBeSkippedForAManagementCluster(t *testing.T) { g.Expect(clusterConfig.Addons.Registry).To(BeNil()) } +func TestDefaultingShouldBeSkippedWhenManagementClusterHasNoTopology(t *testing.T) { + g := NewWithT(t) + + // Create a non-ClusterClass management cluster. + managementCluster := &clusterv1.Cluster{ + ObjectMeta: metav1.ObjectMeta{ + GenerateName: "test-mgmt-cluster-", + Namespace: metav1.NamespaceDefault, + }, + Spec: clusterv1.ClusterSpec{ + // No Topology field - simulates a non-ClusterClass management cluster + }, + } + g.Expect(env.Client.Create(ctx, managementCluster)).To(Succeed()) + t.Cleanup(func() { + g.Expect(env.Client.Delete(ctx, managementCluster)).To(Succeed()) + }) + + // Create a workload cluster with topology. + workloadCluster := createTestCluster( + t, + nil, + &carenv1.DockerClusterConfigSpec{ + Addons: &carenv1.DockerAddons{ + GenericAddons: carenv1.GenericAddons{ + CNI: &carenv1.CNI{}, + }, + }, + }, + ) + + // Validate that the registry addon is not automatically enabled because + // the management cluster has no topology (non-ClusterClass). + clusterConfig, err := variables.UnmarshalClusterConfigVariable(workloadCluster.Spec.Topology.Variables) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(clusterConfig.Addons.Registry).To(BeNil()) +} + func createTestManagementCluster( t *testing.T, clusterConfigSpec *carenv1.DockerClusterConfigSpec,