crossplane-contrib / function-patch-and-transform

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

MergeObject does not honour the same behaviour as Native P&T #99

Closed fernandezcuesta closed 6 months ago

fernandezcuesta commented 6 months ago

When using a patch such as:

        - type: FromCompositeFieldPath
          fromFieldPath: spec.parameters.tags
          toFieldPath: spec.forProvider.tags
          policy:
            toFieldPath: MergeObject

on a resource that looks like:

      - name: public-subnet
        base:
          apiVersion: ec2.aws.upbound.io/v1beta1
          kind: Subnet
          metadata:
            labels:
              type: subnet
            name: # patched
          spec:
            forProvider:
              availabilityZone: # patched
              cidrBlock: # patched
              mapPublicIpOnLaunch: false
              tags:
                kubernetes.io/role/elb: "1"

I expected this to merge the existing tag (kubernetes.io/role/elb: "1") to be merged with the object on spec.parameters.tags. However, this is not being the case and that static tag is simply lost.

This behaves differently when compared to Native P&T and:

    policy:
      mergeOptions:
        keepMapValues: true
negz commented 6 months ago

@fernandezcuesta What version of the function are you running? v0.3.0?

https://github.com/crossplane-contrib/function-patch-and-transform/pull/91 implements policy.toFieldPath. It's not yet in a released version of the function. It's possible that:

  1. You're running a version of the function that doesn't support this new setting
  2. The function silently accepts the unsupported options (see https://github.com/crossplane-contrib/function-patch-and-transform/pull/91#issuecomment-1942672309)

I can cut a release today that includes both fixes.

fernandezcuesta commented 6 months ago

Hi! Yeah my bad, didn't realize it wasn't released yet. I'm using 0.3.0. Eager to validate the fixes in case you have time to release a new version.

negz commented 6 months ago

@fernandezcuesta Please give https://github.com/crossplane-contrib/function-patch-and-transform/releases/tag/v0.4.0 a try! https://marketplace.upbound.io/functions/crossplane-contrib/function-patch-and-transform/v0.4.0.

fernandezcuesta commented 6 months ago

superb! working like a charm! Thanks a lot!