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

keepMapValues: true merge option is not considered with CombineFromComposite patch when transforming json string to object #5572

Open
fcke opened this issue Apr 11, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@fcke
Copy link

fcke commented Apr 11, 2024

Problem statement

The keepMapValues: true merge option does not have effect when it is used in a CombineFromComposite patch along with the transforms operation.

What happened?

I have the following patch:

   - type: CombineFromComposite
     combine:
       strategy: string
       string:
         fmt: '{"%s-%s":{"url":"http://%s.4.48:8080","tls":"DISABLE","tlsSecret":null,"protocol":"h2c"}}'
       variables:
         - fromFieldPath: spec.parameters.valueString1
         - fromFieldPath: spec.parameters.valueString2
         - fromFieldPath: spec.parameters.baseCidrOctets
     toFieldPath: spec.forProvider.manifest.spec.values.chartValues.global.externalServices
     policy:
       mergeOptions:
         keepMapValues: true
     transforms:
     - type: convert
       convert:
         toType: object
         format: json 

The patch works fine when I do not have anything under spec.forProvider.manifest.spec.values.chartValues.global.externalServices. However, when there is already an existing sub-tree, it is overwritten with the newly created json-transformed-to-object value despite of the keepMapValues: true merge option.

Resource, before patch:

  externalServices:
     zService:
       ip: zservice.svc.cluster.local
       ports:
         cm: 8080
         fm_alarm: 8079
         fm_log: 8078
         pm: 8079

After patch:

  externalServices:
     valueString1-valueString2:
       ip: 1.2.4.48:8080
       tls: DISABLE
       tlsSecret: null
       protocol: h2c

However, when I have two separate patch, one for the combine and another one for the transform, the keepMapValues: true has the expected effect and the newly created object is merged.
So, when I have the following patch added to another resource, just to create the proper string which I can use in the original resource for patching (really ugly, but do not know any better way currently...):

  - type: CombineFromComposite
    combine:
      strategy: string
      string:
        fmt: '{"%s-%s":{"url":"http://%s.4.48:8080","tls":"DISABLE","tlsSecret":null,"protocol":"h2c"}}'
      variables:
         - fromFieldPath: spec.parameters.valueString1
         - fromFieldPath: spec.parameters.valueString2
         - fromFieldPath: spec.parameters.baseCidrOctets
    toFieldPath: metadata.annotations.externalServiceNew
  - type: ToCompositeFieldPath
    fromFieldPath: metadata.annotations.externalServiceNew
    toFieldPath: metadata.annotations.externalServiceNew

And I use the transform to patch the target resource (note: fromFieldPath: Required is there to prevent creation of the resource before the formatted string is available as I need the changes to the externalServices when this resource is created):

  - type: FromCompositeFieldPath
    fromFieldPath: metadata.annotations.externalServiceNrf
    toFieldPath: spec.forProvider.manifest.spec.values.chartValues.global.externalServices
    policy:
      fromFieldPath: Required
      mergeOptions:
        keepMapValues: true
    transforms:
    - type: convert
      convert:
        toType: object
        format: json

Everything works flawlessly.

Example:
Resource, before patch:

  externalServices:
    zService:
      ip: zservice.svc.cluster.local
        ports:
          cm: 8080
          fm_alarm: 8079
          fm_log: 8078
          pm: 8079

After patch:

  externalServices:
     valueString1-valueString2:
       ip: 1.2.4.48:8080
       tls: DISABLE
       tlsSecret: null
       protocol: h2c
     zService:
       ip: zservice.svc.cluster.local
       ports:
         cm: 8080
         fm_alarm: 8079
         fm_log: 8078
         pm: 8079

What environment did it happen in?

Crossplane version: 1.15.0
Cloud provider: AWS EKS
Kuberetes: 1.29

@fcke fcke added the bug Something isn't working label Apr 11, 2024
@fcke
Copy link
Author

fcke commented Apr 26, 2024

ping :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant