Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/webhook/addons/registry/autoenabler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
38 changes: 38 additions & 0 deletions pkg/webhook/addons/registry/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading