Skip to content

Commit

Permalink
Merge pull request #9425 from chrischdi/pr-fix-cc-namingstrategy
Browse files Browse the repository at this point in the history
🐛 topology: fix namingstrategy webhook to not use uppercase characters for testing the template and align unit test to e2e test
  • Loading branch information
k8s-ci-robot committed Sep 14, 2023
2 parents 2b55cb8 + 0bde9c0 commit 8fbb3b4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions internal/webhooks/clusterclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func validateNamingStrategies(clusterClass *clusterv1.ClusterClass) field.ErrorL
if md.NamingStrategy == nil || md.NamingStrategy.Template == nil {
continue
}
name, err := names.MachineDeploymentNameGenerator(*md.NamingStrategy.Template, "cluster", "mdTopology").GenerateName()
name, err := names.MachineDeploymentNameGenerator(*md.NamingStrategy.Template, "cluster", "mdtopology").GenerateName()
templateFldPath := field.NewPath("spec", "workers", "machineDeployments").Index(i).Child("namingStrategy", "template")
if err != nil {
allErrs = append(allErrs,
Expand All @@ -459,7 +459,7 @@ func validateNamingStrategies(clusterClass *clusterv1.ClusterClass) field.ErrorL
if mp.NamingStrategy == nil || mp.NamingStrategy.Template == nil {
continue
}
name, err := names.MachinePoolNameGenerator(*mp.NamingStrategy.Template, "cluster", "mpTopology").GenerateName()
name, err := names.MachinePoolNameGenerator(*mp.NamingStrategy.Template, "cluster", "mptopology").GenerateName()
templateFldPath := field.NewPath("spec", "workers", "machinePools").Index(i).Child("namingStrategy", "template")
if err != nil {
allErrs = append(allErrs,
Expand Down
6 changes: 3 additions & 3 deletions internal/webhooks/clusterclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ func TestClusterClassValidation(t *testing.T) {
WithControlPlaneTemplate(
builder.ControlPlaneTemplate(metav1.NamespaceDefault, "cp1").
Build()).
WithControlPlaneNamingStrategy(&clusterv1.ControlPlaneClassNamingStrategy{Template: pointer.String("template-cp-{{ .cluster.name }}")}).
WithControlPlaneNamingStrategy(&clusterv1.ControlPlaneClassNamingStrategy{Template: pointer.String("{{ .cluster.name }}-cp-{{ .random }}")}).
WithControlPlaneInfrastructureMachineTemplate(
builder.InfrastructureMachineTemplate(metav1.NamespaceDefault, "cpInfra1").
Build()).
Expand All @@ -1183,15 +1183,15 @@ func TestClusterClassValidation(t *testing.T) {
builder.InfrastructureMachineTemplate(metav1.NamespaceDefault, "infra1").Build()).
WithBootstrapTemplate(
builder.BootstrapTemplate(metav1.NamespaceDefault, "bootstrap1").Build()).
WithNamingStrategy(&clusterv1.MachineDeploymentClassNamingStrategy{Template: pointer.String("template-md-{{ .cluster.name }}")}).
WithNamingStrategy(&clusterv1.MachineDeploymentClassNamingStrategy{Template: pointer.String("{{ .cluster.name }}-md-{{ .machineDeployment.topologyName }}-{{ .random }}")}).
Build()).
WithWorkerMachinePoolClasses(
*builder.MachinePoolClass("bb").
WithInfrastructureTemplate(
builder.InfrastructureMachinePoolTemplate(metav1.NamespaceDefault, "infra2").Build()).
WithBootstrapTemplate(
builder.BootstrapTemplate(metav1.NamespaceDefault, "bootstrap2").Build()).
WithNamingStrategy(&clusterv1.MachinePoolClassNamingStrategy{Template: pointer.String("template-mp-{{ .cluster.name }}")}).
WithNamingStrategy(&clusterv1.MachinePoolClassNamingStrategy{Template: pointer.String("{{ .cluster.name }}-md-{{ .machinePool.topologyName }}-{{ .random }}")}).
Build()).
Build(),
expectErr: false,
Expand Down

0 comments on commit 8fbb3b4

Please sign in to comment.