Skip to content

Commit 97bff23

Browse files
committed
run-resourcewatch: Remove command polling
There's no reason for any of these commands to fail locally, and if they did there's no reason they would succeed if retried.
1 parent 6929d09 commit 97bff23

File tree

1 file changed

+26
-51
lines changed

1 file changed

+26
-51
lines changed

pkg/resourcewatch/storage/git_store.go

Lines changed: 26 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import (
77
"path"
88
"path/filepath"
99
"strings"
10-
"time"
11-
12-
"k8s.io/apimachinery/pkg/util/wait"
1310

1411
"k8s.io/kube-openapi/pkg/util/sets"
1512

@@ -80,32 +77,22 @@ func (s *GitStorage) handle(gvr schema.GroupVersionResource, oldObj, obj *unstru
8077

8178
if delete {
8279
klog.Infof("Calling commitRemove for %s", filePath)
83-
// ignore error, we've already reported and we're not doing anything else.
84-
pollErr := wait.PollImmediate(1*time.Second, 15*time.Second, func() (bool, error) {
85-
86-
err := os.Remove(path.Join(s.path, filePath))
87-
if err != nil {
88-
// If the file doesn't exist it means we're deleting a file we haven't previously observed.
89-
// That's probably a collection bug.
90-
// Add it first before removing it.
91-
if os.IsNotExist(err) {
92-
klog.Info("Observed delete of file we haven't previously observed. Adding it first.")
93-
s.handle(gvr, nil, obj, false)
94-
s.handle(gvr, nil, obj, true)
95-
return true, nil
96-
}
80+
err := os.Remove(path.Join(s.path, filePath))
81+
if err != nil {
82+
// If the file doesn't exist it means we're deleting a file we haven't previously observed.
83+
// That's probably a collection bug.
84+
// Add it first before removing it.
85+
if os.IsNotExist(err) {
86+
klog.Info("Observed delete of file we haven't previously observed. Adding it first.")
87+
s.handle(gvr, nil, obj, false)
88+
s.handle(gvr, nil, obj, true)
89+
return
90+
} else {
9791
klog.Errorf("Error removing %q: %v", filePath, err)
98-
return false, err
99-
}
100-
if err := s.commitRemove(filePath, "unknown", ocCommand); err != nil {
101-
klog.Error(err)
102-
return false, nil
10392
}
104-
return true, nil
105-
})
106-
107-
if pollErr != nil {
108-
klog.Errorf("PollWait Error: %v", pollErr)
93+
}
94+
if err := s.commitRemove(filePath, "unknown", ocCommand); err != nil {
95+
klog.Error(err)
10996
}
11097

11198
return
@@ -124,31 +111,19 @@ func (s *GitStorage) handle(gvr schema.GroupVersionResource, oldObj, obj *unstru
124111
modifyingUser = err.Error()
125112
}
126113

127-
// ignore error, we've already reported and we're not doing anything else.
128-
pollErr := wait.PollImmediate(1*time.Second, 15*time.Second, func() (bool, error) {
129-
switch {
130-
case operation == gitOpAdded:
131-
klog.Infof("Calling commitAdd for %s", filePath)
132-
if err := s.commitAdd(filePath, modifyingUser, ocCommand); err != nil {
133-
klog.Error(err)
134-
return false, nil
135-
}
136-
case operation == gitOpModified:
137-
klog.Infof("Calling commitModify for %s", filePath)
138-
if err := s.commitModify(filePath, modifyingUser, ocCommand); err != nil {
139-
klog.Error(err)
140-
return false, nil
141-
}
142-
default:
143-
klog.Errorf("unhandled case for %s", filePath)
144-
145-
return true, nil
114+
switch operation {
115+
case gitOpAdded:
116+
klog.Infof("Calling commitAdd for %s", filePath)
117+
if err := s.commitAdd(filePath, modifyingUser, ocCommand); err != nil {
118+
klog.Error(err)
146119
}
147-
return true, nil
148-
})
149-
150-
if pollErr != nil {
151-
klog.Errorf("PollWait Error: %v", pollErr)
120+
case gitOpModified:
121+
klog.Infof("Calling commitModify for %s", filePath)
122+
if err := s.commitModify(filePath, modifyingUser, ocCommand); err != nil {
123+
klog.Error(err)
124+
}
125+
default:
126+
klog.Errorf("unhandled case for %s: %d", filePath, operation)
152127
}
153128
}
154129

0 commit comments

Comments
 (0)