Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

event-watcher: don't parse resource version #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions tools/event-watcher/event-watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ import (
"k8s.io/client-go/tools/clientcmd"
)

var (
// PodLastResourceVersion holds last cached revision prior start processing
PodLastResourceVersion string

// ServiceLastResourceVersion holds last cached revision prior start processing
ServiceLastResourceVersion string

// EventLastResourceVersion holds last cached revision prior start processing
EventLastResourceVersion string
)

// Param represents an event parameter
type Param struct {
ParmName string `json:"parmName"`
Expand Down Expand Up @@ -88,13 +77,6 @@ func main() {
// Build and start the pod informer
podInformer := factory.Core().V1().Pods().Informer()
podInformer.AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: func(obj interface{}) bool {
if PodLastResourceVersion == "" {
PodLastResourceVersion = podInformer.LastSyncResourceVersion()
fmt.Printf("Last resource revision for pods: %s\n", PodLastResourceVersion)
}
return isNewer(obj.(*v1.Pod).ResourceVersion, PodLastResourceVersion)
},
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: onAddPod, // Triggers when a new pod gets created
DeleteFunc: onDeletePod, // Triggers when a pod gets deleted
Expand All @@ -105,13 +87,6 @@ func main() {
// Build and start a service informer
svcInformer := factory.Core().V1().Services().Informer()
svcInformer.AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: func(obj interface{}) bool {
if ServiceLastResourceVersion == "" {
ServiceLastResourceVersion = svcInformer.LastSyncResourceVersion()
fmt.Printf("Last resource revision for services: %s\n", ServiceLastResourceVersion)
}
return isNewer(obj.(*v1.Service).ResourceVersion, ServiceLastResourceVersion)
},
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: onAddService, // Triggers when a new service gets created
DeleteFunc: onDeleteService, // Triggers when a service gets deleted
Expand All @@ -122,13 +97,6 @@ func main() {
// Build and start an event informer
eventInformer := factory.Core().V1().Events().Informer()
eventInformer.AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: func(obj interface{}) bool {
if EventLastResourceVersion == "" {
EventLastResourceVersion = eventInformer.LastSyncResourceVersion()
fmt.Printf("Last resource revision for events: %s\n", EventLastResourceVersion)
}
return isNewer(obj.(*v1.Event).ResourceVersion, EventLastResourceVersion)
},
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: onAddEvent, // Triggers when a new event gets created
},
Expand Down Expand Up @@ -160,12 +128,6 @@ func main() {
<-stopper
}

func isNewer(currentResourceVersion string, lastResourceVersion string) bool {
last, _ := strconv.ParseUint(lastResourceVersion, 10, 64)
current, _ := strconv.ParseUint(currentResourceVersion, 10, 64)
return current > last
}

func getBaseUEI() string {
return getEnv("ONMS_BASE_UEI", "uei.opennms.org/kubernetes")
}
Expand Down