generated from crossplane/function-template-go
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into custom-template-delims
- Loading branch information
Showing
19 changed files
with
434 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,6 @@ | |
|
||
# Go workspace file | ||
go.work | ||
|
||
# Binaries | ||
function-go-templating |
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,13 @@ | ||
--- | ||
# Use this function yaml when developing and executing the function directly instead of in a container | ||
# E.g. `go run . --insecure --debug --address=":9443"` | ||
|
||
apiVersion: pkg.crossplane.io/v1beta1 | ||
kind: Function | ||
metadata: | ||
name: function-go-templating | ||
annotations: | ||
render.crossplane.io/runtime: Development | ||
render.crossplane.io/runtime-development-target: localhost:9443 | ||
spec: | ||
package: xpkg.upbound.io/crossplane-contrib/function-go-templating:latest # ignored |
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,25 @@ | ||
apiVersion: apiextensions.crossplane.io/v1 | ||
kind: Composition | ||
metadata: | ||
name: example-function-from-yaml | ||
spec: | ||
compositeTypeRef: | ||
apiVersion: example.crossplane.io/v1beta1 | ||
kind: XR | ||
mode: Pipeline | ||
pipeline: | ||
- step: render-templates | ||
functionRef: | ||
name: function-go-templating | ||
input: | ||
apiVersion: gotemplating.fn.crossplane.io/v1beta1 | ||
kind: GoTemplate | ||
source: Inline | ||
inline: | ||
template: | | ||
--- | ||
apiVersion: {{ .observed.composite.resource.apiVersion }} | ||
kind: {{ .observed.composite.resource.kind }} | ||
status: | ||
# Extract single value from encoded yaml string | ||
dummy: {{ (.observed.composite.resource.spec.yamlBlob | fromYaml).key2 }} |
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,6 @@ | ||
apiVersion: pkg.crossplane.io/v1beta1 | ||
kind: Function | ||
metadata: | ||
name: function-go-templating | ||
spec: | ||
package: xpkg.upbound.io/crossplane-contrib/function-go-templating:latest |
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,9 @@ | ||
apiVersion: example.crossplane.io/v1beta1 | ||
kind: XR | ||
metadata: | ||
name: example | ||
spec: | ||
yamlBlob: | | ||
key1: value1 | ||
key2: value2 | ||
key3: value3 |
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,44 @@ | ||
# getResourceCondition | ||
|
||
## Usage | ||
|
||
```golang | ||
{{ getResourceCondition $conditionType $resource }} | ||
{{ $resource | getResourceCondition $conditionType }} | ||
``` | ||
|
||
Examples: | ||
|
||
```golang | ||
// Print whole condition | ||
{{ .observed.resources.project | getResourceCondition "Ready" | toYaml }} | ||
|
||
// Check status | ||
{{ if eq (.observed.resources.project | getResourceCondition "Ready").Status "True" }} | ||
// do something | ||
{{ end }} | ||
``` | ||
|
||
See example composition for more usage examples | ||
|
||
## Example Outputs | ||
|
||
Requested resource does not exist or does not have the requested condition | ||
|
||
´´´yaml | ||
lasttransitiontime: "0001-01-01T00:00:00Z" | ||
message: "" | ||
reason: "" | ||
status: Unknown | ||
type: Ready | ||
´´´ | ||
|
||
Requested resource does have the requested condition | ||
|
||
´´´yaml | ||
lasttransitiontime: "2023-11-03T10:07:31+01:00" | ||
message: "custom message" | ||
reason: foo | ||
status: "True" | ||
type: Ready | ||
´´´ |
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,47 @@ | ||
apiVersion: apiextensions.crossplane.io/v1 | ||
kind: Composition | ||
metadata: | ||
name: example-function-get-resource-condition | ||
spec: | ||
compositeTypeRef: | ||
apiVersion: example.crossplane.io/v1beta1 | ||
kind: XR | ||
mode: Pipeline | ||
pipeline: | ||
- step: render-templates | ||
functionRef: | ||
name: function-go-templating | ||
input: | ||
apiVersion: gotemplating.fn.crossplane.io/v1beta1 | ||
kind: GoTemplate | ||
source: Inline | ||
inline: | ||
template: | | ||
--- | ||
apiVersion: {{ .observed.composite.resource.apiVersion }} | ||
kind: {{ .observed.composite.resource.kind }} | ||
status: | ||
# Retreive condition of XR | ||
compositeCondition: | ||
{{ getResourceCondition "Ready" .observed.composite | toYaml | nindent 4 }} | ||
# Retreive non existing condition of a resource just returns an Unknown condition | ||
compositeConditionNotFound: | ||
{{ getResourceCondition "Other" .observed.composite | toYaml | nindent 4 }} | ||
# You can also retreive conditions of composed resources the same way | ||
composedCondition: | ||
{{ getResourceCondition "Ready" .observed.resources.project | toYaml | nindent 4 }} | ||
# Use a getResourceCondition to render conditional blocks in templates | ||
{{ if eq (getResourceCondition "Ready" .observed.resources.project).Status "True" }} | ||
projectId: {{ .observed.resources.project.resource.status.atProvider.id | quote }} | ||
{{ end }} | ||
# Alternative syntax using pipelines | ||
pipeline: | ||
{{ .observed.resources.project | getResourceCondition "Ready" | toYaml | nindent 4 }} | ||
# Non object | ||
nonResource: | ||
{{ .observed.whatever | getResourceCondition "Ready" | toYaml | nindent 4 }} |
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,6 @@ | ||
apiVersion: pkg.crossplane.io/v1beta1 | ||
kind: Function | ||
metadata: | ||
name: function-go-templating | ||
spec: | ||
package: xpkg.upbound.io/crossplane-contrib/function-go-templating:latest |
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,21 @@ | ||
apiVersion: identity.openstack.upbound.io/v1alpha1 | ||
kind: ProjectV3 | ||
metadata: | ||
annotations: | ||
crossplane.io/composition-resource-name: project | ||
labels: | ||
crossplane.io/composite: myproject | ||
name: myproject | ||
spec: | ||
forProvider: | ||
name: myproject | ||
providerConfigRef: | ||
name: myprovider | ||
status: | ||
atProvider: | ||
id: abcdef | ||
conditions: | ||
- type: Ready | ||
status: "True" | ||
reason: "foo" | ||
lastTransitionTime: "2023-11-03T09:07:31Z" |
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,12 @@ | ||
apiVersion: example.crossplane.io/v1beta1 | ||
kind: XR | ||
metadata: | ||
name: example | ||
spec: | ||
key: value | ||
status: | ||
conditions: | ||
- type: Ready | ||
status: "True" | ||
reason: "xr foo" | ||
lastTransitionTime: "2023-11-03T09:07:31Z" |
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,25 @@ | ||
apiVersion: apiextensions.crossplane.io/v1 | ||
kind: Composition | ||
metadata: | ||
name: example-function-to-yaml | ||
spec: | ||
compositeTypeRef: | ||
apiVersion: example.crossplane.io/v1beta1 | ||
kind: XR | ||
mode: Pipeline | ||
pipeline: | ||
- step: render-templates | ||
functionRef: | ||
name: function-go-templating | ||
input: | ||
apiVersion: gotemplating.fn.crossplane.io/v1beta1 | ||
kind: GoTemplate | ||
source: Inline | ||
inline: | ||
template: | | ||
--- | ||
apiVersion: {{ .observed.composite.resource.apiVersion }} | ||
kind: {{ .observed.composite.resource.kind }} | ||
status: | ||
# Copy the whole 'complexDictionary' as is by fomatting it as yaml | ||
dummy: {{ .observed.composite.resource.spec.complexDictionary | toYaml | nindent 7 }} |
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,6 @@ | ||
apiVersion: pkg.crossplane.io/v1beta1 | ||
kind: Function | ||
metadata: | ||
name: function-go-templating | ||
spec: | ||
package: xpkg.upbound.io/crossplane-contrib/function-go-templating:latest |
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,12 @@ | ||
apiVersion: example.crossplane.io/v1beta1 | ||
kind: XR | ||
metadata: | ||
name: example | ||
spec: | ||
complexDictionary: | ||
scalar1: true | ||
scalar2: text | ||
scalar3: 123 | ||
list: | ||
- abc | ||
- def |
Oops, something went wrong.