generated from crossplane/function-template-go
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper functions for retrieving composed and composite resources
- Loading branch information
Showing
13 changed files
with
346 additions
and
11 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 |
---|---|---|
|
@@ -21,4 +21,8 @@ | |
go.work | ||
|
||
# Binaries | ||
function-go-templating | ||
function-go-templating | ||
|
||
# IDE | ||
.idea | ||
.idea/** |
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,16 @@ | ||
# getComposedResource | ||
The getComposedResource function is a utility function used to facilitate the retrieval of composed resources within templated configurations, specifically targeting observed resources. By accepting a function request map and a resource name, it navigates the complex structure of a request to fetch the specified composed resource, making it easier and more user-friendly to access nested data. If the resource is found, it returns a map containing the resource's manifest; if not, it returns nil, indicating the resource does not exist or is inaccessible through the given path. | ||
## Usage | ||
|
||
|
||
Examples: | ||
|
||
```golang | ||
// Retrieve the observed resource named "flexServer" from the function request | ||
{{ flexServer := getComposedResource . "flexServer" }} | ||
|
||
// Extract values from the observed resource | ||
{{ $flexServerID := get $flexServer.status.atProvider "id" }} | ||
|
||
|
||
``` |
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,49 @@ | ||
apiVersion: apiextensions.crossplane.io/v1 | ||
kind: Composition | ||
metadata: | ||
name: example-function-get-composed-resource | ||
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: | | ||
--- | ||
# Create an initial composed resource for which we will retrieve a value | ||
apiVersion: dbforpostgresql.azure.upbound.io/v1beta1 | ||
kind: FlexibleServer | ||
metadata: | ||
annotations: | ||
{{ setResourceNameAnnotation "flexserver" }} | ||
gotemplating.fn.crossplane.io/ready: "False" | ||
spec: | ||
forProvider: | ||
storageMb: 32768 | ||
providerConfigRef: | ||
name: my-provider-cfg | ||
--- | ||
# Use getComposedResource to retrieve the observed resource named "flexServer" | ||
{{ $flexServer := getComposedResource . "flexServer" }} | ||
apiVersion: dbforpostgresql.azure.upbound.io/v1beta1 | ||
kind: FlexibleServerConfiguration | ||
metadata: | ||
annotations: | ||
{{ setResourceNameAnnotation "flexServerConfig" }} | ||
gotemplating.fn.crossplane.io/ready: "False" | ||
spec: | ||
forProvider: | ||
# Populate the field using the observed status of the retrieved resource | ||
serverId: {{ get $flexServer.status "id" }} | ||
providerConfigRef: | ||
name: my-provider-cfg |
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: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,20 @@ | ||
apiVersion: dbforpostgresql.azure.upbound.io/v1beta1 | ||
kind: FlexibleServer | ||
metadata: | ||
annotations: | ||
crossplane.io/composition-resource-name: flexServer | ||
labels: | ||
crossplane.io/composite: example | ||
spec: | ||
forProvider: | ||
storageMb: 32768 | ||
providerConfigRef: | ||
name: my-provider-cfg | ||
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,6 @@ | ||
apiVersion: example.crossplane.io/v1beta1 | ||
kind: XR | ||
metadata: | ||
name: example | ||
spec: {} | ||
|
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,30 @@ | ||
# getCompositeResource | ||
The getCompositeResource function is a utility function used to facilitate the retrieval of a composite resources (XR) within templated configurations. Upon successful retrieval, the function returns a map containing the observed composite resource's manifest. If the resource cannot be located or is unreachable, it returns nil, indicating the absence or inaccessibility of the composite resource. | ||
## Usage | ||
|
||
|
||
Examples: | ||
Given the following XR spec | ||
```yaml | ||
apiVersion: example.crossplane.io/v1beta1 | ||
kind: XR | ||
metadata: | ||
name: example | ||
spec: | ||
name: "example" | ||
location: "eastus" | ||
|
||
``` | ||
```golang | ||
// Retrieve the observed composite resource (XR) from the function request | ||
{{ $xr := getCompositeResource . }} | ||
|
||
apiVersion: example.crossplane.io/v1beta1 | ||
kind: ExampleResource | ||
// 'Patch' values from the composite resource into the composed resource | ||
spec: | ||
forProvider: | ||
name: {{ get $xr.spec "name" }} | ||
location: {{ get $xr.spec "location" }} | ||
|
||
``` |
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,35 @@ | ||
apiVersion: apiextensions.crossplane.io/v1 | ||
kind: Composition | ||
metadata: | ||
name: example-function-get-composite-resource | ||
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: | | ||
--- | ||
# Use a getCompositeResource to retrieve the XR | ||
{{ $xr := getCompositeResource . }} | ||
apiVersion: dbforpostgresql.azure.upbound.io/v1beta1 | ||
kind: FlexibleServer | ||
metadata: | ||
annotations: | ||
{{ setResourceNameAnnotation "flexserver" }} | ||
gotemplating.fn.crossplane.io/ready: "False" | ||
spec: | ||
forProvider: | ||
# Use the XR object to set values | ||
adminLogin: {{ get $xr.spec "adminLogin" }} | ||
location: {{ get $xr.spec "location" }} |
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: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,7 @@ | ||
apiVersion: example.crossplane.io/v1beta1 | ||
kind: XR | ||
metadata: | ||
name: example | ||
spec: | ||
adminLogin: "admin" | ||
location: "eastus" |
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
Oops, something went wrong.