Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

imaffe
Copy link
Contributor

@imaffe imaffe commented Dec 5, 2022

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

@imaffe imaffe requested review from nlu90, freeznet and a team as code owners December 5, 2022 11:02
@imaffe imaffe force-pushed the affe/505-hpa-nil-pointer branch from 0442021 to 9775ea9 Compare December 5, 2022 11:02
@github-actions
Copy link

github-actions bot commented Dec 5, 2022

@imaffe:Thanks for your contribution. For this PR, do we need to update docs?
(The PR template contains info about doc, which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)

@github-actions github-actions bot added the doc-info-missing This pr needs to mark a document option in description label Dec 5, 2022
@imaffe imaffe force-pushed the affe/505-hpa-nil-pointer branch from 9775ea9 to 4a1cc0f Compare December 5, 2022 13:41
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")
Copy link
Member

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?

Copy link
Contributor Author

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.

@Huanli-Meng
Copy link
Contributor

@imaffe do we need to update the docs for this PR? Thanks

@tpiperatgod
Copy link
Contributor

I think we can put the logic to determine if spec.minReplicas is nil at the beginning of the reconciliation

@imaffe imaffe added no-need-doc This pr does not need any document and removed doc-info-missing This pr needs to mark a document option in description labels Dec 13, 2022
@imaffe imaffe force-pushed the affe/505-hpa-nil-pointer branch 2 times, most recently from 8fde604 to e921cbb Compare December 16, 2022 15:17
@imaffe imaffe force-pushed the affe/505-hpa-nil-pointer branch from e921cbb to bd8b2c0 Compare December 16, 2022 15:19
Comment on lines +137 to +140
func panicIfNil(value interface{}, message string) {
if value == nil {
panic(message)
}
Copy link
Contributor

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

@tpiperatgod tpiperatgod self-assigned this Feb 10, 2023
@freeznet
Copy link
Member

close by #582

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
m/2023-03 no-need-doc This pr does not need any document
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[function-mesh] nil pointer in MakeFunctionHPA()
6 participants