-
Notifications
You must be signed in to change notification settings - Fork 57
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 KubeObject setters that keep formatting to "kubeobject" lib #133
Conversation
eed3fcc
to
cd33b0f
Compare
Nice!! /approve |
The code uses the "unsafe" module to get access to the internals of KubeObject. This is a temporary solution, until kptdev/kpt#3923 is solved. |
Thanks @kispaljr . Overall looks good. I have a question:
|
yes, it would and that was my first instinct, as well. |
See my view is different here. Why did we create the KubeObjExt -> it is an extension of the KubeObject methods. If the SDK takes it in we can obsolete this. With your proposal the KubeObjExt is irrelevant. So we have a chicken and egg situation |
Moreover we need to add nil check everywhere, which we can avoid with what I propose. |
I am all right with adding the setters as methods to KubeObjectExt. Actually we can keep both sets of functions, by adding methods like this:
We cannot add the getters as methods, since generic methods are not supported in go, but this is not a great loss: GetSpec and GetStatus are not really useful, to be honest :) |
I see the KubeObject pointers in SetXXX functions as "~receivers", so if we think nill-checking is needed there, then I think we should also check the receivers in KubeObjectExt, like this:
All in all, I cannot see a big difference from that perspective. |
I went ahead and added the setters as methods to KubeObjectExt (with tests) |
ok but we don't need both. Let's just extend KubeObjectExt and be done. Eventually this moves to the fn sdk. We should steer people into 1 thing. |
I will try to make my case to keep both possibilities: setters defined on both KubeObject and KubeObjectExt.
|
If Yuwen pulls your fixes into the fn SDK, what changes here? |
I guess you mostly answered that already. What I was trying to say is: I have asked Yuwen to do that, so you should take that into account. Hopefully she can do it quickly. |
thanks @kispaljr for the detailed notes. We created the KubeObjextExt with the intention that functions will create that and use it as that will have extended functionalities such as the ones you have implemented here. If it is indeed the case we need these on the extended objects only and as @johnbelamaric suggested when they move to the base SDK we will simply remove those methods from our library and rest of the implementation will continue to work ( as we are composing the base structure and not instantiating in the parser). However if you think we have an immediate need for straight methods I am fine with keeping both as well. Either way it's easy to refactor when the base library implements this. Thanks a lot. |
I will put I more argument in which is in go people have tried to steer to 1 option only and this is helping things a lot. So I would vote for this. Since it is clear what people want and how to use it. |
and to complete we don't need advanced functionality on subjects for now since getspec/setspec does this for us. We just convert to go types and back, so this makes it also clear how we want people to use it. So my point is once the sdk merges this we can leverage all the other parts and goodies. |
869b093
to
b27b322
Compare
I wasn't convincing enough :), so, as promised, I removed SetSpec and SetStatus working on pure KubeObjects. I cannot move the getters into methods, because the go language doesn't allow generic methods. If anybody has a workaround, I am open to suggestions. |
Given we have GetGoStruct we don't need the additional getSpec and getStatus as the goStruct gives all of them. Also I don't see the value of ToStruct as the .AS method has this already. So better to remove |
d41d2c3
to
5bb9340
Compare
All comments fixed (rebase, removed superfluous functions).
somebody with the right permissions can take care of this? |
/override presubmit-nephio-gosec to overcome the issue which will finally be fixed in fn sdk |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: henderiw, johnbelamaric The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
/lgtm |
…f fields while updating big chunks of a KubeObject
5bb9340
to
edca649
Compare
/lgtm |
@kispaljr: you cannot LGTM your own PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/override presubmit-nephio-gosec |
@henderiw: Overrode contexts on behalf of henderiw: presubmit-nephio-gosec In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/lgtm |
Add KubeObject setters that try to keep YAML comments and the order of fields while updating big chunks of a KubeObject.
Most notably: SetNestedFieldKeepFormatting(), SetSpec() and SetStatus()
I believe that the optimal place to solve this problem is in the upstream kpt-fn SDK (https://github.com/GoogleContainerTools/kpt-functions-sdk), and I already asked the maintainers in this issue: kptdev/kpt#3923
Naturally, if this functionality is implemented in the upstream SDK, then this code should be deleted from the Nephio repo.