Will defer function still get executed after a Kubernetes admission request has timed out?

12/20/2021

For example, a defer function is implemented within a webhook's logic (the webhook is written in Golang). The webhook times out after taking too long to complete. In this case, will the defer function still get executed?

The request timeout is set via context.WithTimeout for the webhook.

-- jtee
go
kubernetes

1 Answer

12/21/2021

It's usually a good idea to clearly mention what programming language you're talking about, although I can figure it out.

In Go, the defer functor (whatever you want to call it) will be executed when the method returns, no matter how it completes, unless you manage to kill the executing process in a drastic manner, and perhaps even then.

-- David M. Karr
Source: StackOverflow