-
Notifications
You must be signed in to change notification settings - Fork 29
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
505: fail with message when webhook not enabled and minReplicas is nil #543
Conversation
0442021
to
9775ea9
Compare
@imaffe:Thanks for your contribution. For this PR, do we need to update docs? |
9775ea9
to
4a1cc0f
Compare
controllers/spec/hpa.go
Outdated
func makeHPA(objectMeta *metav1.ObjectMeta, minReplicas, maxReplicas *int32, podPolicy v1alpha1.PodPolicy, targetRef autov2beta2.CrossVersionObjectReference) *autov2beta2.HorizontalPodAutoscaler { | ||
|
||
panicIfNil(minReplicas, "MinReplicas should not be nil but is nil; This is likely because the webhook is not installed properly so it does not have a default value") | ||
panicIfNil(maxReplicas, "MaxReplicas should not be nil but is nil; This is likely because the webhook is not installed properly so it does not have a default 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.
I think the maxReplicas
is optional?
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 added this check to make sure they are not null (from the code's perspective), but the message should be changed if the maxReplicas is optional and could not be null in this case.
@imaffe do we need to update the docs for this PR? Thanks |
I think we can put the logic to determine if |
8fde604
to
e921cbb
Compare
e921cbb
to
bd8b2c0
Compare
func panicIfNil(value interface{}, message string) { | ||
if value == nil { | ||
panic(message) | ||
} |
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.
we should never panic in a controller's reconciliation loop
close by #582 |
We have two methods to avoid the nil pointer exception.
Method 1 is to provide a default value for the possible nil fields just like in the admission webhook. However adding default value in the code could potentially make it harder to find where the config value comes from when debugging. And it also require us to change two places if we were to change the default value logic.
Method 2 is simple: fail early but with hint messages on what caused the issue and how to resolve the issue. It guides the user to use a newer version of function-mesh with webhooks enabled.
Fixes #505
fix #505