Closed humoflife closed 2 months ago
something like this is working:
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: table.dynamodb.aws.platform.upbound.io
labels:
provider: aws
spec:
compositeTypeRef:
apiVersion: dynamodb.aws.platform.upbound.io/v1alpha1
kind: XTable
mode: Pipeline
pipeline:
- step: go-templating
functionRef:
name: function-go-templating
input:
apiVersion: gotemplating.fn.crossplane.io/v1beta1
kind: GoTemplate
source: Inline
inline:
template: |
{{ $spec := .observed.composite.resource.spec }}
---
apiVersion: dynamodb.aws.upbound.io/v1beta1
kind: Table
metadata:
annotations:
{{ setResourceNameAnnotation (print "table") }}
spec:
forProvider:
array:
{{- range $i, $array := $spec.parameters.array }}
- name: {{ $array.name }}
type: {{ $array.type }}
{{- end }}
- step: automatically-detect-ready-composed-resources
functionRef:
name: crossplane-contrib-function-auto-ready
It should also work using toYAML
The above decoding behavior is by design. To use function-go-templating to perform the array assignment, one can use the following syntax.
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: table.dynamodb.aws.platform.upbound.io
labels:
provider: aws
spec:
compositeTypeRef:
apiVersion: dynamodb.aws.platform.upbound.io/v1alpha1
kind: XTable
mode: Pipeline
pipeline:
- step: go-templating
functionRef:
name: function-go-templating
input:
apiVersion: gotemplating.fn.crossplane.io/v1beta1
kind: GoTemplate
source: Inline
inline:
template: |
{{ $spec := .observed.composite.resource.spec }}
---
apiVersion: dynamodb.aws.upbound.io/v1beta1
kind: Table
metadata:
annotations:
{{ setResourceNameAnnotation (print "table") }}
spec:
forProvider:
array:
{{- range $i, $array := $spec.parameters.array }}
- name: {{ $array.name }}
{{- if $array.type }}
type: {{ $array.type }}
{{- end }}
{{- end }}
For future reference, somthing like https://github.com/crossplane-contrib/function-go-templating/blob/82dc60773ec3ca1fb870ae0eb9f61310dd813639/example/functions/toYaml/composition.yaml#L25C1-L25C100 should also work
What happened?
Receiving the following
crossplane beta render error
:XR:
function-go-templating debug output:
Composition is as follows. Note that the issue has nothing to do with the Kind and api version but was first noticed through a DynamoDB table with an attribute and a globalSecondaryIndex that neither were properly decoded from YAML to JSON by function-go-templating:
How can we reproduce it?
crossplane beta render xr.yaml composition.yaml function.yaml
The function.yaml is as follows:
What environment did it happen in?
Function version: v0.4.1
kubectl version
): v1.29.1uname -a
): Darwin Kernel Version 22.6.0