set-project-id
KRM function for set-project-id
set-project-id #
Overview #
The set-project-id
function sets ‘project-id’
setter and
cnrm.cloud.google.com/project-id
annotation to the provided project ID, only
if they are not already set.
Usage #
set-project-id function is expected to be executed imperatively like:
kpt fn eval --include-meta-resources --image gcr.io/kpt-fn/set-project-id:v0.2.0 -- 'project-id=foo'
The set-project-id
function does the following:
- Sets the the ‘project-id’ setter to the provided project ID.
- If an ‘apply-setters’ function is present in the Kptfile which does not have the ‘project-id’ setter or sets it to an empty value, update that config to set the “project-id” setter to the provided project ID value.
- If no ‘apply-setters’ function is present in the Kptfile, add one with just the ‘project-id’ setter set to the provided project ID value.
- If no pipeline is declared in the Kptfile, declare it and add ‘apply-setters’ function as mutator with the ‘project-id’ setter set to the provided project ID value.
- For all
Config Connector resources,
check if they have the
cnrm.cloud.google.com/project-id
annotation set. If the annotation is not present or is set to an empty value, set it to the provided project ID value.
FunctionConfig #
This function supports ConfigMap
functionConfig
and expects the ‘project-id’
value to be present in the map.
Examples #
Setting the project-id
setter on the package without setters.
Let’s start with the Kptfile of an example package.
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: example-package
Invoke the function:
kpt fn eval --include-meta-resources --image gcr.io/kpt-fn/set-project-id:v0.2.0 -- 'project-id=foo'
Kptfile will be updated to the following:
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: example-package
pipeline:
mutators:
- image: gcr.io/kpt-fn/apply-setters:v0.2
configMap:
project-id: foo
Last modified October 9, 2025: Moving the documentation to Hugo (#1177) (a7f5458)