kubernetes/kops · error

could not delete instance %q: %v

Error message

could not delete instance %q: %v

What it means

Wrapped error returned when deleting a Nova server (instance) by ID fails while tearing down an OpenStack instance group. kOps lists the group's instances and calls DeleteInstanceWithID for each; any per-instance failure aborts the group deletion.

Source

Thrown at upup/pkg/fi/cloudup/openstack/cloud.go:661

	cluster := g.Raw.(*kops.Cluster)
	allInstances, err := c.ListInstances(servers.ListOpts{
		Name: fmt.Sprintf("^%s", g.InstanceGroup.Name),
	})
	if err != nil {
		return err
	}

	instances := []servers.Server{}
	for _, instance := range allInstances {
		if !InstanceInClusterAndIG(instance, cluster.Name, g.InstanceGroup.Name) {
			continue
		}
		instances = append(instances, instance)
	}
	for _, instance := range instances {
		err := c.DeleteInstanceWithID(instance.ID)
		if err != nil {
			return fmt.Errorf("could not delete instance %q: %v", instance.ID, err)
		}
	}

	err = deletePorts(c, g.InstanceGroup.Name, cluster.Name)
	if err != nil {
		return err
	}

	sgName := g.InstanceGroup.Name
	if name, ok := g.InstanceGroup.Annotations[OS_ANNOTATION+SERVER_GROUP_NAME]; ok {
		sgName = name
	}
	sgs, err := c.ListServerGroups(servergroups.ListOpts{})
	if err != nil {
		return fmt.Errorf("could not list server groups %v", err)
	}

	for _, sg := range sgs {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Inspect the wrapped error: 404 means the instance is gone, re-run delete to continue
  2. If 409, wait for the server to leave its task state then retry
  3. Check `openstack server show <id>` to confirm state and project ownership
  4. Verify credentials (OS_USERNAME/OS_PROJECT_NAME) target the correct project
Defensive patterns

Strategy: retry

Validate before calling

srv, err := c.GetInstance(instance.ID)
if err != nil { /* skip: already gone */ }
if srv.Status == "DELETING" || srv.TaskState != "" { wait }

Try / catch

if err := c.DeleteInstanceWithID(instance.ID); err != nil {
    var gErr gophercloud.ErrUnexpectedResponseCode
    if errors.As(err, &gErr) && gErr.Actual == 404 { continue }
    return fmt.Errorf("could not delete instance %q: %v", instance.ID, err)
}

Prevention

When it happens

Trigger: DeleteInstanceWithID(instance.ID) returns an error from the Nova API, typically 404 (instance already terminated), 409 (instance in transitional task state), or auth/endpoint failure.

Common situations: Instance previously deleted manually or by autoscaler; server stuck in DELETING/REBUILDING state so Nova returns 409; expired OpenStack token; wrong project credentials so the instance is not visible.

Related errors


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