-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from ytsarev/multistep
Provider multistep pipeline example mixing P&T and Go Templating
- Loading branch information
Showing
6 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
render: | ||
crossplane beta render xr.yaml composition.yaml functions.yaml -r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Example multistep pipeline | ||
|
||
Example Functions Pipeline with the 3 steps: | ||
|
||
|
||
1. function-patch-and-transform | ||
2. function-go-templating | ||
3. function-patch-and-transform again | ||
|
||
The more details mechanics of each step described below | ||
|
||
1. function-patch-and-transform creates `bucket` | ||
2. function-go-templating creates `bucketACL` and uses the data from the | ||
previous pipelines step to compose the resource spec | ||
``` | ||
region: {{ .desired.resources.bucket.resource.spec.forProvider.region }} | ||
``` | ||
3. function-patch-and-transform is used again to patch the `bucketACL` with the | ||
data from XR spec. Notice that `base` is omitted and resource `name` is | ||
matching the one that is set by the function-go-templating with `{{ setResourceNameAnnotation "bucketACL" }}` | ||
|
||
To render `make render` target is available: | ||
|
||
``` | ||
crossplane beta render xr.yaml composition.yaml functions.yaml -r | ||
--- | ||
apiVersion: example.crossplane.io/v1 | ||
kind: XR | ||
metadata: | ||
name: example-xr | ||
status: | ||
conditions: | ||
- lastTransitionTime: "2024-01-01T00:00:00Z" | ||
message: 'Unready resources: bucket, bucketACL' | ||
reason: Creating | ||
status: "False" | ||
type: Ready | ||
--- | ||
apiVersion: s3.aws.upbound.io/v1beta1 | ||
kind: Bucket | ||
metadata: | ||
annotations: | ||
crossplane.io/composition-resource-name: bucket | ||
generateName: example-xr- | ||
labels: | ||
crossplane.io/composite: example-xr | ||
ownerReferences: | ||
- apiVersion: example.crossplane.io/v1 | ||
blockOwnerDeletion: true | ||
controller: true | ||
kind: XR | ||
name: example-xr | ||
uid: "" | ||
spec: | ||
forProvider: | ||
region: eu-north-1 | ||
--- | ||
apiVersion: s3.aws.upbound.io/v1beta1 | ||
kind: BucketACL | ||
metadata: | ||
annotations: | ||
crossplane.io/composition-resource-name: bucketACL | ||
generateName: example-xr- | ||
labels: | ||
crossplane.io/composite: example-xr | ||
ownerReferences: | ||
- apiVersion: example.crossplane.io/v1 | ||
blockOwnerDeletion: true | ||
controller: true | ||
kind: XR | ||
name: example-xr | ||
uid: "" | ||
spec: | ||
forProvider: | ||
acl: private | ||
bucketSelector: | ||
matchControllerRef: true | ||
region: eu-north-1 | ||
``` | ||
|
||
Notice that `BucketACL` is patched as expected | ||
|
||
``` | ||
spec: | ||
forProvider: | ||
acl: private # acl value that is set on 3rd pipeline step is in place | ||
bucketSelector: | ||
matchControllerRef: true | ||
region: eu-north-1 # region value that is set on 2nd pipeline step is in place | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
apiVersion: apiextensions.crossplane.io/v1 | ||
kind: Composition | ||
metadata: | ||
name: function-patch-and-transform | ||
spec: | ||
compositeTypeRef: | ||
apiVersion: example.crossplane.io/v1 | ||
kind: XR | ||
mode: Pipeline | ||
pipeline: | ||
- step: patch-and-transform | ||
functionRef: | ||
name: function-patch-and-transform | ||
input: | ||
apiVersion: pt.fn.crossplane.io/v1beta1 | ||
kind: Resources | ||
resources: | ||
- name: bucket | ||
base: | ||
apiVersion: s3.aws.upbound.io/v1beta1 | ||
kind: Bucket | ||
patches: | ||
- type: FromCompositeFieldPath | ||
fromFieldPath: "spec.location" | ||
toFieldPath: "spec.forProvider.region" | ||
transforms: | ||
- type: map | ||
map: | ||
EU: "eu-north-1" | ||
US: "us-east-2" | ||
|
||
- step: render-templates | ||
functionRef: | ||
name: function-go-templating | ||
input: | ||
apiVersion: gotemplating.fn.crossplane.io/v1beta1 | ||
kind: GoTemplate | ||
source: Inline | ||
inline: | ||
template: | | ||
--- | ||
apiVersion: s3.aws.upbound.io/v1beta1 | ||
kind: BucketACL | ||
metadata: | ||
annotations: | ||
{{ setResourceNameAnnotation "bucketACL" }} | ||
spec: | ||
forProvider: | ||
bucketSelector: | ||
matchControllerRef: true | ||
region: {{ .desired.resources.bucket.resource.spec.forProvider.region }} | ||
- step: patch-and-transform-again | ||
functionRef: | ||
name: function-patch-and-transform | ||
input: | ||
apiVersion: pt.fn.crossplane.io/v1beta1 | ||
kind: Resources | ||
resources: | ||
- name: bucketACL # resource name matches the one from function-go-templating setResourceNameAnnotation above, no `base` specified | ||
patches: | ||
- type: FromCompositeFieldPath | ||
fromFieldPath: "spec.acl" | ||
toFieldPath: "spec.forProvider.acl" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
apiVersion: pkg.crossplane.io/v1beta1 | ||
kind: Function | ||
metadata: | ||
name: function-patch-and-transform | ||
spec: | ||
package: xpkg.upbound.io/crossplane-contrib/function-patch-and-transform:v0.5.0 | ||
--- | ||
apiVersion: pkg.crossplane.io/v1beta1 | ||
kind: Function | ||
metadata: | ||
name: function-go-templating | ||
spec: | ||
package: xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.4.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Replace this with your XR! | ||
apiVersion: example.crossplane.io/v1 | ||
kind: XR | ||
metadata: | ||
name: example-xr | ||
spec: | ||
location: EU | ||
acl: private |