Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

选举后,leader 节点异常丢失 event #1

Open
zhaogaolong opened this issue Oct 18, 2021 · 4 comments
Open

选举后,leader 节点异常丢失 event #1

zhaogaolong opened this issue Oct 18, 2021 · 4 comments

Comments

@zhaogaolong
Copy link

我有一个疑问,在 controller 选举的过程中的 event 是不是就丢失掉了。

@abowloflrf
Copy link
Owner

是这样的,除非能把上一轮 Leader 当时 watch 的 ResourceVersion 传到下一个 Leader 从那个位置继续 watch,但是成本高了点而且没太大必要毕竟一般 Event 收集容忍一定重复数据问题也不大,在启动的时候往前多收几秒的 Event 就好。

@zhaogaolong
Copy link
Author

在启动的时候往前多收几秒的 Event 就好。
这个是怎么设置的。show code 一下,谢谢

@abowloflrf
Copy link
Owner

在启动的时候往前多收几秒的 Event 就好。
这个是怎么设置的。show code 一下,谢谢

Informer 初次启动的时候会把集群内现存的所有 Events 走一遍 add 事件

func (ec *EventController) addHandlers() {
ec.evInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
e := obj.(*corev1.Event)
ec.enqueue(e, "ADD")
},

然后我这边的做法就是在 enqueue 的时候判断一下这个 Event 对象的创建时间,创建 5s 内的才加到 workqueue 里继续处理

func (ec *EventController) enqueue(e *corev1.Event, handleType string) {
logrus.Infof("event %s [%s][%s/%s][%s], last since %v", handleType, string(e.UID), e.InvolvedObject.Namespace, e.InvolvedObject.Name, e.Reason, time.Since(e.LastTimestamp.Time))
// prevent old events being handled when controller just start
if time.Since(e.LastTimestamp.Time) > time.Second*5 {
return
}
logrus.Infof("event to send [%s]", string(e.UID))
ec.queue.Add(e)
}

@zhaogaolong
Copy link
Author

我给你发了封邮件,希望能认识你。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants