crossplane-contrib / function-patch-and-transform

A patch & transform composition function
https://crossplane.io
Apache License 2.0
23 stars 24 forks source link

keepMapValues policy option doesn't keep existing values. #90

Closed driosalido closed 6 months ago

driosalido commented 7 months ago

Composition migrated through the crossplane-migrator . The original composition works.

...
        resources:
          - name: cluster-addons
            base:
              apiVersion: intenthq.com/v1alpha1
              kind: XClusterAddon
              spec:
                compositionSelector:
                  matchLabels:
                    xclusteraddons.intenthq.com/type: main
                deletionPolicy: Delete
                parameters:
                  main:
                    helm:
                      values:
                        crossplane:
                          enabled: true
            patches:
              - type: FromCompositeFieldPath
                fromFieldPath: spec.parameters.clusterAddons.values
                toFieldPath: spec.parameters.main.helm.values
                policy:
                  mergeOptions:
                    keepMapValues: true

and resource with

spec:
  parameters:
    clusterAddons:
      values:
        crossplane:
          helm:
            chart:
              version: 1.14.5

it's rendered as

apiVersion: intenthq.com/v1alpha1
kind: XClusterAddon
...
spec:
  parameters:
    main:
      helm:
        values:
          crossplane:
            helm:
              chart:
                version: 1.14.5

missing the default values created in the composition

driosalido commented 7 months ago

Using

apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
  name: crossplane-contrib-function-patch-and-transform
spec:
  package: xpkg.upbound.io/crossplane-contrib/function-patch-and-transform:v0.3.0
phisco commented 7 months ago

You are right, merge options are not actually available in this function's input, but your scenario is totally valid.