Skip to content

Commit

Permalink
feat: optional environment label selector fieldpath
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Scorsolini <p.scorsolini@gmail.com>
  • Loading branch information
phisco committed Sep 5, 2023
1 parent 480b7e9 commit fbdd605
Showing 1 changed file with 63 additions and 3 deletions.
66 changes: 63 additions & 3 deletions content/master/concepts/environment-configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,76 @@ spec:
- type: Selector
selector:
matchLabels:
- key: my-label-key
- key: my-first-label-key
type: Value
value: my-label-value
- key: my-label-key
value: my-first-label-value
- key: my-second-label-key
type: FromCompositeFieldPath
valueFromFieldPath: spec.parameters.deploy
resources:
# Removed for brevity
```

By default, Crossplane errors out if a
{{<hover label="byLabel" line="16">}}valueFromFieldPath{{</hover>}}
field doesn't exist in the composite resource at runtime. You can change this
behavior by setting the
{{<hover label="byLabelOptional" line="17">}}fromFieldPathPolicy{{</hover>}}
field to `Optional`, ignoring the label altogether, if not found.

```yaml {label="byLabelOptional",copy-lines="all"}
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: example-composition
spec:
environment:
environmentConfigs:
- type: Selector
selector:
matchLabels:
- key: my-first-label-key
type: Value
value: my-first-label-value
- key: my-second-label-key
type: FromCompositeFieldPath
valueFromFieldPath: spec.parameters.deploy
fromFieldPathPolicy: Optional
resources:
# Removed for brevity
```

Crossplane evaluates label selectors in order, so if a label set as optional
isn't found, but if you already defined an explicit value for it, it uses that
{{<hover label="byLabelOptionalDefault" line="16">}}default value{{</hover>}}
instead.

```yaml {label="byLabelOptionalDefault",copy-lines="all"}
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: example-composition
spec:
environment:
environmentConfigs:
- type: Selector
selector:
matchLabels:
- key: my-first-label-key
type: Value
value: my-label-value
- key: my-second-label-key
type: Value
value: my-default-value
- key: my-second-label-key
type: FromCompositeFieldPath
valueFromFieldPath: spec.parameters.deploy
fromFieldPathPolicy: Optional
resources:
# Removed for brevity
```


#### Manage selector results

Selecting environments by labels may return more than one environment.
Expand Down

0 comments on commit fbdd605

Please sign in to comment.