-
Notifications
You must be signed in to change notification settings - Fork 231
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
Go kpt fn SDK should allow keeping the original YAML comments wherever it's possible #3923
Comments
I feel that this might be a good point to implement support for keeping the comments: here the comments of the top-level node are transferred to the new node, but not recursively. It would be nice to (maybe optionally) transfer the comments to the subtree of YAML nodes under (Maybe the TODO comment in the code tries to suggest something similar) |
I don't see any blockers to add
Yes! This is the right place to make the change. @kispaljr do you want to help us making this change? I can help reviewing the code. |
Yes, I want to help, and I already have a first implementation (without tests so far). But... my employer won't allow me to sign your CLA, so I have to figure out what can I do in this case. |
@kispaljr Sorry for the CLA issue. The good news is that we are in the progress of donating kpt and KRM funcitons to CNCF. cncf/sandbox#34 and it is in good progress. |
@yuwenma if we can cherry-pick this, that would be best, although I do believe we working around it now. |
Sounds good. @kispaljr just to double check: In your PR only the first commit is relevant to the go/fn SDK, right? In that commit, do you expect all methods to go into go/fn SDK or only the |
Problem description
I want to able to write a kpt function using the Go SDK that does the following:
KubeObject
into a go struct (with theAs()
method),KubeObject
(e.g. with theSetNestedField()
method)After this whole cycle I want the original comments inside the "spec" part of the
KubeObject
to remain intact wherever the value of a field hasn't changed.Keeping the comments is a requirement coming form the project I am working on (Nephio)
Implementation ideas I've tried
The main problem with implementing this on top of the current SDK is that if
SetNestedField()
is called with a big go struct with nested sub-structs inside, then it will only keep the head/line/foot comments of the YAML node of the top-level struct, but not of its child nodes. (The same is true forSetNestedSlice()
btw.)One workaround would be reading the head/line/foot comments from the original
KubeObject
and writing them back for the matching parts after callingSetNestedField()
. However only head- and line-comments are exposed in theKubeObject
interface, but not foot-comments (why?). Also I couldn't find a way to walk the subtree of aKubeObject
/SubObject
, because I couldn't found a way to list the names of the fields of aSubObject
(at least not via the officially exposed API).I have some suboptimal workarounds for this problem heavily relying on reflection, and walking the fields of the go struct instead of the
SubObject
, however I feel that this problem should be addressed in the SDK layer, not above it.The text was updated successfully, but these errors were encountered: