{"record":{"id":"d87c3e3bae8ab8be","repo":"kubernetes/kops","slug":"project-metadata-was-empty","errorCode":null,"errorMessage":"project metadata was empty","messagePattern":"project metadata was empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/nodeidentity/gce/identify.go","lineNumber":80,"sourceCode":"\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) {\n\t// log := klog.FromContext(ctx)\n\n\tproviderID := node.Spec.ProviderID\n\tif providerID == \"\" {","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/nodeidentity/gce/identify.go#L62-L98","documentation":"metadata.ProjectID() succeeded but returned an empty string (even after trimming whitespace). Without a project ID the GCE node identifier cannot query instances, so New() refuses to start rather than produce a broken identifier.","triggerScenarios":"The GCE metadata server responds 200 with an empty project ID body while GCP_PROJECT is unset — rare, typically a metadata service anomaly or an instance without a resolvable project context.","commonSituations":"Degenerate metadata responses on oddly configured instances; mocking/proxying of the metadata endpoint returning empty payloads; project association issues on the VM.","solutions":["Set the GCP_PROJECT environment variable explicitly to bypass the metadata lookup","Restart the instance or retry if the metadata service returned an anomalous empty response","Verify the VM is actually associated with a valid GCP project in the console","Check whether any proxy/sidecar intercepts metadata requests and returns empty bodies"],"exampleFix":"// before\n# GCP_PROJECT unset\n// after\nGCP_PROJECT=my-project-id kops-controller ...","handlingStrategy":"validation","validationCode":"project := strings.TrimSpace(os.Getenv(\"GCP_PROJECT\"))\nif project == \"\" {\n    p, err := metadata.ProjectID()\n    if err != nil || strings.TrimSpace(p) == \"\" {\n        return errors.New(\"could not determine GCP project\")\n    }\n}","typeGuard":null,"tryCatchPattern":"ident, err := nodeidentitygce.New(clusterName, capiManager)\nif err != nil {\n    if strings.Contains(err.Error(), \"project metadata was empty\") {\n        // set GCP_PROJECT env var and restart the controller\n    }\n}","preventionTips":["Set GCP_PROJECT explicitly rather than depending on metadata","Verify the VM is bound to a real GCP project","Investigate metadata proxies that may return empty payloads","Fail fast at startup with a clear message when the project can't be resolved"],"tags":["gce","metadata","project-id","empty-value"],"backgroundTag":"metadata-value-empty","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}