kubernetes/kops · error

unable to parse instance url %q

Error message

unable to parse instance url %q

What it means

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.

Source

Thrown at pkg/resources/gce/dump.go:52

	cloud gce.GCECloud

	// mutex protects the follow resources
	mutex sync.Mutex

	// instances is a cache of instances by zone
	instances map[string]map[string]*compute.Instance

	// disks is a cache of disks by zone
	disks map[string]map[string]*compute.Disk
}

// DumpManagedInstance is responsible for dumping a resource for a ManagedInstance
func DumpManagedInstance(op *resources.DumpOperation, r *resources.Resource) error {
	instance := r.Obj.(*compute.ManagedInstance)

	u, err := gce.ParseGoogleCloudURL(instance.Instance)
	if err != nil {
		return fmt.Errorf("unable to parse instance url %q", instance.Instance)
	}

	// Fetch instance details
	instanceMap, err := getDumpState(op).getInstances(op.Context, u.Zone)
	if err != nil {
		return err
	}

	i := &resources.Instance{
		Name: u.Name,
	}

	instanceDetails := instanceMap[u.Name]
	if instanceDetails == nil {
		var sb strings.Builder
		fmt.Fprintf(&sb, "instance %q not found (currentAction=%q instanceStatus=%q)", instance.Instance, instance.CurrentAction, instance.InstanceStatus)
		if instance.LastAttempt != nil && instance.LastAttempt.Errors != nil {
			for _, e := range instance.LastAttempt.Errors.Errors {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Log/inspect the failing instance.Instance value printed in the error and compare against the expected Google self-link format.
  2. Refresh cluster state (kops update cluster / re-export) so instance resources carry current, full self-links.
  3. Delete the orphaned ManagedInstance resource from the instance group state if the underlying VM no longer exists, then re-run the dump.
  4. If the URL is valid but still rejected, check the gce.ParseGoogleCloudURL regex against your URL form (regional vs global paths) and update kops.

Example fix

// before
u, err := gce.ParseGoogleCloudURL(instance.Instance)
if err != nil {
	return fmt.Errorf("unable to parse instance url %q", instance.Instance)
}
// after
u, err := gce.ParseGoogleCloudURL(instance.Instance)
if err != nil {
	return fmt.Errorf("unable to parse instance url %q: %w", instance.Instance, err)
}
Defensive patterns

Strategy: validation

Validate before calling

var gceSelfLinkRe = regexp.MustCompile(`^https://www\.googleapis\.com/compute/[^/]+/projects/[^/]+/zones/[^/]+/instances/[^/]+$`)
func instanceURLValid(selfLink string) bool { return gceSelfLinkRe.MatchString(selfLink) }
// call before DumpManagedInstance: if !instanceURLValid(instance.Instance) { skip/log }

Type guard

func isFullGCEInstanceURL(u string) bool {
	_, err := gce.ParseGoogleCloudURL(u)
	return err == nil && strings.HasPrefix(u, "https://www.googleapis.com/compute/")
}

Try / catch

if err := resources.DumpManagedInstance(op, r); err != nil {
	if strings.HasPrefix(err.Error(), "unable to parse instance url") {
		klog.Warningf("skipping resource with malformed instance URL: %v", err)
		return nil // continue dump instead of failing whole run
	}
	return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/15e3dc601d1cb557. Report an issue: GitHub.