admiraltyio / admiralty

A system of Kubernetes controllers that intelligently schedules workloads across clusters.
https://admiralty.io
Apache License 2.0
673 stars 87 forks source link

Panic on nil pointer dereference #195

Closed kirillmakhonin-brt closed 10 months ago

kirillmakhonin-brt commented 1 year ago

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

adrienjt commented 10 months ago

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

adrienjt commented 10 months ago

I figured it out. This is because the webhook is reinvocated in your setup, since #193, so this code path is run: https://github.com/admiraltyio/admiralty/blob/93761fdd7c1000fd511c63ec315adf94ad746fa0/pkg/webhooks/proxypod/proxypod.go#L62 Deserialization should be done into an initialized object. Unfortunately, trying to deserialize into nil doesn't produce an error.