Skip to content

Commit

Permalink
Merge pull request #5 from BaizeAI/dev/fix-timestamp-issue
Browse files Browse the repository at this point in the history
fix: lastTimestamp may be null (zero) which could cause events never being processed
  • Loading branch information
kebe7jun authored Sep 6, 2024
2 parents 000b574 + bfc3caf commit 868944f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Configure `kcover` to monitor specific Kubernetes resources by labeling them:

```shell
kubectl label pytorchjobs <job-name> kcover.io/cascading-recovery=true
kubectl label pytorchjobs <job-name> kcover.io/need-recovery=true
```

## Usage
Expand Down
8 changes: 6 additions & 2 deletions pkg/events/kubeevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ func (a *kubeEventsRecorder) Start() error {
_, err := informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
event := obj.(*corev1.Event)
if event.LastTimestamp.Add(3 * time.Minute).Before(time.Now()) {
klog.Infof("event %s is too old, ignore it", event.Name)
eventTimestamp := event.LastTimestamp
if eventTimestamp.IsZero() {
eventTimestamp = event.CreationTimestamp
}
if eventTimestamp.Add(3 * time.Minute).Before(time.Now()) {
klog.Infof("event %s is too old %s against %s, ignore it", event.Name, eventTimestamp.String(), time.Now().String())
return
}
if event.Annotations[constants.NeedRecoveryAnnotation] == "true" {
Expand Down

0 comments on commit 868944f

Please sign in to comment.