crossplane-contrib / function-patch-and-transform

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

fix(environment): Validate against correct patch types #78

Closed MisterMX closed 10 months ago

MisterMX commented 10 months ago

This validates the given environment patch types against the correct types as specified in the API.

Originally, only the *EnvironmentFieldPath types were accepted but the input API definition only defines *CompositeFieldPath patches:

https://github.com/crossplane-contrib/function-patch-and-transform/blob/11be501f8e04cd1684cce0b3539438f0b6facd20/input/v1beta1/resources_patches.go#L71

negz commented 10 months ago

@MisterMX Looks like this needs a small unit test update too.

MisterMX commented 10 months ago

Thanks for the hint. I fixed the tests. To accomplish that I had to make some small changes to the render code:

Using the correct patch types requires changing the order in which xr and env are passed to ApplyToObjects to the "correct" order (xr, env) instead of (env, xr). Here env takes over the role of the composed resource just like in Apply.

Also, the tests were incorrectly assuming the environment data in patches to be under data which is not the case in Crossplane (see https://github.com/crossplane/crossplane/blob/806f0d20d146f6f4f1735c5ec6a7dc78923814b3/internal/controller/apiextensions/composite/environment_fetcher.go#L106). There it is not required to prefix environment patches with data. I changed that and remove the prefix from the tests.