kubernetes-sigs/cluster-api
View on GitHubMachineSet with wrong MachineSetNameLabel value in .spec.selector spawns infinite Machines
Open
#12,156 opened on May 7, 2025
area/machinearea/machinesethelp wantedkind/bugpriority/important-longtermtriage/accepted
Repository metrics
- Stars
- (4,267 stars)
- PR merge metrics
- (PR metrics pending)
Description
What steps did you take and what happened?
Scaling up a CAPI MachineSet with a .spec.selector.matchLabels that has a k/v clusterv1.MachineSetNameLabel (cluster.x-k8s.io/set-name) with value that doesn't match the .metadata.name of the MachineSet, causes a infinite-loop of child Machines being created.
Reproducing steps:
- a CAPI MachineSet is created with matching
.spec.selector.matchLabelsand.spec.template.metadata.labels'scluster.x-k8s.io/set-namebut with its.metadata.namediffering from them - the CAPI MachineSet is scaled up to 1 replica by the user
- the CAPI MachineSet controller goes to create a machine, it sets the
.metadata.labelsvalue for the keyclusterv1.MachineSetNameLabelin the Machine by setting it to the parent MachineSet.metadata.name, ignoring what was specified in the.spec.template.metadata.labelsof the parent MachineSet - the CAPI Machine that gets created from the scale up has
.metadata.labelsdiffering from the one its parent MachineSet uses to select/find its children in the.spec.selector.matchingLabels - the CAPI machineset controller as such is unable to keep track if its children, and keeps creating new ones as the diff between owned machines and spec.replicas is always < 0
What did you expect to happen?
Only one Machine being created.
Cluster API version
Reproduced in v1.9.z, might be in all supported versions.
Kubernetes version
v1.32
Anything else you would like to add?
No response
Label(s) to be applied
/kind bug
/area machineset /area machine