Closed foriequal0 closed 1 year ago
It can, but it produces a zero time.Time
, which per https://pkg.go.dev/time#Time represents "January 1, year 1, 00:00:00.000000000 UTC".
k8s-openapi types the Event::event_time
field as Option<MicroTime>
because the spec says the field is optional.
Is 0001-01-01T00:00:00.000000000Z
a more useful value than None
? In golang where nonsensical "zero" values for structs are the norm since optionals require pointer types, sure. But I'm not sure I want to carry that forward into Rust when we have a proper Option
.
core/v1 Event spec says eventTime is optional, but events.k8s.io/v1 Event spec says it's required.
so api.get()
or api.list()
on events.k8s.io/v1 Event woud fail when there's any event that is converted from old type.
Oh, I forgot to mention that events.k8s.io/v1 Event usually contains core/v1 Events that are automatically converted.
I attached kubectl get event
, not kubecl get events.events.k8s.io
this is the latter.
{
"apiVersion": "events.k8s.io/v1",
"deprecatedCount": 1,
"deprecatedFirstTimestamp": "2023-02-16T18:25:07Z",
"deprecatedLastTimestamp": "2023-02-16T18:25:07Z",
"deprecatedSource": {
"component": "default-scheduler"
},
"eventTime": null,
"kind": "Event",
"metadata": {
"creationTimestamp": "2023-02-16T18:25:07Z",
"name": "some-pod.174461445d6d3cff",
"namespace": "test-530513",
"resourceVersion": "320932",
"uid": "f3ac47c9-cc86-4193-a2ed-2e4428b7ad77"
},
"note": "Successfully assigned test-530513/some-pod to test-pgd-control-plane",
"reason": "Scheduled",
"regarding": {
"apiVersion": "v1",
"kind": "Pod",
"name": "some-pod",
"namespace": "test-530513",
"resourceVersion": "320930",
"uid": "ace87ee8-15fb-46ae-9dae-c77422c2010f"
},
"type": "Normal"
}
Does the API server accept a JSON blob that doesn't contain an eventTime
field at all as an events.k8s.io/v1 Event ? Or does it require the field to be present?
Okay, from experimentation, it looks like the old core Events are translated into events/v1 Events with eventTime: null
. Creating new Events (or editing existing ones) with eventTime: null
or without eventTime
is rejected by the API server. New events/v1 Events that were generated by the API server as such must have eventTime: non-null
.
There is also the case of reportingController
etc fields - they are required in new events/v1 Events, but unlike eventTime
they are omitted entirely instead of being set to null
for old core Events. Also unlike the eventTime
field they are marked as optional in the OpenAPI spec.
So I think I'll treat this as an OpenAPI spec bug that should mark Event::eventTime
as an optional field just like it did for reportingController
etc, rather than allow MicroTime
to be deserializable from null
.
kubernetes apimachinary's MicroTime can be parsed from
null
https://github.com/kubernetes/apimachinery/blob/master/pkg/apis/meta/v1/micro_time.go#L111 Event events.k8s.io/v1 that is converted from core/v1 usually have"eventTime": null
e.g.