kumahq / kuma-website

🐻 The official website for Kuma, the control plane for modern service connectivity.
https://kuma.io
Apache License 2.0
128 stars 94 forks source link

Preserve comments in `policy_yaml` block #2055

Open slonka opened 2 weeks ago

slonka commented 2 weeks ago

Description

Now when we parse the yaml in policy_yaml it will remove the comments. One simple trick that we could do to preserve them would be to create a map like this:

(contents_of_line, line_number): comment

and after all the modifications are done reapply the comments by searching the map for the same line and a closeby line_number. E.g.:

image

would create a map like:

("          match: ", 20): "optional: if absent, all clusters will be patched"
...

and then we would reapply this comment somewhere near 20 line (let's say [15, 25]) to lines that match match:. WDYT?

lahabana commented 2 weeks ago

It would be good. I'm a little curious on the feasability. Also there are yaml parsers (yq is one of them) which preserves comments. Wondering if there is such a thing on ruby

slonka commented 2 weeks ago

Maybe https://github.com/jim80net/yq ?

bartsmykla commented 1 week ago

triage: we should check if the builtin ruby YAML parser doesn't allow preserving comments