{"record":{"id":"15e3dc601d1cb557","repo":"kubernetes/kops","slug":"unable-to-parse-instance-url-q","errorCode":null,"errorMessage":"unable to parse instance url %q","messagePattern":"unable to parse instance url %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/resources/gce/dump.go","lineNumber":52,"sourceCode":"\tcloud gce.GCECloud\n\n\t// mutex protects the follow resources\n\tmutex sync.Mutex\n\n\t// instances is a cache of instances by zone\n\tinstances map[string]map[string]*compute.Instance\n\n\t// disks is a cache of disks by zone\n\tdisks map[string]map[string]*compute.Disk\n}\n\n// DumpManagedInstance is responsible for dumping a resource for a ManagedInstance\nfunc DumpManagedInstance(op *resources.DumpOperation, r *resources.Resource) error {\n\tinstance := r.Obj.(*compute.ManagedInstance)\n\n\tu, err := gce.ParseGoogleCloudURL(instance.Instance)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unable to parse instance url %q\", instance.Instance)\n\t}\n\n\t// Fetch instance details\n\tinstanceMap, err := getDumpState(op).getInstances(op.Context, u.Zone)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\ti := &resources.Instance{\n\t\tName: u.Name,\n\t}\n\n\tinstanceDetails := instanceMap[u.Name]\n\tif instanceDetails == nil {\n\t\tvar sb strings.Builder\n\t\tfmt.Fprintf(&sb, \"instance %q not found (currentAction=%q instanceStatus=%q)\", instance.Instance, instance.CurrentAction, instance.InstanceStatus)\n\t\tif instance.LastAttempt != nil && instance.LastAttempt.Errors != nil {\n\t\t\tfor _, e := range instance.LastAttempt.Errors.Errors {","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/resources/gce/dump.go#L34-L70","documentation":"DumpManagedInstance casts the resource object to a GCE ManagedInstance and parses its Instance self-link URL with gce.ParseGoogleCloudURL; if the URL doesn't match the expected projects/zones/instances format, it returns 'unable to parse instance url %q' without wrapping the parse error. This means the instance self-link stored on the resource is malformed or empty.","triggerScenarios":"instance.Instance is empty, truncated, or not a full Google Cloud self-link (e.g. 'https://www.googleapis.com/compute/v1/projects/<proj>/zones/<zone>/instances/<name>') during 'kops toolbox dump' on a GCE cluster.","commonSituations":"Dangling/stale ManagedInstance resources from a partially deleted instance group, resources built from an older kops version that stored relative URLs, or manual edits to the cluster state.","solutions":["Log/inspect the failing instance.Instance value printed in the error and compare against the expected Google self-link format.","Refresh cluster state (kops update cluster / re-export) so instance resources carry current, full self-links.","Delete the orphaned ManagedInstance resource from the instance group state if the underlying VM no longer exists, then re-run the dump.","If the URL is valid but still rejected, check the gce.ParseGoogleCloudURL regex against your URL form (regional vs global paths) and update kops."],"exampleFix":"// before\nu, err := gce.ParseGoogleCloudURL(instance.Instance)\nif err != nil {\n\treturn fmt.Errorf(\"unable to parse instance url %q\", instance.Instance)\n}\n// after\nu, err := gce.ParseGoogleCloudURL(instance.Instance)\nif err != nil {\n\treturn fmt.Errorf(\"unable to parse instance url %q: %w\", instance.Instance, err)\n}","handlingStrategy":"validation","validationCode":"var gceSelfLinkRe = regexp.MustCompile(`^https://www\\.googleapis\\.com/compute/[^/]+/projects/[^/]+/zones/[^/]+/instances/[^/]+$`)\nfunc instanceURLValid(selfLink string) bool { return gceSelfLinkRe.MatchString(selfLink) }\n// call before DumpManagedInstance: if !instanceURLValid(instance.Instance) { skip/log }","typeGuard":"func isFullGCEInstanceURL(u string) bool {\n\t_, err := gce.ParseGoogleCloudURL(u)\n\treturn err == nil && strings.HasPrefix(u, \"https://www.googleapis.com/compute/\")\n}","tryCatchPattern":"if err := resources.DumpManagedInstance(op, r); err != nil {\n\tif strings.HasPrefix(err.Error(), \"unable to parse instance url\") {\n\t\tklog.Warningf(\"skipping resource with malformed instance URL: %v\", err)\n\t\treturn nil // continue dump instead of failing whole run\n\t}\n\treturn err\n}","preventionTips":["Keep kops state in sync so ManagedInstance objects carry full Google self-links","Purge orphaned resources after partial deletions before running toolbox dump","Validate self-link format when constructing resource objects","Watch for version changes in Google compute API URL schemes"],"tags":["gce","url-parsing","dump"],"backgroundTag":"url-parse-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}