-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Using utilruntime.Must() for adding schemes #1462
Using utilruntime.Must() for adding schemes #1462
Conversation
Signed-off-by: Chris Hein <[email protected]>
5e83db8
to
37efde1
Compare
Signed-off-by: Chris Hein <[email protected]>
37efde1
to
1f9742a
Compare
@@ -113,7 +113,7 @@ const ( | |||
// change, and thus should be done for next project version. | |||
multiGroupControllerImportCodeFragment = `%scontroller "%s/controllers/%s" | |||
` | |||
addschemeCodeFragment = `_ = %s.AddToScheme(scheme) | |||
addschemeCodeFragment = `utilruntime.Must(%s.AddToScheme(scheme)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but could you add in the first comment one example of scenario that is solved/attended with?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not directly experiencing issues from this but from a best practices side in most other implementations of AddingToScheme()
they implement utilruntime.Must()
to ensure panics causing the controller to crash. https://github.com/search?q=org%3Akubernetes+utilruntime.Must&type=Code and https://github.com/search?q=org%3Akubernetes-sigs+utilruntime.Must&type=Code
Potentially it doesn't matter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HI @christopherhein,
I checked the Must impl here, and it just causes a panic error.
Regards that would be a
best practices
See here that it is not used in the biggest part of the places where the addSchema is used in the example provided. Also, if it is a good practice then:
- Should we not add this info in the AddToScheme doc?
- Why is the controller-runtime not using it all examples/scenarios?
Regards Kubebuilder project scenarios
Note that the errors returned has been explicitly ignored in the Kubebuilder projects, and then I was curious if you face any issue that justifies it.
Also, start to cause an panic error in all these scenarios may not be the expected behaviour. For example, will the panic occurs if the CRD required not be found in the cluster? What are the possible errors/scenarios where an error can be returned from it? Would be required to kill the project in all these circumstances?
Did you checked that already?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO it's reasonable to just let the controller fail if it can't even add scheme.
@droot @DirectXMan12 Thoughts?
will the panic occurs if the CRD required not be found in the cluster?
From my understanding no.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @camilamacedo86 sorry for the delayed response here. For now I've put in a PR to also add documentation to the scheme - kubernetes-sigs/controller-runtime#894
I had looked into a handful of the other implementation and most will cause Panics already for example if you register all the schemes from `client-go this https://github.com/kubernetes/client-go/blob/master/kubernetes/scheme/register.go#L133 will panic if there are issues.
I discussed this yesterday with @DirectXMan12 and they'd mentioned that this "either a) it was an oversight, or b) that pattern turned up after we had started writing our examples" and "we really should be checking the return value"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the errors usually come from errors in the conversion or defaulting registration since I've been able to repro panics by doing things like registering schemes of CRDs with the same GVK as standard k8s objects.
Per #1462 (comment), I guess we are on the same page. We can get this in. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: christopherhein, mengqiy 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 |
thanks @mengqiy! |
Add the use of
utilruntime.Must()
from apimachinery to catch errors with scheme configurations.Signed-off-by: Chris Hein [email protected]