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

Add toYaml & fromYaml functions #20

Merged
merged 5 commits into from
Nov 15, 2023

Conversation

jan-di
Copy link
Contributor

@jan-di jan-di commented Nov 6, 2023

Description of your changes

Add two functions toYaml and fromYamlto this function, as they are not supported in sprig. Esepcially the first one is essential, as the templates are focused on creating yaml resources.

I have:

  • Read and followed Crossplane's contribution process.
  • [ ] Added or updated unit tests for my change.

@jan-di jan-di force-pushed the feature/yamlConversion branch from 2991437 to 07d2255 Compare November 6, 2023 16:28
@tnm-
Copy link

tnm- commented Nov 8, 2023

Thx, I was looking for exactly this. Without it, i believe go templates need to be aware of the input schema all the way down even to copy values from those fields (i.e. to not change them at all).

@ezgidemirel
Copy link
Collaborator

Hi @jan-di , thanks for extending available helper functions! Can you please create a new folder under examples and provide manifests that can work with crossplane beta render tooling?

@jan-di jan-di force-pushed the feature/yamlConversion branch from 1e6331b to 614e3b2 Compare November 13, 2023 16:29
@jan-di
Copy link
Contributor Author

jan-di commented Nov 13, 2023

@ezgidemirel done. Please note I also added example/.dev/functions.yaml to be able to run pipelines locally using go instead of using a tagged image.

@tnm-
Copy link

tnm- commented Nov 15, 2023

Could merging and releasing this get some priority? I am aware that functions are still beta feature, and there's no bug report for this (yes, I consider the lack of this a bug, not an enhancement -- should we open an bug type issue as well?). Without this, function-go-templating is very limited in usability, unfortunately.

Thank you!

@phisco
Copy link
Collaborator

phisco commented Nov 15, 2023

toYaml shouldn't be strictly required, as JSON is totally valid inside YAML, surely not the best to see in the output of the render subcommands, but for what crossplane is concerned, it should just work.

fromYaml could indeed give you access to YAML passed as string as per your example, so although nice to have, I wouldn't call it a bug, @tnm-.

Copy link
Collaborator

@ezgidemirel ezgidemirel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jan-di for the PR! Added a small comment to fix README. Apart from that, there are some conflicts that need to be resolved. Could you please rebase your PR, so that we can merge it :)

README.md Outdated Show resolved Hide resolved
@tnm-
Copy link

tnm- commented Nov 15, 2023

toYaml shouldn't be strictly required, as JSON is totally valid inside YAML, surely not the best to see in the output of the render subcommands, but for what crossplane is concerned, it should just work.

I disagree, I think toYaml is required. Or at least I haven't figured out how to take arbitrary yaml object from claim/xr and output it to the managed resource verbatim (either as yaml or json) without knowing and defining the exact schema of the arbitrary yaml object in the go template.

@jan-di jan-di force-pushed the feature/yamlConversion branch from 5d2d662 to 9a4169d Compare November 15, 2023 08:31
jan-di and others added 4 commits November 15, 2023 09:31
Signed-off-by: Jan Dittrich <[email protected]>
Signed-off-by: Jan Dittrich <[email protected]>
Co-authored-by: ezgidemirel <[email protected]>
Signed-off-by: Jan Dittrich <[email protected]>
@jan-di jan-di force-pushed the feature/yamlConversion branch from 9a4169d to a5a9d15 Compare November 15, 2023 08:32
Signed-off-by: Jan Dittrich <[email protected]>
@jan-di
Copy link
Contributor Author

jan-di commented Nov 15, 2023

Thanks @jan-di for the PR! Added a small comment to fix README. Apart from that, there are some conflicts that need to be resolved. Could you please rebase your PR, so that we can merge it :)

Thank you for the review. From my side, everything is done and green :)

@ezgidemirel ezgidemirel merged commit a594f05 into crossplane-contrib:main Nov 15, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants