Skip to content

Cluster validation allows invalid worker topology names #12068

Open
@dlipovetsky

Description

@dlipovetsky

What steps did you take and what happened?

The worker topologies are found under Cluster.Spec.Topology.Workers.MachineDeployments and Cluster.Spec.Topology.Workers.MachinePools. Each of these has a Name field.

The the topology controller uses the value of the Name field to generate a MachineDeployment or MachinePool name, respectively, so the value must be a valid Kubernetes resource name, i.e. it must conform to https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names.

Today, the Name field validation checks only length and uniqueness.

If I assign a Name field a value (wrk_z_cli) with an underscore, making it invalid for a Kubernetes resource, I get no validation error. However, the topology controller returns an error when it fails to create a resource. The following controller log excerpt shows this:

I0403 06:16:38.220170       1 reconcile_state.go:66] "Reconciling state for topology owned objects" controller="topology/cluster" controllerGroup="cluster.x-k8s.io" controllerKind="Cluster" Cluster="default/mg-2132-rc1" namespace="default" name="mg-2132-rc1" reconcileID="b97648fc-122b-42df-a1ae-62f55946db6b"
I0403 06:16:38.340486       1 reconcile_state.go:579] "Creating NutanixMachineTemplate/mg-2132-rc1-wrk_z_cli-njvs7" controller="topology/cluster" controllerGroup="cluster.x-k8s.io" controllerKind="Cluster" Cluster="default/mg-2132-rc1" namespace="default" name="mg-2132-rc1" reconcileID="b97648fc-122b-42df-a1ae-62f55946db6b" MachineDeployment="default/mg-2132-rc1-wrk_z_cli-bftqj" machineDeploymentTopology="wrk_z_cli" resource={"group":"infrastructure.cluster.x-k8s.io","version":"v1beta1","resource":"NutanixMachineTemplate"} NutanixMachineTemplate="default/mg-2132-rc1-wrk_z_cli-njvs7"
E0403 06:16:38.344150       1 reconcile_state.go:1253] "Failed to create object" err="NutanixMachineTemplate.infrastructure.cluster.x-k8s.io \"mg-2132-rc1-wrk_z_cli-njvs7\" is invalid: metadata.name: Invalid value: \"mg-2132-rc1-wrk_z_cli-njvs7\": a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')" controller="topology/cluster" controllerGroup="cluster.x-k8s.io" controllerKind="Cluster" Cluster="default/mg-2132-rc1" namespace="default" name="mg-2132-rc1" reconcileID="b97648fc-122b-42df-a1ae-62f55946db6b" MachineDeployment="default/mg-2132-rc1-wrk_z_cli-bftqj" machineDeploymentTopology="wrk_z_cli" resource={"group":"infrastructure.cluster.x-k8s.io","version":"v1beta1","resource":"NutanixMachineTemplate"} NutanixMachineTemplate="default/mg-2132-rc1-wrk_z_cli-njvs7" NutanixMachineTemplate="default/mg-2132-rc1-wrk_z_cli-njvs7"

What did you expect to happen?

The Cluster validation should reject a worker topology name that would result in an invalid Kubernetes resource name.

Cluster API version

v1.9.4

Kubernetes version

v1.31.4

Anything else you would like to add?

No response

Label(s) to be applied

/kind bug
/area clusterclass

Metadata

Metadata

Assignees

Labels

area/clusterclassIssues or PRs related to clusterclasskind/bugCategorizes issue or PR as related to a bug.priority/important-soonMust be staffed and worked on either currently, or very soon, ideally in time for the next release.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions