crossplane-contrib / crossplane-contrib/function-patch-and-transform

Patching a resource from a value obtained from function-go-templating

Open
#146 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
46
Forks
41
Avg merge
1d 10h
Merged PRs (30d)
3

Description

Hi Folks,

I want to patch a resource inside the function-patch-and-transform function using a value that I obtain from the function-go-templating.

I see the other way where we get data from the go template function into the p&t function [here](https://github.com/crossplane-contrib/function-patch-and-transform/blob/main/example/multistep/composition.yaml)

I am attaching my sample composition below.

```yaml
---
# Removed for brevity
pipeline:
- step: castai-ekscluster
functionRef:
name: function-go-templating
input:
apiVersion: gotemplating.fn.crossplane.io/v1beta1
kind: GoTemplate
source: Inline
inline:
template: |
{{- $environmentConfigs := (index .context "apiextensions.crossplane.io/environment") }}
{{- $accountIdstr := printf "%q" (index $environmentConfigs "accountId") }}
{{- $eksClusterName := printf "%q" (index $environmentConfigs "eksClusterName") }}
{{- $region := (index $environmentConfigs "region") }}
{{- $deletionPolicy := .observed.composite.resource.spec.crossplaneParameters.deletionPolicy }}
{{- $providerConfigRef := "default" }}
---
apiVersion: castai.upbound.io/v1alpha1
kind: EksClusterId
metadata:
annotations:
gotemplating.fn.crossplane.io/composition-resource-name: EksClusterId
labels:
cast-ai-cluster: {{$eksClusterName}}
spec:
deletionPolicy: {{$deletionPolicy}}
providerConfigRef:
name: {{$providerConfigRef}}
forProvider:
region: {{$region}}
accountId: {{$accountIdstr}}
clusterName: {{$eksClusterName}}


- step: aws-auth-patch
functionRef:
name: function-patch-and-transform
input:
apiVersion: pt.fn.crossplane.io/v1beta1
kind: Resources
resources:
- name: awsauthconfigmap
base:
apiVersion: v1
kind: ConfigMap
metadata:
name: ashish-test
namespace: castai-agent
patches:
- type: FromCompositeFieldPath
fromFieldPath: HERE I want the value from the function-go-templating
toFieldPath: "data.mapRoles"
transforms:
- type: string
string:
type: Format
fmt: '[{"rolearn": "%s", "username": "system:node:{{EC2PrivateDNSName}}", "groups": ["system:masters"]}]'
```

tagging @ytsarev as you might already be knowing solution.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.