crossplane-contrib / provider-kubernetes

Crossplane provider to provision and manage Kubernetes objects on (remote) Kubernetes clusters.
Apache License 2.0
143 stars 83 forks source link

Apply transformation when Patching from Resource #52

Open fabioaraujopt opened 2 years ago

fabioaraujopt commented 2 years ago

I'm trying to create a k8s secret patching from another secret.

I'm trying to achieve this by applying the following object inside of a composition:

- name: argocd-creds-secret
      base:
        apiVersion: kubernetes.crossplane.io/v1alpha1
        kind: Object
        metadata:
          name: cluster-bearer-token
        spec:
          references:
          - patchesFrom:
              apiVersion: v1
              kind: Secret
              name: connection-string
              namespace: default
              fieldPath: data.kubeconfig
            toFieldPath: data.bearer-token
            transforms:
              - type: string
                string:
                  type: Regexp
                  regexp:
                    match: '(?<=token:).*$'
          forProvider:
            manifest:
              apiVersion: v1
              kind: Secret
              metadata:
                namespace: default
              data:
                sample-key: #to be patched
          providerConfigRef:
            name: local-kubernetes-provider

It looks like it completely ignores the transformation. Is the transformation taken into account at the current implementation=

morningspace commented 2 years ago

@fabioaraujopt yes, transforms was not implemented intentionally at the beginning when patchesFrom was introduced as the more we add such at provider level, the more we see the similarity for such feature in Composition at core level. Will see if there are more such requirements from community. @turkenh ?

fabioaraujopt commented 2 years ago

Thank you for explanation @morningspace. Do you suggest any alternative to this? We are increase a lot the complexity of several compositions because of this issue.

lippertmarkus commented 1 year ago

We also have the requirement for transformations, also to e.g. combine multiple different fields into a single string in the target object

marianheinsen commented 1 year ago

We also need this, for example to add a prefix or suffix when patching a value

dariozachow commented 11 months ago

This would be a nice addition to the provider :)

maximilianbraun commented 9 months ago

Would love to see that as well.

Sometimes, you need to do some plumbing, which may not follow xp conventions and then an implemenation like this couple bridge to compositions and enable certain cases which as of today would only (in my understanding) be possible, e.g. with specific composition functions. (Getting secret data, transform it and push it into an Object)

MisterMX commented 9 months ago

Patch and Transforms can be quite complicated and are provide limitations in some cases (like lack of certain transform features). I would suggest using something more generic and more "common" in the Go and K8s ecosystem, like Go templates. Also there are composition environments in Crossplane though it is still an alpha feature.

ctenberge-oneid commented 6 days ago

Having this would help a lot of use cases that need very little "transformations" not be forced to write and maintain Compositions/Definitions and the whole versioning/releasing of those.