kubernetes/kops · error

expected exactly one subnet for GCE, got %d

Error message

expected exactly one subnet for GCE, got %d

What it means

setupZones (GCE branch) validation: fires when more than one subnet ID is provided for a GCE cluster. Because GCE clusters in kOps are single-region and one subnet per region, multiple --subnet-ids cannot be mapped, so creation aborts with the offending count.

Source

Thrown at upup/pkg/fi/cloudup/new_cluster.go:754

		for _, zoneName := range allZones.List() {
			region, err := gce.ZoneToRegion(zoneName)
			if err != nil {
				return nil, err
			}

			// We create default subnets named the same as the regions
			subnetName := region

			subnet := model.FindSubnet(cluster, subnetName)
			if subnet == nil {
				subnet = &api.ClusterSubnetSpec{
					Name:   subnetName,
					Region: region,
				}
				if len(opt.SubnetIDs) != 0 {
					// We don't support multi-region clusters, so we can't have more than one subnet
					if len(opt.SubnetIDs) != 1 {
						return nil, fmt.Errorf("expected exactly one subnet for GCE, got %d", len(opt.SubnetIDs))
					}
					subnet.ID = opt.SubnetIDs[0]
				}
				cluster.Spec.Networking.Subnets = append(cluster.Spec.Networking.Subnets, *subnet)
			}
			zoneToSubnetsMap[zoneName] = append(zoneToSubnetsMap[zoneName], subnet)
		}

		return zoneToSubnetsMap, nil

	case api.CloudProviderDO:
		if len(opt.Zones) > 1 {
			return nil, fmt.Errorf("digitalocean cloud provider currently supports one region only.")
		}

		// For DO we just pass in the region for --zones
		region := opt.Zones[0]
		subnet := model.FindSubnet(cluster, region)

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Pass exactly one subnet ID for GCE clusters
  2. Keep the cluster single-region; create separate clusters for other regions
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at upup/pkg/fi/cloudup/new_cluster.go:754 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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