{"record":{"id":"b709e7f46d15f1b6","repo":"cilium/cilium","slug":"encountered-duplicate-bgp-instance-with-name-s","errorCode":null,"errorMessage":"encountered duplicate BGP instance with name %s","messagePattern":"encountered duplicate BGP instance with name (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/bgp/manager/workdiff.go","lineNumber":79,"sourceCode":"\t\tfallthrough\n\tcase len(wd.reconcile) > 0:\n\t\treturn false\n\t}\n\treturn true\n}\n\n// registerOrReconcileDiff will populate the `seen` field of the reconcileDiff with `policy`,\n// compute BgpServers which must be registered and mark existing BgpServers for\n// reconciliation of their configuration.\n//\n// since registerOrReconcileDiff populates the `seen` field of a diff, this method should always\n// be called first when computing a reconcileDiff.\nfunc (wd *reconcileDiff) registerOrReconcileDiff(existingInstances map[string]*instance.BGPInstance, desiredConfig *v2.CiliumBGPNodeConfig) error {\n\tfor i, config := range desiredConfig.Spec.BGPInstances {\n\t\tif _, ok := wd.seen[config.Name]; !ok {\n\t\t\twd.seen[config.Name] = &desiredConfig.Spec.BGPInstances[i]\n\t\t} else {\n\t\t\treturn fmt.Errorf(\"encountered duplicate BGP instance with name %s\", config.Name)\n\t\t}\n\t\tif existing, ok := existingInstances[config.Name]; !ok {\n\t\t\t// new instance\n\t\t\twd.register = append(wd.register, config.Name)\n\t\t} else {\n\t\t\t// existing instance\n\t\t\trecreate, err := wd.requiresRecreate(existing, &desiredConfig.Spec.BGPInstances[i])\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif recreate {\n\t\t\t\twd.withdraw = append(wd.withdraw, config.Name)\n\t\t\t\twd.register = append(wd.register, config.Name) // register does an initial reconciliation as well\n\t\t\t} else {\n\t\t\t\twd.reconcile = append(wd.reconcile, config.Name)\n\t\t\t}\n\t\t}\n\t}","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/pkg/bgp/manager/workdiff.go#L61-L97","documentation":"registerOrReconcileDiff rejects a CiliumBGPNodeConfig whose Spec.BGPInstances list contains two entries with the same `name`, because instance names are used as map keys and session identifiers. The diff computation aborts immediately on the first duplicate, so the whole node config is not reconciled.","triggerScenarios":"Iterating desiredConfig.Spec.BGPInstances in registerOrReconcileDiff when wd.seen already contains config.Name — i.e. two YAML/JSON BGPInstances entries with an identical name in one CiliumBGPNodeConfig.","commonSituations":"Copy-pasting a BGPInstances block and forgetting to change the name; Helm/kustomize templates rendering the same name twice; merging patches that append a duplicate instance instead of replacing it.","solutions":["Edit the CiliumBGPNodeConfig and give every BGPInstances entry a unique `name`.","Re-apply the CR and confirm the agent log no longer reports the duplicate.","If generated via Helm/kustomize, fix the template so instance names are parameterized and unique.","Optionally add a CRD-level validation or admission policy to reject duplicate instance names early."],"exampleFix":"# before\nbgpInstances:\n- name: \"instance-1\"\n  localASN: 65001\n- name: \"instance-1\"\n  localASN: 65002\n# after\nbgpInstances:\n- name: \"instance-1\"\n  localASN: 65001\n- name: \"instance-2\"\n  localASN: 65002","handlingStrategy":"validation","validationCode":"seen := map[string]struct{}{}\nfor _, i := range cfg.Spec.BGPInstances {\n\tif _, dup := seen[i.Name]; dup {\n\t\treturn fmt.Errorf(\"duplicate BGP instance name %q\", i.Name)\n\t}\n\tseen[i.Name] = struct{}{}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Enforce unique instance names via a CRD enum-free but admission-policy check (e.g. ValidatingAdmissionPolicy, CEL uniqueness).","In Helm/kustomize, generate instance names from a map key so duplicates are impossible.","Run `kubectl apply --dry-run=server` plus a lint script over BGP configs.","Review diffs after merging CR changes to catch copy-pasted blocks."],"tags":["bgp","config","duplicate","validation"],"backgroundTag":"duplicate-resource-name","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}