{"record":{"id":"faabda582da0dd85","repo":"kubernetes/kops","slug":"found-multiple-instances-with-name-s","errorCode":null,"errorMessage":"found multiple Instances with name: %s","messagePattern":"found multiple Instances with name: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awstasks/instance.go","lineNumber":103,"sourceCode":"\n\tresponse, err := cloud.EC2().DescribeInstances(ctx, request)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error listing instances: %v\", err)\n\t}\n\n\tinstances := []ec2types.Instance{}\n\tif response != nil {\n\t\tfor _, reservation := range response.Reservations {\n\t\t\tinstances = append(instances, reservation.Instances...)\n\t\t}\n\t}\n\n\tif len(instances) == 0 {\n\t\treturn nil, nil\n\t}\n\n\tif len(instances) != 1 {\n\t\treturn nil, fmt.Errorf(\"found multiple Instances with name: %s\", *e.Name)\n\t}\n\n\tklog.V(2).Info(\"found existing instance\")\n\ti := instances[0]\n\n\tif i.InstanceId == nil {\n\t\treturn nil, fmt.Errorf(\"found instance, but InstanceId was nil\")\n\t}\n\n\tactual := &Instance{\n\t\tID:               i.InstanceId,\n\t\tPrivateIPAddress: i.PrivateIpAddress,\n\t\tInstanceType:     i.InstanceType,\n\t\tImageID:          i.ImageId,\n\t\tName:             findNameTag(i.Tags),\n\t}\n\n\t// Fetch instance UserData","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awstasks/instance.go#L85-L121","documentation":"After DescribeInstances, Find() expects the task's name tag to match exactly one EC2 instance. If more than one instance matches the name, it cannot determine which one this task manages, so it fails rather than mutating the wrong instance. This is a uniqueness invariant of kops instance naming.","triggerScenarios":"Two or more EC2 instances carry the same value for the filter kops uses (typically the Name tag combination for the instance group) in the same VPC/cluster.","commonSituations":"Manually launching a copy of an instance with the same tags; an autoscaling event leaving a duplicate; misconfigured instance group names colliding; snapshots/AMIs baked with tags being reused.","solutions":["List instances with the duplicated name tag (aws ec2 describe-instances --filters Name=tag:Name,Values=...) and terminate/retag the duplicate.","Ensure instance groups have unique names in the cluster spec.","If the duplicate was created by a stuck ASG, fix the ASG (delete stale instances).","Re-run kops apply once the name is unique."],"exampleFix":"# before: two instances tagged Name=nodes.cluster.k8s.local\naws ec2 terminate-instances --instance-ids i-0duplicate\n# after: only one instance with that tag remains","handlingStrategy":"validation","validationCode":"out, err := ec2.DescribeInstances(ctx, &ec2.DescribeInstancesInput{\n  Filters: []ec2types.Filter{{Name: aws.String(\"tag:k8s.io/cluster/cluster.k8s.local\"), Values: []string{\"owned\"}}},\n})\n// count instances per Name tag; fail if any tag maps to >1 instance","typeGuard":"func exactlyOne(instances []ec2types.Instance) (ec2types.Instance, bool) {\n  if len(instances) != 1 { return ec2types.Instance{}, false }\n  return instances[0], true\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"found multiple Instances with name\") {\n  klog.Errorf(\"duplicate instance name tags; dedupe before applying: %v\", err)\n}","preventionTips":["Never manually launch instances reusing kops Name/cluster tags.","Keep instance group names unique within the cluster.","Clean up stuck ASG/rolling-update leftovers before re-applying.","Use `kops toolbox instance-selector`/IG naming conventions instead of hand-tagged instances."],"tags":["aws","ec2","duplicate-resources","tagging"],"backgroundTag":"duplicate-resource-name","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"}