kubernetes/kops · error

error waiting for router creation: %w

Error message

error waiting for router creation: %w

What it means

Returned by RenderGCE when the GCE operation object produced by Routers().Insert() completes with an error, as reported by t.Cloud.WaitForOp(op). The Insert call itself was accepted, but the long-running Google operation failed server-side, so the Cloud Router was not created. The wrapped error contains Google's operation error details.

Source

Thrown at upup/pkg/fi/cloudup/gcetasks/router.go:176

					Name:                          *e.Name,
					NatIpAllocateOption:           *e.NATIPAllocationOption,
					SourceSubnetworkIpRangesToNat: *e.SourceSubnetworkIPRangesToNAT,
				},
			},
		}

		for _, subnet := range e.Subnetworks {
			router.Nats[0].Subnetworks = append(router.Nats[0].Subnetworks, &compute.RouterNatSubnetworkToNat{
				Name:                subnet.URL(project, region),
				SourceIpRangesToNat: []string{subnetNatAllIPRanges},
			})
		}
		op, err := t.Cloud.Compute().Routers().Insert(project, region, router)
		if err != nil {
			return fmt.Errorf("error creating Router: %w", err)
		}
		if err := t.Cloud.WaitForOp(op); err != nil {
			return fmt.Errorf("error waiting for router creation: %w", err)
		}
	} else {
		if !reflect.DeepEqual(changes, &Router{}) {
			return fmt.Errorf("applying changes to Router is unsupported: %s", *e.Name)
		}
	}

	return nil
}

type terraformRouterNat struct {
	Name                          *string                         `cty:"name"`
	Region                        *string                         `cty:"region"`
	Router                        *terraformWriter.Literal        `cty:"router"`
	NATIPAllocateOption           *string                         `cty:"nat_ip_allocate_option"`
	SourceSubnetworkIPRangesToNat *string                         `cty:"source_subnetwork_ip_ranges_to_nat"`
	Subnetworks                   []*terraformRouterNatSubnetwork `cty:"subnetwork"`
}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Inspect the wrapped operation error for the specific Google failure reason (e.g. resource not found, already exists)
  2. Verify the VPC network and subnets referenced by the router exist in the target region before applying
  3. If name conflict, delete or rename the pre-existing router in the region (gcloud compute routers list)
  4. Re-run `kops update cluster` once the referenced resources have propagated — this is often transient
  5. Check Google Cloud status / regional incidents if the operation error is an internalError

Example fix

null
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure referenced network exists before creating the router
_, err := compute.Networks.Get(projectID, networkName).Do()
if err != nil { return fmt.Errorf("network %s not found: %w", networkName, err) }

Type guard

func isOpError(op *compute.Operation) bool {
    return op != nil && op.Status == "DONE" && op.Error != nil
}

Try / catch

if err := t.Cloud.WaitForOp(op); err != nil {
    var ge *googleapi.Error
    if errors.As(err, &ge) {
        return fmt.Errorf("router creation op failed (%d): %w", ge.Code, err)
    }
    return fmt.Errorf("error waiting for router creation: %w", err)
}

Prevention

When it happens

Trigger: Routers().Insert succeeds in enqueueing an operation, but WaitForOp polls it and finds status DONE with an error field — e.g. the referenced network/subnet doesn't exist, a router name conflict, or a Google-side failure while creating the router in the region.

Common situations: Network/subnet resources not fully propagated (created earlier in the same apply but eventually-consistent on Google's side); invalid network name in cluster spec; router name collides with a manually created router; regional capacity/API incidents.

Related errors


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