{"record":{"id":"8a84aa103b780364","repo":"kubernetes/kops","slug":"malformed-format-of-loadbalancer-id-s-d","errorCode":null,"errorMessage":"malformed format of loadbalancer ID: %s, %d","messagePattern":"malformed format of loadbalancer ID: (.+?), (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/azure/azure_utils.go","lineNumber":138,"sourceCode":"\tSubscriptionID    string\n\tResourceGroupName string\n\tLoadBalancerName  string\n}\n\n// String returns the load balancer ID in the path format.\nfunc (lb *LoadBalancerID) String() string {\n\treturn fmt.Sprintf(\"/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/loadbalancers/%s/backendAddressPools/LoadBalancerBackEnd\",\n\t\tlb.SubscriptionID,\n\t\tlb.ResourceGroupName,\n\t\tlb.LoadBalancerName,\n\t)\n}\n\n// ParseLoadBalancerID parses a given load balancer ID string and returns a LoadBalancerID.\nfunc ParseLoadBalancerID(lb string) (*LoadBalancerID, error) {\n\tl := strings.Split(lb, \"/\")\n\tif len(l) != 11 {\n\t\treturn nil, fmt.Errorf(\"malformed format of loadbalancer ID: %s, %d\", lb, len(l))\n\t}\n\treturn &LoadBalancerID{\n\t\tSubscriptionID:    l[2],\n\t\tResourceGroupName: l[4],\n\t\tLoadBalancerName:  l[8],\n\t}, nil\n}\n\n// PublicIPAddressID contains the resource ID/names required to construct a PublicIPAddress ID.\ntype PublicIPAddressID struct {\n\tSubscriptionID      string\n\tResourceGroupName   string\n\tPublicIPAddressName string\n}\n\n// String returns the PublicIPAddress ID in the path format.\nfunc (s *PublicIPAddressID) String() string {\n\treturn fmt.Sprintf(\"/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/publicIPAddresss/%s\",","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/azure/azure_utils.go#L120-L156","documentation":"ParseLoadBalancerID parses an Azure load balancer resource ID of the form /subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.Network/loadBalancers/<lb>/... where the path must split into exactly 11 slash-separated segments. If the count differs, the ID is malformed and this error reports the observed segment count. Called by the load balancer task's Find and unit tests.","triggerScenarios":"Calling ParseLoadBalancerID with a truncated load balancer path, a bare name, or an ID of another resource type — e.g. a 9-segment NSG-style ID or an 11-segment subnet ID with wrong resource hierarchy.","commonSituations":"Copy-pasting a truncated ID from CLI/portal output; passing a subnet or NSG ID into a load balancer field; load balancer name containing \"/\" (changes count); manual edits to cluster spec api loadBalancer configuration.","solutions":["Provide the full load balancer resource ID as expected by kOps (11 slash-delimited segments including the name segment).","Fetch the canonical ID with `az network lb show -g <rg> -n <lb> --query id` and use it.","Count segments (strings.Split on \"/\") equals 11 before passing.","Verify the correct ID type is placed in the load balancer field of the spec, not a subnet/NSG ID.","Re-run kops update cluster after correcting the spec."],"exampleFix":"// before\nlbID = \"/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Network/loadBalancers\"\n// after\nlbID = \"/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/my-lb/frontendIPConfigurations/pip\"","handlingStrategy":"validation","validationCode":"// Go: validate load balancer ID shape before parsing\nfunc looksLikeAzureLBID(s string) bool {\n    l := strings.Split(s, \"/\")\n    return len(l) == 11 &&\n        l[1] == \"subscriptions\" &&\n        l[3] == \"resourcegroups\" &&\n        strings.Contains(s, \"loadBalancers/\")\n}\nif !looksLikeAzureLBID(lbID) {\n    return fmt.Errorf(\"expected full load balancer resource ID, got %q\", lbID)\n}","typeGuard":"func isLoadBalancerID(s string) bool {\n    return strings.HasPrefix(s, \"/subscriptions/\") &&\n        strings.Contains(s, \"loadBalancers/\") &&\n        strings.Count(s, \"/\") == 10\n}","tryCatchPattern":"parsed, err := azure.ParseLoadBalancerID(lbID)\nif err != nil {\n    log.Printf(\"load balancer ID %q malformed (%v); check segment count is 11\", lbID, err)\n    return err\n}","preventionTips":["Use az network lb show --query id to obtain the canonical ID.","Verify the expected 11-segment path form for load balancer IDs in this codebase.","Keep load balancer names free of \"/\" characters.","Don't pass subnet/NSG/PIP IDs into load balancer fields.","Validate spec ID fields with unit tests (TestLoadBalancerIDParse pattern) in CI."],"tags":["azure","resource-id","parsing","load-balancer"],"backgroundTag":"malformed-azure-resource-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"}