leaderelection: populate the apiVersion/kind when reporting events

This avoids the assumption that the kinds are populated in the schema,
and is arguably a little more efficient also.

Kubernetes-commit: 3bf06ff3a15a2f1fefeb7a70373a92cb4b94818f
This commit is contained in:
Justin SB
2021-11-13 11:14:02 -05:00
committed by Kubernetes Publisher
parent e627be7959
commit ecfd45a4d9
3 changed files with 15 additions and 3 deletions

View File

@@ -87,7 +87,11 @@ func (ll *LeaseLock) RecordEvent(s string) {
return
}
events := fmt.Sprintf("%v %v", ll.LockConfig.Identity, s)
ll.LockConfig.EventRecorder.Eventf(&coordinationv1.Lease{ObjectMeta: ll.lease.ObjectMeta}, corev1.EventTypeNormal, "LeaderElection", events)
subject := &coordinationv1.Lease{ObjectMeta: ll.lease.ObjectMeta}
// Populate the type meta, so we don't have to get it from the schema
subject.Kind = "Lease"
subject.APIVersion = coordinationv1.SchemeGroupVersion.String()
ll.LockConfig.EventRecorder.Eventf(subject, corev1.EventTypeNormal, "LeaderElection", events)
}
// Describe is used to convert details on current resource lock