vmware-tanzu / cartographer

Cartographer is a Supply Chain Choreographer.
https://cartographer.sh
Apache License 2.0
446 stars 65 forks source link

Coerce non-strings to strings in Templates #9

Open DanieldeR opened 2 years ago

DanieldeR commented 2 years ago

As a template author I want to be able to coerce non-strings to strings So that I can fulfill the contract of the objects I am deploying

Given a template whose templated object has a string field
And a workload parameter that is some other type
When I reference the param in a template field with escaped quotations
Then the object is successfully deployed by Cartographer
scothis commented 2 years ago

This is a general concern that could impact all templated values, not just params. How cartographer is currently handling types is correct to preserves the type and not attempt to automatically convert. That said, I think cartographer could be a bit more capable in how the template expression are resolved. I know this could quickly snowball, we should be very conservative with the syntax and explore multiple options.

One possible approach to is defined a well known set of method filters after the expression to transform the resolved value before it is substituted. $(pathExpression | filterFunc)$. A current expression like $(workload.spec.params[?(@.name=='hello')].value)$ could be enriched to $(workload.spec.params[?(@.name=='hello')].value | asString)$.