@@ -59,6 +59,7 @@ pipeline context using notation like:
5959- ` {{ .desired.composite.resource.status.widgets }}`
6060- ` {{ (index .desired.composed "resource-name").resource.spec.widgets }}`
6161- ` {{ index .context "apiextensions.crossplane.io/environment" }}`
62+ - ` {{ index .extraResources "some-bucket-by-name" }}`
6263
6364This function supports all of Go's [built-in template functions][builtin]. The
6465above examples use the `index` function to access keys like `resource-name` that
@@ -106,6 +107,65 @@ $ crossplane beta render xr.yaml composition.yaml functions.yaml
106107See the [composition functions documentation][docs-functions] to learn more
107108about `crossplane beta render`.
108109
110+ # ## ExtraResources
111+
112+ By defining one or more special `ExtraResources`, you can ask Crossplane to
113+ retrieve additional resources from the local cluster and make them available to
114+ your templates. See the [docs][extra-resources] for more information.
115+
116+ ` ` ` yaml
117+ apiVersion: meta.gotemplating.fn.crossplane.io/v1alpha1
118+ kind: ExtraResources
119+ requirements:
120+ some-foo-by-name:
121+ # Resources can be requested either by name
122+ apiVersion: example.com/v1beta1
123+ kind: Foo
124+ matchName: "some-extra-foo"
125+ some-foo-by-labels:
126+ # Or by label.
127+ apiVersion: example.com/v1beta1
128+ kind: Foo
129+ matchLabels:
130+ app: my-app
131+ some-bar-by-a-computed-label:
132+ # But you can also generate them dynamically using the template, for example:
133+ apiVersion: example.com/v1beta1
134+ kind: Bar
135+ matchLabels:
136+ foo: {{ .observed.composite.resource.name }}
137+ ` ` `
138+
139+ This will result in Crossplane retrieving the requested resources and making
140+ them available to your templates under the `extraResources` key, with the
141+ following format :
142+
143+ ` ` ` json5
144+ {
145+ "extraResources": {
146+ "some-foo-by-name": [
147+ // ... the requested bucket if found, empty otherwise ...
148+ ],
149+ "some-foo-by-labels": [
150+ // ... the requested buckets if found, empty otherwise ...
151+ ],
152+ // ... any other requested extra resources ...
153+ }
154+ }
155+ ` ` `
156+
157+ So, you can access the retrieved resources in your templates like this, for
158+ example :
159+
160+ ` ` ` yaml
161+ {{ someExtraResources := index .extraResources "some-extra-resources-key" }}
162+ {{- range $i, $extraResource := $someExtraResources }}
163+ #
164+ # Do something for each retrieved extraResource
165+ #
166+ {{- end }}
167+ ` ` `
168+
109169# # Additional functions
110170
111171| Name | Description |
@@ -147,3 +207,4 @@ $ crossplane xpkg build -f package --embed-runtime-image=runtime
147207[go] : https://go.dev
148208[docker] : https://www.docker.com
149209[cli] : https://docs.crossplane.io/latest/cli
210+ [extra-resources] : https://docs.crossplane.io/latest/concepts/composition-functions/#how-composition-functions-work
0 commit comments