Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sprig templating capability to transforms and CombineFromComposite #63

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions example/composition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,60 @@ spec:
region: us-east-2
patches:
- type: FromCompositeFieldPath
fromFieldPath: "location"
fromFieldPath: "spec.location"
toFieldPath: "spec.forProvider.region"
transforms:
- type: map
map:
EU: "eu-north-1"
US: "us-east-2"
US: "us-east-2"

- name: bucket-policy
base:
apiVersion: s3.aws.upbound.io/v1beta1
kind: BucketPolicy
spec:
forProvider:
region: us-east-2
bucketSelector:
matchControllerRef: true
patches:
- type: FromCompositeFieldPath
fromFieldPath: "spec.location"
toFieldPath: "metadata.labels.location"
transforms:
- type: string
string:
type: Template
template: '{{ . | lower }}'
- type: CombineFromComposite
toFieldPath: "spec.forProvider.policy"
combine:
strategy: template
variables:
- fromFieldPath: spec.writeAccessPrincipalArns
variableName: writeAccessPrincipalArns
- fromFieldPath: spec.readAccessPrincipalArns
template:
template: |
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"PolicyForAllowUploadWithACL",
"Effect":"Allow",
"Principal":{"AWS": {{ .writeAccessPrincipalArns | toJson }} },
"Action":"s3:PutObject",
"Resource":"arn:aws:s3:::DOC-EXAMPLE-BUCKET/*",
"Condition": {
"StringEquals": {"s3:x-amz-acl":"bucket-owner-full-control"}
},
{
"Sid":"PolicyForAllowedRead",
"Effect":"Allow",
"Principal":{"AWS": {{ index . "1" | toJson }} },
"Action":"s3:GetObject",
"Resource":"*",
}
]
}
4 changes: 2 additions & 2 deletions example/functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ 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.1.4
annotations:
render.crossplane.io/runtime: Development
6 changes: 6 additions & 0 deletions example/xr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ metadata:
name: example-xr
spec:
location: US
writeAccessPrincipalArns:
- "111122223333"
- "444455556666"
readAccessPrincipalArns:
- "123456789012"
- "987654321098"
15 changes: 15 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21
toolchain go1.21.3

require (
github.com/Masterminds/sprig/v3 v3.2.3
github.com/alecthomas/kong v0.8.1
github.com/crossplane/crossplane-runtime v1.14.3
github.com/crossplane/function-sdk-go v0.1.0
Expand All @@ -20,6 +21,10 @@ require (

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand All @@ -40,26 +45,36 @@ require (
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/labstack/gommon v0.4.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
Expand Down
Loading
Loading