crossplane-contrib / function-patch-and-transform

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

Are FromEnvironmentFieldPath and CombineFromEnvironment Supported #67

Closed davejhahn closed 10 months ago

davejhahn commented 10 months ago

I'm having a problem where it seems like it is not patching from EnvironmentConfig in function-patch-and-transform.

I have a resources pipeline that basically does the same thing and want to change to use a Pipeline so that I can do some other functions and the issues I am having indicate it is not patching.

Not sure if in the pipeline the from or to field paths need to be different, it didn't seem like it from what I was reading.

Below is basically what I have:

apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
  name: storage-pipeline
spec:
  compositeTypeRef:
    apiVersion: xxx.xxx.xxx/v1alpha1
    kind: xStorage
  mode: Pipeline
  pipeline:
  - step: create-storage
    functionRef:
      name: function-patch-and-transform
    input:
      apiVersion: pt.fn.crossplane.io/v1beta1
      kind: Resources
      resources:
      - name: storage
        base:
          apiVersion: storage.azure.upbound.io/v1beta1
          kind: Account
          metadata:
            name: storagename
        patches:
        - type: FromEnvironmentFieldPath
          fromFieldPath: "storage.accountReplicationType"
          toFieldPath: spec.forProvider.accountReplicationType
        - type: FromCompositeFieldPath
          fromFieldPath: "spec.accountReplicationType"
          toFieldPath: spec.forProvider.accountReplicationType

        - type: FromEnvironmentFieldPath
          fromFieldPath: "storage.accountTier"
          toFieldPath: spec.forProvider.accountTier
        - type: FromCompositeFieldPath
          fromFieldPath: "spec.accountTier"
          toFieldPath: spec.forProvider.accountTier

        - type: FromEnvironmentFieldPath
          fromFieldPath: "storage.accountKind"
          toFieldPath: spec.forProvider.accountKind
        - type: FromCompositeFieldPath
          fromFieldPath: "spec.accountKind"
          toFieldPath: spec.forProvider.accountKind

        - type: FromEnvironmentFieldPath
          fromFieldPath: "storage.allowNestedItemsToBePublic"
          toFieldPath: spec.forProvider.allowNestedItemsToBePublic
        - type: FromCompositeFieldPath
          fromFieldPath: "spec.allowNestedItemsToBePublic"
          toFieldPath:  spec.forProvider.allowNestedItemsToBePublic

        - type: FromEnvironmentFieldPath
          fromFieldPath: "storage.publicNetworkAccessEnabled"
          toFieldPath: spec.forProvider.publicNetworkAccessEnabled
        - type: FromCompositeFieldPath
          fromFieldPath: "spec.publicNetworkAccessEnabled"
          toFieldPath: spec.forProvider.publicNetworkAccessEnabled

        - type: FromEnvironmentFieldPath
          fromFieldPath: "location.long"
          toFieldPath: spec.forProvider.location

        - type: FromEnvironmentFieldPath
          fromFieldPath: "product.resourceGroupName"
          toFieldPath: spec.forProvider.resourceGroupName

        - type: CombineFromEnvironment
          combine:
            strategy: string
            variables:
            - fromFieldPath: "organization.identifier"
            - fromFieldPath: "subscription.identifier"
            - fromFieldPath: "environment.code"
            - fromFieldPath: "location.short"
            - fromFieldPath: "product.identifier"
            - fromFieldPath: "data.instance.identifier"
            string: 
              fmt: "%s%sst%s%s%s%s"
          toFieldPath: "metadata.annotations[crossplane.io/external-name]"

The above works fine in a composition that is Resource mode, just not in Pipeline using function-patch-and-transform.

Just trying to validate that function-patch-and-transform handles EnvironmentConfig patches and if it does, is there something just wrong with the paths that is different in function-patch-and-transform?

Thanks.

Dave

davejhahn commented 10 months ago

I think I solved my problem as I was posting this.