Skip to content

Commit

Permalink
Merge pull request #7 from phisco/main
Browse files Browse the repository at this point in the history
docs(README): add p&t example and diagram
  • Loading branch information
phisco authored Feb 15, 2024
2 parents 095ede3 + c41f850 commit 8631fa5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ input of this function:
`spec.environment.policy.resolve` is not supported yet, which results
effectively in the same behavior as `Always`.

Here's an example:
Here's an example using [function-go-templating](https://github.com/crossplane-contrib/function-go-templating):

```yaml
apiVersion: apiextensions.crossplane.io/v1
Expand Down Expand Up @@ -62,6 +62,54 @@ spec:
fromEnv: {{ index .context "apiextensions.crossplane.io/environment" "complex" "c" "d" }}
```
Here is another example using [function-patch-and-transform](https://github.com/crossplane-contrib/function-patch-and-transform):
```yaml
... same as above ...
- step: patch-and-transform
# function-patch-and-transform knows it has to look for the environment in the
# context at "apiextensions.crossplane.io/environment"
functionRef:
name: function-patch-and-transform
input:
apiVersion: pt.fn.crossplane.io/v1beta1
kind: Resources
environment:
patches:
# So you can then use it in all your patches:
# - Env -> XR
- type: ToCompositeFieldPath
fromFieldPath: "someFieldInTheEnvironment"
toFieldPath: "status.someFieldFromTheEnvironment"
# - XR -> Env
- type: FromCompositeFieldPath
fromFieldPath: "spec.someFieldInTheXR"
toFieldPath: "someFieldFromTheXR"
resources:
- name: bucket
base:
apiVersion: s3.aws.upbound.io/v1beta1
kind: Bucket
spec:
forProvider:
region: us-east-2
patches:
# - Env -> Resource
- type: FromEnvironmentFieldPath
fromFieldPath: "someFieldInTheEnvironment"
toFieldPath: "spec.forProvider.someFieldFromTheEnvironment"
# - Resource -> Env
- type: ToEnvironmentFieldPath
fromFieldPath: "status.someOtherFieldInTheResource"
toFieldPath: "someOtherFieldInTheEnvironment"
# the environment will be passed to the next function in the pipeline
# as part of the context
```

This diagram shows what part of the usual Composition is replaced by this
function and how it fits with other functions:
![diagram.png](diagram.png)

## Using this function

See the [example](example) directory for examples that you can run locally using
Expand Down
Binary file added diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8631fa5

Please sign in to comment.