kubernetes/kops · error
unable to determine gcp project for cluster
Error message
unable to determine gcp project for cluster
What it means
applyGCPCluster requires Cluster.Spec.Project to be set because the GCPCluster CAPI object must reference a GCP project. When the project field is empty, it returns this error instead of guessing. It means the kops Cluster spec lacks the mandatory GCP project.
Source
Thrown at pkg/controllers/clusterapi/cluster_controller.go:117
return err
}
if err := s.createKopsControlPlane(ctx, kube); err != nil {
return err
}
if err := s.createClusterObject(ctx, kube); err != nil {
return err
}
return nil
}
func (s *clusterScope) applyGCPCluster(ctx context.Context, kube client.Client) error {
// This is because of network tags in cloud-provider-gcp
// TODO: cloud-provider-gcp should not assume cluster name is a valid prefix
name := gce.SafeClusterName(s.Cluster.GetName())
gcpProject := s.Cluster.Spec.Project
if gcpProject == "" {
return fmt.Errorf("unable to determine gcp project for cluster")
}
gcpRegion := ""
for _, subnet := range s.Cluster.Spec.Subnets {
if gcpRegion == "" {
gcpRegion = subnet.Region
} else if gcpRegion != subnet.Region {
return fmt.Errorf("found multiple gcp regions for cluster")
}
}
if gcpRegion == "" {
return fmt.Errorf("unable to determine gcp region for cluster")
}
// TODO: Sync with LinkToNetwork
gcpNetworkName := s.Cluster.Spec.NetworkID
if gcpNetworkName == "" {
gcpNetworkName = gce.SafeTruncatedClusterName(s.Cluster.ObjectMeta.Name, 63)
}View on GitHub (pinned to 4c8573c808)
Solutions
- Set spec.project in the kops Cluster spec to the target GCP project ID
- Recreate the cluster with --project <gcp-project-id> if initially omitted
- Re-run reconciliation after applying the corrected spec
Example fix
// before spec: subnets: [...] # project missing // after spec: project: my-gcp-project subnets: [...]
Defensive patterns
Strategy: validation
Validate before calling
if len(cluster.Spec.Subnets) > 0 && cluster.Spec.Project == "" {
return fmt.Errorf("cluster %s: spec.project required for GCP", cluster.Name)
} Prevention
- Always pass --project when creating GCP clusters
- Add spec validation in admission/webhook for GCP clusters missing project
- Review manifests after migration between clouds
When it happens
Trigger: clusterScope.Apply() on a GCP cluster whose Cluster.Spec.Project is empty, during CAPI controller reconciliation.
Common situations: Cluster created without 'kops create cluster --project' or with spec.project deleted; migration of cluster manifest between clouds; automation generating manifests that omit project.
Related errors
- found multiple gcp regions for cluster
- unable to determine gcp region for cluster
- unable to determine gcp network for cluster
- applying GCPCluster object to cluster: %w
- error creating kops config template: %w
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/e3410c938d14ee96.
Report an issue: GitHub.