Skip to content

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

@damdo

Description

@damdo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/machineIssues or PRs related to machine lifecycle managementarea/machinesetIssues or PRs related to machinesetshelp wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/bugCategorizes issue or PR as related to a bug.priority/important-longtermImportant over the long term, but may not be staffed and/or may need multiple releases to complete.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