kubernetes-sigs/cluster-api

MachineSet with wrong MachineSetNameLabel value in .spec.selector spawns infinite Machines

Open

#12,156 opened on May 7, 2025

View on GitHub
 (11 comments) (0 reactions) (1 assignee)Go (1,532 forks)auto 404
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.matchLabels and .spec.template.metadata.labels 's cluster.x-k8s.io/set-name but with its .metadata.name differing 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.labels value for the key clusterv1.MachineSetNameLabel in the Machine by setting it to the parent MachineSet .metadata.name, ignoring what was specified in the .spec.template.metadata.labels of the parent MachineSet
  • the CAPI Machine that gets created from the scale up has .metadata.labels differing 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

Contributor guide