kubernetes/kops · error

error listing InstanceTemplates: %v

Error message

error listing InstanceTemplates: %v

What it means

The InstanceTemplate Find task lists all instance templates in the GCE project via the Compute API to locate the template matching this task's NamePrefix. If the List call fails with anything other than a NotFound, the task wraps and returns the underlying API error with this message.

Source

Thrown at upup/pkg/fi/cloudup/gcetasks/instancetemplate.go:105

var (
	_ fi.CloudupTask   = &InstanceTemplate{}
	_ fi.CompareWithID = &InstanceTemplate{}
)

func (e *InstanceTemplate) CompareWithID() *string {
	return e.ID
}

func (e *InstanceTemplate) Find(c *fi.CloudupContext) (*InstanceTemplate, error) {
	cloud := c.T.Cloud.(gce.GCECloud)

	templates, err := cloud.Compute().InstanceTemplates().List(context.Background(), cloud.Project())
	if err != nil {
		if gce.IsNotFound(err) {
			return nil, nil
		}
		return nil, fmt.Errorf("error listing InstanceTemplates: %v", err)
	}

	expected, err := e.mapToGCE(cloud.Project(), cloud.Region())
	if err != nil {
		return nil, err
	}

	for _, r := range templates {
		if !strings.HasPrefix(r.Name, fi.ValueOf(e.NamePrefix)+"-") {
			continue
		}

		if !matches(expected, r) {
			continue
		}

		actual := &InstanceTemplate{}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Read the wrapped inner error to identify the HTTP status/code
  2. Verify the Compute Engine API is enabled: `gcloud services list --enabled` in the target project
  3. Check credentials: ensure the service account has compute.admin/compute.viewer and the key is valid (`gcloud auth activate-service-account` test)
  4. If rate-limited (429), retry after backoff or reduce concurrent API usage
  5. If transient 5xx, simply re-run `kops update cluster`
Defensive patterns

Strategy: retry

Validate before calling

// Before running kops, sanity-check API access:
//   gcloud compute instance-templates list --project <project> > /dev/null
//   gcloud services list --enabled --project <project> | grep compute.googleapis.com

Try / catch

err := kops.UpdateCluster(...)
if err != nil && strings.Contains(err.Error(), "error listing InstanceTemplates") {
    // inspect wrapped cause; retry on 429/5xx, fail fast on 401/403
    if isTransient(err) { backoffAndRetry() }
}

Prevention

When it happens

Trigger: The compute.googleapis.com InstanceTemplates.List call returns a non-404 error: expired/insufficient service-account credentials, the Compute API disabled in the project, quota/rate-limit (429), transient 5xx from GCP, or network failure from the kOps node.

Common situations: Service account keys rotated/revoked mid-run; compute API not enabled on a new project; GCP regional outage or rate limiting during a large `kops update cluster`; wrong project configured so the caller lacks compute.reader.

Related errors


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