{"record":{"id":"857b8c0d0e60b3b0","repo":"kubernetes/kops","slug":"found-multiple-machines-with-providerid-q","errorCode":null,"errorMessage":"found multiple machines with providerID %q","messagePattern":"found multiple machines with providerID %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/nodeidentity/clusterapi/capimanager/manager.go","lineNumber":67,"sourceCode":"\t\tGroup:   \"cluster.x-k8s.io\",\n\t\tKind:    \"Machine\",\n\t\tVersion: \"v1beta1\",\n\t})\n\tif err := m.kubeClient.List(ctx, &machines); err != nil {\n\t\treturn nil, fmt.Errorf(\"error listing machines: %w\", err)\n\t}\n\tvar matches []*unstructured.Unstructured\n\tfor i := range machines.Items {\n\t\tmachine := &machines.Items[i]\n\t\tmachineSpecProviderID, _, _ := unstructured.NestedString(machine.Object, \"spec\", \"providerID\")\n\t\tif machineSpecProviderID != providerID {\n\t\t\tcontinue\n\t\t}\n\t\tmatches = append(matches, machine)\n\t}\n\tif len(matches) > 0 {\n\t\tif len(matches) > 1 {\n\t\t\treturn nil, fmt.Errorf(\"found multiple machines with providerID %q\", providerID)\n\t\t}\n\t\tmachine := matches[0]\n\t\tmachine = machine.DeepCopy()\n\t\treturn clusterapi.NewMachine(machine), nil\n\t}\n\n\treturn nil, nil\n}\n","sourceCodeStart":49,"sourceCodeEnd":76,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/nodeidentity/clusterapi/capimanager/manager.go#L49-L76","documentation":"After filtering Machine objects by matching spec.providerID, FindMachineByProviderID expects at most one match. If more than one Machine in the management cluster reports the same providerID, it returns this error rather than guessing. Duplicates indicate a serious CAPI state problem: leftover Machines from a failed rollout or cloned Machine objects sharing a backing instance.","triggerScenarios":"Two or more Machine objects whose spec.providerID equals the queried value — e.g. a Machine was deleted and recreated but the old object lingers in a terminating state, machines were copied across clusters/management clusters, or a rollout created a new Machine before the old one's providerID was cleared.","commonSituations":"Interrupted Cluster API rollout/upgrade leaving orphaned Machine resources; restoring Machine objects from backups into the same management cluster; manually creating a Machine with a providerID copied from an existing one; KCP/MachineDeployment reconciliation bugs.","solutions":["List machines and inspect duplicates: kubectl get machines -o jsonpath range over spec.providerID; identify the stale one.","Delete the orphaned/terminating duplicate Machine (ensure it is not backed by a live node).","Check the owning MachineDeployment/KubeadmControlPlane for stuck rollouts and fix the revision so old Machines are reaped.","Prevent recurrence by ensuring providerIDs are unique per instance and avoid restoring duplicate Machine manifests."],"exampleFix":"// before: stale duplicate\nkubectl get machine worker-abc worker-abc-old   # both spec.providerID azure://...same\n\n// after: remove the orphan\nkubectl delete machine worker-abc-old","handlingStrategy":"validation","validationCode":"var machines unstructured.UnstructuredList\n_ = kubeClient.List(ctx, &machines)\ncounts := map[string]int{}\nfor i := range machines.Items {\n    pid, _, _ := unstructured.NestedString(machines.Items[i].Object, \"spec\", \"providerID\")\n    counts[pid]++\n}\nfor pid, n := range counts {\n    if n > 1 {\n        return fmt.Errorf(\"providerID %q claimed by %d machines; clean up duplicates\", pid, n)\n    }\n}","typeGuard":null,"tryCatchPattern":"machine, err := mgr.FindMachineByProviderID(ctx, providerID)\nif err != nil && strings.Contains(err.Error(), \"found multiple machines\") {\n    return fmt.Errorf(\"inspect 'kubectl get machines' and delete the stale duplicate before retrying: %w\", err)\n}","preventionTips":["Alert on any providerID matching more than one Machine object","Complete rollouts before maintenance; reap stuck terminating Machines","Never restore Machine manifests without deduplicating providerIDs"],"tags":["clusterapi","duplicate-resources","provider-id","kubernetes","kops"],"backgroundTag":"duplicate-resource-matching-provider-id","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}