-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Server Side Apply has poor interaction with some fields zero values #1669
Comments
Yes, that is correct. This is why the new typed builder syntax exists. Also, it's not really related to controller-runtime. Your two options for Apply are Unstructureds or Typed Builders. |
It would be great to document that as there are no examples in the library or docs on use Apply and the only examples that I can find are from an issue (#347) where the normal types (not unstructured or Typed Builders) are used. |
Also as far as I can tell Typed Builders cannot be used directly with controller-runtime client, we would need to drop down directly into the client-go library which breaks the abstraction provided by controller-runtime? |
We're still working on improved Apply support. The typed builders are relatively new and have minimal support in the ecosystem (we only recently merged the ability to generate them in the first place). My standing recommendation is still templates+go:embed+Unstructured though. It's much easier to manage long term. I'm going to close this out as this is not a bug we can address (nor can it be fixed in general). /close |
@coderanger: Closing this issue. 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. |
I think there is still something going on here... Using envtest binaries for k8s 1.20.2 I get the errors above, but Kind @ 1.20.7 I do not. Looking at the commit on k/k master, it doesn't appear to be in any 1.20.x tags at all. |
When using
client.Apply
patch type, some APIs run into issues. In particular, Service.spec.ports.targetPort, although there are likely others.Consider this example:
The expectation is this creates the service on the first iteration, and is a NOP on future iterations.
In reality, its changing each time:
In a real controller, this change then is picked up by the watch, and triggers another Reconcile, which loops forever.
Its plausible to workaround this by doing complex diffing on the client side, but this breaks the UX goal of
Ensure
presented in #347, where a client can just declare they configuration they want and let the server figure it out.The reason for this is due to the Service API:
TargetPort intstr.IntOrString
json:"targetPort,omitempty" protobuf:"bytes,4,opt,name=targetPort"``TargetPort is never empty because its not a pointer, so it is always marshalled as 0.
This can be seen in the following test:
which outputs:
The new client-go native typed Apply support does not have this issue, as seen by the test below:
The reason for this is the Apply code has a mirror of the API where each field is a pointer, thus
omitempty
actually leads to it not being set (TargetPort *intstr.IntOrString
json:"targetPort,omitempty"`).The request is to improve this experience. This could be done in a number of ways including...:
apply
variants of objectsPS:
TypeMeta
is required to explicitly be set which seems like something that can be inferred from the object type automatically.The text was updated successfully, but these errors were encountered: