crossplane-contrib / provider-upjet-aws

Official AWS Provider for Crossplane by Upbound.
https://marketplace.upbound.io/providers/upbound/provider-aws
Apache License 2.0
137 stars 112 forks source link

[Bug]: PnT Match transform not working as expected #1298

Closed linusyong closed 1 month ago

linusyong commented 1 month ago

Is there an existing issue for this?

Affected Resource(s)

Resource MRs required to reproduce the bug

Steps to Reproduce

  1. Apply the XRD and Composition:
    $ kubectl apply -f xrd.yaml
    $ kubectl apply -f compisiton.yaml
  2. Apply the xPolicyTest:
    $ kubectl apply -f xpolicytest.yaml
  3. Check the Policy created:
    $ kubectl describe policies linus-cluster-xplane-karpenter-policy
    Name:         linus-cluster-xplane-karpenter-policy
    Namespace:    
    Labels:       crossplane.io/claim-name=
                  crossplane.io/claim-namespace=
                  crossplane.io/composite=linus-cluster
    Annotations:  crossplane.io/composition-resource-name: xplane-karpenter-policy
                  crossplane.io/external-create-failed: 2024-05-06T10:57:16Z
                  crossplane.io/external-create-pending: 2024-05-06T10:57:16Z
                  crossplane.io/external-create-succeeded: 2024-05-06T10:56:31Z
                  crossplane.io/external-name: linus-cluster-xplane-karpenter-policy
                  myAnnotation: StringNotFound

What happened?

It is expected that

    - type: FromCompositeFieldPath
      fromFieldPath: spec.name
      toFieldPath: metadata.annotations["myAnnotation"]
      transforms:
      - type: match
        match:
          patterns:
          - type: literal
            literal: "field1-text"
            result: "matchedLiteral"
          fallbackTo: Value
          fallbackValue: "StringNotFound"

should match "field1-text" and replace with "matchedLiteral". However a match wasn't found and replaced with the fallbackValue of "StringNotFound"

Relevant Error Output Snippet

No response

Crossplane Version

1.15.2

Provider Version

1.4.0

Kubernetes Version

Client Version: v1.28.0 Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 Server Version: v1.29.3-eks-adc711

Kubernetes Distribution

EKS

Additional Info

No response

phisco commented 1 month ago

Your Composite Resource xPolicyTest has spec.name set to linus-cluster, your patch is patching from that to the Composed Resource's metadata.annotations["myAnnotation"]. So given that linus-cluster != field1-text, the patch defaults to the configured fallback value, StringNotFound. Looks correct to me.

linusyong commented 1 month ago

Thanks @phisco, you're right. Looks like is my understanding of match transformation is wrong. Thanks again, will close this.