Describe the bug
Enabling nullability in my operator project causes webhooks to fail. When nullability is enabled, I see the following Request.Object.Uid is required error on the kube-apiserver, which it is receiving from ASP.NET:
I0425 03:24:52.491708 1 request.go:1411] body was not decodable (unable to check for Status): Object 'Kind' is missing in '{"type":"https://tools.ietf.org/html/rfc9110#section-15.5.1","title":"One or more validation errors occurred.","status":400,"errors":{"Request.Object.Uid":["The Uid field is required."]},"traceId":"00-1e0d8715878c6606b3c70f8683bd85d3-c57cbcf6dfc4b1a6-00"}' W0425 03:24:52.491764 1 dispatcher.go:225] Failed calling webhook, failing closed mutate.test.company.com.v1: failed calling webhook "mutate.test.company.com.v1": failed to call webhook: the server rejected our request for an unknown reason
And the AdmissionReview Kubernetes is sending in the POST has the following fields for the object (metadata and spec removed for brevity):
{
"kind": "AdmissionReview",
"apiVersion": "admission.k8s.io/v1",
"request": {
"object": {
"apiVersion": "company.com/v1",
"kind": "test",
"metadata": "my metadata"
"spec": "my spec"
},
}
}
And what little MVC logging there was:
trce: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[52] Action Filter: Before executing OnActionExecuting on filter Microsoft.AspNetCore.Mvc.Infrastructure.ModelStateInvalidFilter. dbug: Microsoft.AspNetCore.Mvc.Infrastructure.ModelStateInvalidFilter[1] The request has model state errors, returning an error response.
It seems that the model binder is trying to bind the uid field for the object, but because 1) nullable is enabled, 2) the Uid is not nullable in k8s.models.V1ObjectMeta, and 3) the request does not contain the uid under the request.object, it is failing to bind.
Some Microsoft documentation might be helpful.
To reproduce
- Run Kubernetes API server with verbose logging.
- Create a new operator project with a mutation webhook and nullable enabled.
- Implement the webhook .
- Run the operator.
- Try to create the object in Kubernetes.
- Observe that the Kubernetes API server logs the error given by ASP.NET.
- Disable nullable in the project.
- Do steps 4-5 the and observe that the request finishes (though mine is still failing after the 200 status for unknown reasons).
Expected behavior
Model binding should succeed with nullable-enabled projects.
Screenshots
No response
Additional Context
No response
Describe the bug
Enabling nullability in my operator project causes webhooks to fail. When nullability is enabled, I see the following
Request.Object.Uid is requirederror on the kube-apiserver, which it is receiving from ASP.NET:I0425 03:24:52.491708 1 request.go:1411] body was not decodable (unable to check for Status): Object 'Kind' is missing in '{"type":"https://tools.ietf.org/html/rfc9110#section-15.5.1","title":"One or more validation errors occurred.","status":400,"errors":{"Request.Object.Uid":["The Uid field is required."]},"traceId":"00-1e0d8715878c6606b3c70f8683bd85d3-c57cbcf6dfc4b1a6-00"}' W0425 03:24:52.491764 1 dispatcher.go:225] Failed calling webhook, failing closed mutate.test.company.com.v1: failed calling webhook "mutate.test.company.com.v1": failed to call webhook: the server rejected our request for an unknown reasonAnd the AdmissionReview Kubernetes is sending in the POST has the following fields for the object (metadata and spec removed for brevity):
{ "kind": "AdmissionReview", "apiVersion": "admission.k8s.io/v1", "request": { "object": { "apiVersion": "company.com/v1", "kind": "test", "metadata": "my metadata" "spec": "my spec" }, } }And what little MVC logging there was:
trce: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[52] Action Filter: Before executing OnActionExecuting on filter Microsoft.AspNetCore.Mvc.Infrastructure.ModelStateInvalidFilter. dbug: Microsoft.AspNetCore.Mvc.Infrastructure.ModelStateInvalidFilter[1] The request has model state errors, returning an error response.It seems that the model binder is trying to bind the
uidfield for the object, but because 1) nullable is enabled, 2) theUidis not nullable ink8s.models.V1ObjectMeta, and 3) the request does not contain theuidunder therequest.object, it is failing to bind.Some Microsoft documentation might be helpful.
To reproduce
Expected behavior
Model binding should succeed with nullable-enabled projects.
Screenshots
No response
Additional Context
No response