Skip to content

Commit 3c71f19

Browse files
committed
Move user provided object filter to controller
This is where it belongs (even though implementing this at recorder stage worked as well). No need to process the event all along up to recorder. TODO: make the filter list a map, so lookups would not need as much cpu time.
1 parent 0cbccfd commit 3c71f19

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

pkg/controller/controller.go

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package controller
77

88
import (
99
"fmt"
10+
"strings"
1011
"time"
1112

1213
"github.com/bpineau/katafygio/config"
@@ -161,6 +162,12 @@ func (c *Controller) processItem(key string) error {
161162
return fmt.Errorf("error fetching %s from store: %v", key, err)
162163
}
163164

165+
for _, obj := range c.config.ExcludeObject {
166+
if strings.Compare(strings.ToLower(obj), strings.ToLower(c.name+":"+key)) == 0 {
167+
return nil
168+
}
169+
}
170+
164171
if !exists {
165172
// deleted object
166173
c.enqueue(&event.Notification{Action: event.Delete, Key: key, Kind: c.name, Object: ""})

pkg/recorder/recorder.go

+11-22
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@ func (w *Listener) Stop() {
7777
}
7878

7979
func (w *Listener) processNextEvent(ev *event.Notification) {
80-
if w.shouldIgnore(ev) {
81-
return
82-
}
83-
84-
w.config.Logger.Debugf("kind=%s name=%s", ev.Kind, ev.Key)
85-
8680
path, err := getPath(w.config.LocalDir, ev)
8781
if err != nil {
8882
w.config.Logger.Errorf("failed to get %s path: %v", ev.Key, err)
@@ -100,22 +94,6 @@ func (w *Listener) processNextEvent(ev *event.Notification) {
10094
}
10195
}
10296

103-
func (w *Listener) shouldIgnore(ev *event.Notification) bool {
104-
for _, kind := range w.config.ExcludeKind {
105-
if strings.Compare(strings.ToLower(kind), ev.Kind) == 0 {
106-
return true
107-
}
108-
}
109-
110-
for _, obj := range w.config.ExcludeObject {
111-
if strings.Compare(strings.ToLower(obj), ev.Kind+":"+ev.Key) == 0 {
112-
return true
113-
}
114-
}
115-
116-
return w.config.DryRun
117-
}
118-
11997
func getPath(root string, ev *event.Notification) (string, error) {
12098
filename := ev.Kind + "-" + filepath.Base(ev.Key) + ".yaml"
12199

@@ -128,6 +106,11 @@ func getPath(root string, ev *event.Notification) (string, error) {
128106
}
129107

130108
func (w *Listener) remove(file string) error {
109+
w.config.Logger.Debugf("Removing %s from disk", file)
110+
if w.config.DryRun {
111+
return nil
112+
}
113+
131114
w.activesLock.Lock()
132115
delete(w.actives, file)
133116
w.activesLock.Unlock()
@@ -140,6 +123,12 @@ func (w *Listener) relativePath(file string) string {
140123
}
141124

142125
func (w *Listener) save(file string, data string) error {
126+
w.config.Logger.Debugf("Saving %s to disk", file)
127+
128+
if w.config.DryRun {
129+
return nil
130+
}
131+
143132
dir := filepath.Clean(filepath.Dir(file))
144133

145134
err := os.MkdirAll(dir, 0700)

0 commit comments

Comments
 (0)