kubernetes/kops · error

error fetching cluster %q: %v

Error message

error fetching cluster %q: %v

What it means

When replacing a Cluster manifest, kops calls clientset.GetCluster to check whether the cluster exists in the state store. If the lookup fails with anything other than NotFound (which is treated as 'does not exist'), the failure is wrapped in this error.

Source

Thrown at cmd/kops/replace.go:135

				{
					// Retrieve the current status of the cluster.  This will eventually be part of the cluster object.
					cloud, err := cloudup.BuildCloud(v)
					if err != nil {
						return err
					}
					status, err := cloud.FindClusterStatus(v)
					if err != nil {
						return err
					}

					// Check if the cluster exists already
					clusterName := v.Name
					cluster, err := clientset.GetCluster(ctx, clusterName)
					if err != nil {
						if errors.IsNotFound(err) {
							cluster = nil
						} else {
							return fmt.Errorf("error fetching cluster %q: %v", clusterName, err)
						}
					}
					if cluster == nil {
						if !c.Force {
							return fmt.Errorf("cluster %v does not exist (try adding --force flag)", clusterName)
						}

						err = cloudup.PerformAssignments(v, vfsContext, cloud)
						if err != nil {
							return fmt.Errorf("error populating configuration: %w", err)
						}

						_, err = clientset.CreateCluster(ctx, v)
						if err != nil {
							return fmt.Errorf("error creating cluster: %v", err)
						}
					} else {
						_, err = clientset.UpdateCluster(ctx, v, status)

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Check KOPS_STATE_STORE / --state points at the correct, existing bucket/container
  2. Verify cloud credentials and read permissions on the state store (`kops get clusters` as a smoke test)
  3. Test network connectivity/DNS to the state store backend
  4. Inspect the wrapped underlying error (%v) for the exact backend failure
  5. If the cluster truly should not exist, confirm the name in the manifest is correct

Example fix

// before
export KOPS_STATE_STORE=s3://wrong-bucket
// after
export KOPS_STATE_STORE=s3://my-clusters-state-store
Defensive patterns

Strategy: try-catch

Validate before calling

// smoke-test the state store first
if err := exec.Command("kops", "get", "clusters").Run(); err != nil {
    return fmt.Errorf("state store unreachable: %w", err)
}

Try / catch

if err != nil {
    if !errors.IsNotFound(err) {
        // backend failure, not absence: check state store config/credentials
        log.Printf("GetCluster(%s) backend error: %v", clusterName, err)
    }
    return err
}

Prevention

When it happens

Trigger: State store unreachable or misconfigured (--state / KOPS_STATE_STORE pointing at a nonexistent bucket), credentials lacking permission to read the state store, network timeout to the backend, or corrupted state-store entry for the cluster name.

Common situations: Wrong KOPS_STATE_STORE env var (e.g. pointing at another team's bucket); IAM/S3 permission revoked; offline/blocked network in CI; cluster name in the manifest differs from what you expected and the state store backend errors.

Related errors


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