Skip to content

Commit

Permalink
fix cooldownqueue key from event
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Bertschy <[email protected]>
  • Loading branch information
matthyx committed Sep 17, 2024
1 parent c931614 commit cdfac44
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions utils/cooldownqueue.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package utils

import (
"strings"
"time"

"github.com/kubescape/synchronizer/domain"
"istio.io/pkg/cache"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
)

Expand All @@ -14,7 +14,7 @@ const (
evictionInterval = 1 * time.Second
)

// CooldownQueue is a queue that lets clients put events into it with a cooldown
// CooldownQueue i a queue that lets clients put events into it with a cooldown
//
// When a client puts an event into a queue, it waits for a cooldown period before
// the event is forwarded to the consumer. If and event for the same key is put into the queue
Expand Down Expand Up @@ -44,20 +44,9 @@ func NewCooldownQueue() *CooldownQueue {

// makeEventKey creates a unique key for an event from a watcher
func makeEventKey(e watch.Event) string {
object, ok := e.Object.(*unstructured.Unstructured)
if !ok {
return ""
}
id := domain.KindName{
Kind: &domain.Kind{
Group: object.GetAPIVersion(),
Resource: object.GetKind(),
},
Name: object.GetName(),
Namespace: object.GetNamespace(),
}

return id.String()
gvk := e.Object.GetObjectKind().GroupVersionKind()
meta := e.Object.(metav1.Object)
return strings.Join([]string{gvk.Group, gvk.Version, gvk.Kind, meta.GetNamespace(), meta.GetName()}, "/")
}

func (q *CooldownQueue) Closed() bool {
Expand Down

0 comments on commit cdfac44

Please sign in to comment.