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

[function-mesh] nil pointer in MakeFunctionHPA() #505

Closed
imaffe opened this issue Nov 2, 2022 · 7 comments · Fixed by #582
Closed

[function-mesh] nil pointer in MakeFunctionHPA() #505

imaffe opened this issue Nov 2, 2022 · 7 comments · Fixed by #582

Comments

@imaffe
Copy link
Contributor

imaffe commented Nov 2, 2022

A nil pointer deference is thrown in
image.png

image.png

The exception is thrown because function.Spec.MinReplica is null:

2022-11-02T15:54:14.680+0800 INFO function-resource MinReplicas {"pt": null}

The spec json is

{
   "specs":{
      "className":"org.apache.pulsar.functions.api.examples.ExclamationFunction",
      "clusterName":"test-pulsar",
      "replicas":1,
      "maxReplicas":5,
      "input":{
         "typeClassName":"java.lang.String",
         "topics":[
            "persistent://public/default/java-function-input-topic"
         ]
      },
      "output":{
         "typeClassName":"java.lang.String",
         "topic":"persistent://public/default/java-function-output-topic"
      },
      "logTopic":"persistent://public/default/logging-function-logs",
      "resources":{
         "limits":{
            "cpu":"200m",
            "memory":"1100M"
         },
         "requests":{
            "cpu":"100m",
            "memory":"1G"
         }
      },
      "secretsMap":{
         "name":{
            "path":"test-secret",
            "key":"username"
         },
         "pwd":{
            "path":"test-secret",
            "key":"password"
         }
      },
      "volumeMounts":[
         {
            "name":"cache-volume",
            "mountPath":"/cache"
         }
      ],
      "autoAck":true,
      "forwardSourceMessageProperty":true,
      "maxPendingAsyncRequests":1000,
      "pod":{
         "labels":{
            "locaction":"mtv"
         },
         "annotations":{
            "managed-function":"true"
         },
         "volumes":[
            {
               "name":"cache-volume",
               "emptyDir":{
                  
               }
            }
         ],
         "imagePullSecrets":[
            {
               "name":"regcred"
            }
         ],
         "initContainers":[
            {
               "name":"init-function",
               "image":"busybox:1.28",
               "command":[
                  "sh",
                  "-c",
                  "echo The app is running! && sleep 30"
               ],
               "resources":{
                  
               }
            }
         ],
         "sidecars":[
            {
               "name":"sidecar-function",
               "image":"busybox:1.28",
               "command":[
                  "sh",
                  "-c",
                  "echo The app is running! && sleep 30000"
               ],
               "resources":{
                  
               }
            }
         ],
         "env":[
            {
               "name":"EXAMPLE_VARIABLE",
               "value":"exampleValue"
            }
         ]
      },
      "pulsar":{
         "pulsarConfig":"test-pulsar",
         "authSecret":"test-auth",
         "tlsSecret":"test-tls"
      },
      "java":{
         "jar":"pulsar-functions-api-examples.jar",
         "jarLocation":"public/default/nlu-test-java-function",
         "extraDependenciesDir":"random-dir/"
      }
   }
}

I can follow this issue to understand the HPA related code~

@imaffe imaffe self-assigned this Nov 2, 2022
@imaffe imaffe changed the title [function-mesh] nil pointer in MakHPAFunction() [function-mesh] nil pointer in MakeFunctionHPA() Nov 2, 2022
@imaffe
Copy link
Contributor Author

imaffe commented Nov 7, 2022

Looks like my default webhook is not enabled.

@tpiperatgod
Copy link
Contributor

Currently, this issue occurs during upgrades from older versions (without webhook) to newer versions. Therefore, it makes sense to solve this issue.

@imaffe
Copy link
Contributor Author

imaffe commented Nov 7, 2022

This is because, when I run the operator controller locally using make run,seems the webhook is not created and thus the nil pointer. (If webhook enabled, the validation should guarantee that the nil pointer condition will not occur). Need to find a way to enable webhook in local run.

@imaffe imaffe closed this as completed Nov 7, 2022
@imaffe imaffe reopened this Nov 7, 2022
@imaffe
Copy link
Contributor Author

imaffe commented Nov 7, 2022

Currently, this issue occurs during upgrades from older versions (without webhook) to newer versions. Therefore, it makes sense to solve this issue.

Good to know this. For fixing this issue, do you mean something like check if the pointer is nil and provide a default value for it before we process the Spec (just like we did in the mutating webhook)?

Or should we just simply detect the nil pointer and fail early and instruct the user to complete the Spec ?

@tpiperatgod
Copy link
Contributor

This is because, when I run the operator controller locally using make run,seems the webhook is not created and thus the nil pointer. (If webhook enabled, the validation should guarantee that the nil pointer condition will not occur). Need to find a way to enable webhook in local run.

It is recommended to use nocalhost to run the controller with webhook enabled, pls see: https://streamnative.slack.com/files/U03EV808CAC/F03RZTPPWE8/develop_functionmesh_with_nocalhost.mp4

@tpiperatgod
Copy link
Contributor

Good to know this. For fixing this issue, do you mean something like check if the pointer is nil and provide a default value for it before we process the Spec (just like we did in the mutating webhook)?

Or should we just simply detect the nil pointer and fail early and instruct the user to complete the Spec ?

I think the "default value" is better...

@imaffe
Copy link
Contributor Author

imaffe commented Nov 14, 2022

Thanks, I'll try with the nocalhost~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment