admiraltyio/admiralty

Panic on nil pointer dereference

kirillmakhonin-brt opened this issue · 2 comments

Hello
We've tried to use annotations proxy-pod-scheduling-constraints/use-constraints-from-spec-for-proxy-pod-scheduling on the latest version and 've recevied this error

2023/09/06 17:29:58 http: panic serving 10.64.18.99:57152: runtime error: invalid memory address or nil pointer dereference

goroutine 3623240 [running]:

net/http.(*conn).serve.func1()
  net/http/server.go:1802 +0xb9

panic({0x1818520, 0x2a70bf0})
  runtime/panic.go:1047 +0x266
admiralty.io/multicluster-scheduler/pkg/webhooks/proxypod.mutator.mutate({0xc00202d800}, 0xc000df4400)
  admiralty.io/multicluster-scheduler/pkg/webhooks/proxypod/proxypod.go:133 +0x48d

We suspect that issue is in the code that tries to access srcPod.Spec as Spec may be empty in corner cases

Hi, Spec isn't a pointer, so that's no it. However, srcPod may be nil. I'll have a look.

I figured it out. This is because the webhook is reinvocated in your setup, since #193, so this code path is run:

if err := yaml.UnmarshalStrict([]byte(pod.Annotations[common.AnnotationKeySourcePodManifest]), srcPod); err != nil {

Deserialization should be done into an initialized object. Unfortunately, trying to deserialize into nil doesn't produce an error.