kpt icon indicating copy to clipboard operation
kpt copied to clipboard

Formatting breaks yaml anchors/references

Open mortent opened this issue 4 years ago • 5 comments

Expected behavior

Formatting configs would not break yaml docs that includes anchors and references.

Actual behavior

Running the kpt fn render command on a configuration that includes anchors and references ends up putting the anchors before the references in the yaml, thereby making the yaml invalid.

Information

Steps to reproduce the behavior

kpt pkg get https://github.com/mortent/kpt-packages.git/zookeeper-networkpolicy
kpt fn render zookeeper-networkpolicy  # Succeeds, but reformats the config.
kpt fn render zookeeper-networkpolicy  # Fails

mortent avatar May 03 '21 22:05 mortent

I cannot reproduce this because the package uses a private image? How does the output yaml look like?

Shell32-Natsu avatar May 03 '21 22:05 Shell32-Natsu

Simplified the example to avoid relying on the private images.

mortent avatar May 03 '21 22:05 mortent

cc @phanimarupaka @droot

Shell32-Natsu avatar May 03 '21 22:05 Shell32-Natsu

The issue is with format filter ordering of fields. It doesn't consider anchors and references. We should implement additional sorting rules to have anchors before references. What is the priority of this ? m2 or m3 ?

phanimarupaka avatar May 03 '21 22:05 phanimarupaka

I put this in m4. I don't think using anchors and references are very common with k8s config, so I don't think it is a major issue. But we should keep track of it and see if we can eventually get it fixed.

mortent avatar May 04 '21 00:05 mortent