{"record":{"id":"cf091577d4e766df","repo":"kubernetes/kops","slug":"error-reading-project-from-gce-v","errorCode":null,"errorMessage":"error reading project from GCE: %v","messagePattern":"error reading project from GCE: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/nodeidentity/gce/identify.go","lineNumber":76,"sourceCode":"}\n\n// New creates and returns a nodeidentity.Identifier for Nodes running on GCE\nfunc New(clusterName string, capiManager *capimanager.Manager) (nodeidentity.Identifier, error) {\n\tctx := context.Background()\n\n\tcomputeService, err := compute.NewService(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error building compute API client: %v\", err)\n\t}\n\n\t// Project ID\n\tproject := os.Getenv(\"GCP_PROJECT\")\n\tif project != \"\" {\n\t\tklog.Infof(\"using project=%q from GCP_PROJECT env var\", project)\n\t} else {\n\t\tproject, err = metadata.ProjectID()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error reading project from GCE: %v\", err)\n\t\t}\n\t\tproject = strings.TrimSpace(project)\n\t\tif project == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"project metadata was empty\")\n\t\t}\n\t\tklog.Infof(\"Found project=%q\", project)\n\t}\n\n\treturn &nodeIdentifier{\n\t\tcomputeService: computeService,\n\t\tproject:        project,\n\t\tclusterName:    clusterName,\n\t\tcapiManager:    capiManager,\n\t}, nil\n}\n\n// IdentifyNode queries GCE for the node identity information\nfunc (i *nodeIdentifier) IdentifyNode(ctx context.Context, node *corev1.Node) (*nodeidentity.Info, error) {","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/nodeidentity/gce/identify.go#L58-L94","documentation":"When GCP_PROJECT is unset, New() falls back to reading the project ID from the GCE metadata server via metadata.ProjectID(). This error wraps any failure contacting or parsing the metadata response, so the identifier cannot scope its compute queries.","triggerScenarios":"GCP_PROJECT env var empty AND metadata.ProjectID() errors — controller not on GCE (no metadata server), metadata server unreachable, or credentials/metadata client misconfigured.","commonSituations":"Controller pod on non-GCP infrastructure without GCP_PROJECT set; network policy blocking 169.254.169.254; metadata service disabled or flaky on the instance; typo'd/empty GCP_PROJECT value falling through to the metadata path.","solutions":["Set the GCP_PROJECT environment variable explicitly for the controller process/pod so the metadata lookup is skipped","If running on GCE, verify the metadata server (169.254.169.254) is reachable and not blocked by firewall/network policy","Check that the instance has a correctly attached service account (metadata requires it)","Fix any typo or quoting issue that makes GCP_PROJECT effectively empty"],"exampleFix":"// before\n# GCP_PROJECT unset, relying on metadata server\n// after\nenv:\n- name: GCP_PROJECT\n  value: my-project-id","handlingStrategy":"validation","validationCode":"project := os.Getenv(\"GCP_PROJECT\")\nif project == \"\" {\n    if _, err := metadata.ProjectID(); err != nil {\n        return errors.New(\"GCP_PROJECT unset and metadata server unreachable\")\n    }\n}","typeGuard":null,"tryCatchPattern":"ident, err := nodeidentitygce.New(clusterName, capiManager)\nif err != nil {\n    if strings.Contains(err.Error(), \"error reading project from GCE\") {\n        // set GCP_PROJECT explicitly or fix metadata reachability, then restart\n    }\n}","preventionTips":["Always set GCP_PROJECT explicitly in controller manifests","Ensure link-local 169.254.169.254 is not blocked by network policy when relying on metadata","Verify instance service-account attachment for metadata access","Health-check metadata reachability before starting the controller"],"tags":["gce","metadata","project-id","env-var"],"backgroundTag":"metadata-server-unreachable","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}