[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-02。"],[[["\u003cp\u003eConfig Connector determines resource creation location by checking for a scope-defining field (\u003ccode\u003eprojectRef\u003c/code\u003e) or annotation (\u003ccode\u003ecnrm.cloud.google.com/project-id\u003c/code\u003e) in the resource specification.\u003c/p\u003e\n"],["\u003cp\u003eMost project-scoped resources support the \u003ccode\u003eprojectRef\u003c/code\u003e field, which can directly specify the Google Cloud project ID or reference a Project resource managed in the same cluster.\u003c/p\u003e\n"],["\u003cp\u003eIf a resource lacks the \u003ccode\u003eprojectRef\u003c/code\u003e field, you can use the \u003ccode\u003ecnrm.cloud.google.com/project-id\u003c/code\u003e annotation in the resource's metadata to define the project.\u003c/p\u003e\n"],["\u003cp\u003eA default project ID can be applied to an entire Kubernetes namespace by annotating the namespace, and this annotation can be overwritten by a resource-specific annotation.\u003c/p\u003e\n"],["\u003cp\u003eIf no project is specified in a resource, or namespace annotation, then the namespace name will be used as the project ID, although it's not recommended.\u003c/p\u003e\n"]]],[],null,["# Project-scoped resources\n========================\n\n*** ** * ** ***\n\nConfig Connector can manage your resources at the project, folder, or\norganization level. In order for Config Connector to determine where to create\nyour resources, it first checks for a [scope-defining field](/config-connector/docs/how-to/organizing-resources/overview#scope-defining_field)\nin your resource spec, if not found, then checks for a [scope-defining annotation](/config-connector/docs/how-to/organizing-resources/overview#scope-defining_annotation).\n| **Note:** The scope concept does not apply to all Config Connector resources. See [Exceptions](/config-connector/docs/how-to/organizing-resources/overview#exceptions) for more details. You can check the [resource reference page](/config-connector/docs/reference/resources) to see if a resource supports the `spec.projectRef` field or `cnrm.cloud.google.com/project-id` annotation.\n\nSpecify `projectRef` field\n--------------------------\n\nMost project-scoped Config Connector resources support a field named `projectRef`\nin its CRD spec. Use this field to specify the Google Cloud project that you\nwant to create the resource in.\n\nIf the Google Cloud project is also managed in the same cluster with the\nthe [Project](/config-connector/docs/reference/resource-docs/resourcemanager/project)\nCRD, you can specify the project as a Kubernetes resource reference: \n\n ...\n spec:\n projectRef:\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003ePROJECT_RESOURCE_NAME\u003c/span\u003e\u003c/var\u003e\n namespace: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003ePROJECT_RESOURCE_NAMESPACE\u003c/span\u003e\u003c/var\u003e\n ...\n\nThis approach makes it possible to use Config Connector and create a Google Cloud\nproject with its child resources in one single apply operation.\nThe namespace field is optional if the project Kubernetes resource is in the\nsame Kubernetes namespace as your project-scoped resource.\n\nIf the Google Cloud project is not managed as a Kubernetes resource\nin the same cluster, you can use the `external` field to directly specify the\nproject ID. The exact format of the value may be different depending on the\nresource type. Two most common formats are \"\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\" and\n\"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\". See an example of\n\"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\" below: \n\n ...\n spec:\n projectRef:\n external: \"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\"\n ...\n\nAnnotate resource configuration\n-------------------------------\n\nIf the Config Connector resource is project-scoped but does not support\n`projectRef` field, you can set the project ID to the resource configuration\nusing the `project-id` annotation: \n\n ...\n metadata:\n annotations:\n cnrm.cloud.google.com/project-id: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003ePROJECT_ID\u003c/span\u003e\u003c/var\u003e\n ...\n\nHere is an example of what a `FooBar` resource's YAML looks like with this\nannotation in it: \n\n apiVersion: foo.cnrm.cloud.google.com/v1beta1\n kind: FooBar\n metadata:\n annotations:\n cnrm.cloud.google.com/project-id: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003ePROJECT_ID\u003c/span\u003e\u003c/var\u003e\n name: foobarname\n\nAnnotate namespace configuration\n--------------------------------\n\nYou can set a default project ID for newly-created resources by\nannotating your Kubernetes namespace. If any of the resources in the namespace\nhave this annotation explicitly set in its own configuration, the resource-level\nannotation overwrites the namespace-level annotation.\n\nTo annotate the namespace using command line, run the following command: \n\n```\nkubectl annotate namespace NAMESPACE_NAME cnrm.cloud.google.com/project-id=PROJECT_ID\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eNAMESPACE_NAME\u003c/var\u003e: your namespace name\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: your Google Cloud project ID\n\nAlternatively, you can apply a YAML manifest containing the\nannotation. Copy the YAML below into a file: \n\n apiVersion: v1\n kind: Namespace\n metadata:\n annotations:\n cnrm.cloud.google.com/project-id: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003ePROJECT_ID\u003c/span\u003e\u003c/var\u003e\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eNAMESPACE_NAME\u003c/span\u003e\u003c/var\u003e\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: your Google Cloud project ID\n- \u003cvar translate=\"no\"\u003eNAMESPACE_NAME\u003c/var\u003e: your namespace name\n\nAfter you have created the file, apply it to your cluster.\n| **Note:** You must create the namespace and annotation before applying any resources to the namespace.\n\nUsing the namespace name as the project ID\n------------------------------------------\n\nIf neither the resource nor the namespace specifies a project ID, then\nConfig Connector uses the namespace's name as the project ID. This default\nbehavior is supported by Config Connector but we don't recommend it since the\nimplicit default of project ID can be confusing."]]