TypeMeta not properly set on IMC
Describe the bug When creating a new InMemoryChannel, the TypeMeta field is not being set properly on InMemoryChannel struct seen by the reconciler for the imc-dispatcher: https://github.com/knative/eventing/blob/90721ab4054f4ec239f84371e8afdb1b6fcdfc5a/pkg/reconciler/inmemorychannel/dispatcher/inmemorychannel.go#L61
Expected behavior The TypeMeta field should be properly annotated with the correct Kind and APIVersion.
To Reproduce
- Create a new minikube cluster
- Add
logging.FromContext(ctx).Infof("imc: %+v", imc)to line 77 ofpkg/reconciler/inmemorychannel/dispatcher/inmemorychannel.go kubectl apply -Rf third_party/cert-managerko apply -Rf config- Create an InMemoryChannel with the following config:
apiVersion: messaging.knative.dev/v1
kind: Channel
metadata:
name: example-channel
namespace: default
spec:
channelTemplate:
apiVersion: messaging.knative.dev/v1
kind: InMemoryChannel
- Get the logs from the pod. You should see something like:
{
"level": "info",
"ts": "2023-07-13T19:31:51.021Z",
"logger": "inmemorychannel-dispatcher",
"caller": "dispatcher/inmemorychannel.go:77",
"msg": "imc: &{TypeMeta:{Kind: APIVersion:} ObjectMeta:{Name:example-channel GenerateName: Namespace:default SelfLink: UID:74d549a7-4494-4a6f-b264-a2d5e5cfd2df ResourceVersion:3789 Generation:1 CreationTimestamp:2023-07-13 19:31:51 +0000 UTC DeletionTimestamp:<nil> DeletionGracePeriodSeconds:<nil> Labels:map[] Annotations:map[messaging.knative.dev/creator:system:serviceaccount:knative-eventing:eventing-controller messaging.knative.dev/lastModifier:system:serviceaccount:knative-eventing:eventing-controller messaging.knative.dev/subscribable:v1] OwnerReferences:[{APIVersion:messaging.knative.dev/v1 Kind:Channel Name:example-channel UID:c8e6356a-2f95-4d68-ba34-74ff443ed5e8 Controller:0xc00081a878 BlockOwnerDeletion:0xc00081a879}] Finalizers:[] ManagedFields:[{Manager:channel_controller Operation:Update APIVersion:messaging.knative.dev/v1 Time:2023-07-13 19:31:51 +0000 UTC FieldsType:FieldsV1 FieldsV1:{\"f:status\":{\".\":{},\"f:address\":{\".\":{},\"f:name\":{},\"f:url\":{}},\"f:conditions\":{},\"f:observedGeneration\":{}}} Subresource:status} {Manager:controller Operation:Update APIVersion:messaging.knative.dev/v1 Time:2023-07-13 19:31:51 +0000 UTC FieldsType:FieldsV1 FieldsV1:{\"f:metadata\":{\"f:ownerReferences\":{\".\":{},\"k:{\\\"uid\\\":\\\"c8e6356a-2f95-4d68-ba34-74ff443ed5e8\\\"}\":{}}}} Subresource:}]} Spec:{ChannelableSpec:{SubscribableSpec:{Subscribers:[]} Delivery:<nil>}} Status:{ChannelableStatus:{Status:{ObservedGeneration:1 Conditions:[{Type:Addressable Status:True Severity: LastTransitionTime:{Inner:2023-07-13 19:31:51 +0000 UTC} Reason: Message:} {Type:ChannelServiceReady Status:True Severity: LastTransitionTime:{Inner:2023-07-13 19:31:51 +0000 UTC} Reason: Message:} {Type:DeadLetterSinkResolved Status:True Severity: LastTransitionTime:{Inner:2023-07-13 19:31:51 +0000 UTC} Reason:DeadLetterSinkNotConfigured Message:No dead letter sink is configured.} {Type:DispatcherReady Status:True Severity:Info LastTransitionTime:{Inner:2023-07-13 19:31:51 +0000 UTC} Reason: Message:} {Type:EndpointsReady Status:True Severity: LastTransitionTime:{Inner:2023-07-13 19:31:51 +0000 UTC} Reason: Message:} {Type:Ready Status:True Severity: LastTransitionTime:{Inner:2023-07-13 19:31:51 +0000 UTC} Reason: Message:} {Type:ServiceReady Status:True Severity: LastTransitionTime:{Inner:2023-07-13 19:31:51 +0000 UTC} Reason: Message:}] Annotations:map[]} AddressStatus:{Address:0xc000a9a108 Addresses:[]} SubscribableStatus:{Subscribers:[]} DeliveryStatus:{DeadLetterSinkURI: DeadLetterSinkCACerts:<nil>}}}}",
"commit": "90721ab-dirty",
"knative.dev/pod": "imc-dispatcher-75f7d7dfdf-vntql",
"knative.dev/controller": "knative.dev.eventing.pkg.reconciler.inmemorychannel.dispatcher.Reconciler",
"knative.dev/kind": "messaging.knative.dev.InMemoryChannel",
"knative.dev/traceid": "af39ef0f-3f64-4996-9159-310cab84e6f4",
"knative.dev/key": "default/example-channel"
}
Note that the TypeMeta has empty strings for Kind and APIVersion.
Knative release version release-next
Additional context Add any other context about the problem here such as proposed priority
/assign
/triage accepted
Bug reproduced
Yes, this might happen on typed informers, see below for how to solve it: https://github.com/knative/eventing/blob/90721ab4054f4ec239f84371e8afdb1b6fcdfc5a/pkg/reconciler/subscription/controller.go#L74-L80
From discussion with @pierDipi :
It seems like this problem is being caused in the generated code, and using EnsureTypeMeta doesn't fix it. We should fix this in knative/pkg instead
@Cali0707 Is anyone working on this in knative/pkg ?
@g1rjeevan not currently, but to complicate this I am not sure how to fix it in knative/pkg.
@pierDipi do you have any recommended approaches for this?
Thinking more about this: technically, knative/pkg already provides that info with the logging key knative.dev/kind:
"knative.dev/kind": "messaging.knative.dev.InMemoryChannel",
so even though the object itself has not TypeMeta set, we can infer it from that logging key
@Cali0707 do you still think this is necessary given my last comment?
@Cali0707 do you still think this is necessary given my last comment?
No, probably not. Let's close this! But, I am still interested in what was causing the problem...