You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# users can specify CEL expressions to determine when a resource should be included in the graph
198
+
- ${schema.spec.value.enabled}
195
199
```
196
200
197
-
Using `externalRef` An user can specify if the object is something that is created out-of-band and needs to be referenced in the RGD.
201
+
### Using `externalRef` to reference Objects outside the ResourceGraphDefinition.
202
+
203
+
Users can specify if the object is something that is created out-of-band and needs to be referenced in the RGD.
198
204
An external reference could be specified like this:
199
205
```
200
206
resources:
@@ -209,7 +215,52 @@ resources:
209
215
210
216
As part of processing the Resource Graph, the instance reconciler waits for the `externalRef` object to be present and reads the object from the cluster as a node in the graph. Subsequent resources can use data from this node.
211
217
212
-
## ResourceGraphDefinition Status Reporting
218
+
219
+
### Using Conditional CEL Expressions (`?`)
220
+
221
+
KRO can make use of CEL Expressions (see [this proposal for details](https://github.com/google/cel-spec/wiki/proposal-246) or look at the [CEL Implementation Reference](https://pkg.go.dev/github.com/google/cel-go/cel#hdr-Syntax_Changes-OptionalTypes)) to define optional runtime conditions for resources based on the conditional operator `?`.
222
+
223
+
This allows you to optionally define values that have no predefined schema or are not hard dependencies in the Graph.
224
+
225
+
#### Using `?` for referencing schema-less objects like `ConfigMap` or `Secret`
226
+
227
+
You can use the `optional` operator to reference objects that do not have a predefined schema in the ResourceGraphDefinition. This is useful for referencing objects that may or may not exist at runtime.
228
+
229
+
> :warning: `?` removes the ability of KRO to introspect the schema of the referenced object. Thus, it cannot wait for fields after the `?` to be present. It is recommended to use conditional expressions only for objects that are not critical to the ResourceGraphDefinition's operation or when the schema cannot be known at design time.
230
+
231
+
A config map can be referenced like this:
232
+
233
+
```yaml title="config-map.yaml"
234
+
apiVersion: v1
235
+
kind: ConfigMap
236
+
metadata:
237
+
name: demo
238
+
data:
239
+
VALUE: "foobar"
240
+
```
241
+
242
+
```yaml title="external reference in ResourceGraphDefinition"
243
+
- id: external
244
+
externalRef:
245
+
apiVersion: v1
246
+
kind: ConfigMap
247
+
metadata:
248
+
name: demo
249
+
namespace: default
250
+
```
251
+
252
+
With this reference, you can access the data in your schema:
253
+
254
+
```text title="CEL Expression"
255
+
${external.data.?VALUE}
256
+
```
257
+
258
+
> :warning: KRO will only wait for the external reference to be present in the cluster, but it will not validate the schema of the referenced config. If the config map does not have the `VALUE` field, the expression will evaluate to `null` and might result in unexpected behavior in your application if not handled properly.
259
+
260
+
261
+
_For a more detailed example, see the [Optional Values & External References](../../examples/basic/optionals.md) documentation._
262
+
263
+
## Status Reporting
213
264
214
265
The `status` section of a `ResourceGraphDefinition` provides information about the state of the graph and it's generated `CustomResourceDefinition` and controller.
0 commit comments