Skip to content

Commit f6f2770

Browse files
committed
address review comments
Signed-off-by: everettraven <[email protected]>
1 parent 10eaf1f commit f6f2770

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

internal/contentmanager/cache/cache.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"errors"
66
"fmt"
77
"io"
8+
"slices"
9+
"strings"
810
"sync"
911
"time"
1012

@@ -39,6 +41,10 @@ type CloserSyncingSource interface {
3941
}
4042

4143
type sourcerer interface {
44+
// Source returns a CloserSyncingSource for the provided
45+
// GroupVersionKind. If the CloserSyncingSource encounters an
46+
// error after having initially synced, it should requeue the
47+
// provided client.Object and call the provided callback function
4248
Source(schema.GroupVersionKind, client.Object, func(context.Context)) (CloserSyncingSource, error)
4349
}
4450

@@ -85,6 +91,11 @@ func (c *cache) Close() error {
8591
errs = append(errs, err)
8692
}
8793
}
94+
95+
slices.SortFunc(errs, func(a, b error) int {
96+
return strings.Compare(a.Error(), b.Error())
97+
})
98+
8899
return errors.Join(errs...)
89100
}
90101

@@ -132,11 +143,19 @@ func (c *cache) startNewSources(ctx context.Context, gvks sets.Set[schema.GroupV
132143
}
133144
}
134145

146+
slices.SortFunc(sourcesErrors, func(a, b error) int {
147+
return strings.Compare(a.Error(), b.Error())
148+
})
149+
135150
return errors.Join(sourcesErrors...)
136151
}
137152

138153
func (c *cache) startNewSource(ctx context.Context, gvk schema.GroupVersionKind, watcher Watcher) (CloserSyncingSource, error) {
139154
s, err := c.sourcerer.Source(gvk, c.owner, func(ctx context.Context) {
155+
// this callback function ensures that we remove the source from the
156+
// cache if it encounters an error after it initially synced successfully
157+
c.mu.Lock()
158+
defer c.mu.Unlock()
140159
err := c.removeSource(gvk)
141160
if err != nil {
142161
logr := log.FromContext(ctx)
@@ -180,6 +199,11 @@ func (c *cache) removeStaleSources(gvks sets.Set[schema.GroupVersionKind]) error
180199
removeErrs = append(removeErrs, err)
181200
}
182201
}
202+
203+
slices.SortFunc(removeErrs, func(a, b error) int {
204+
return strings.Compare(a.Error(), b.Error())
205+
})
206+
183207
return errors.Join(removeErrs...)
184208
}
185209

internal/contentmanager/source/dynamicsource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (dis *dynamicInformerSource) Start(ctx context.Context, q workqueue.TypedRa
112112
// We won't be able to update the ClusterExtension status
113113
// conditions so instead force a requeue if we
114114
// have previously synced and then errored
115-
q.Add(reconcile.Request{
115+
defer q.Add(reconcile.Request{
116116
NamespacedName: types.NamespacedName{
117117
Name: dis.cfg.Owner.GetName(),
118118
},
@@ -139,7 +139,7 @@ func (dis *dynamicInformerSource) Start(ctx context.Context, q workqueue.TypedRa
139139
close(dis.syncedChan)
140140
})
141141

142-
_ = wait.PollUntilContextCancel(dis.informerCtx, time.Second, true, func(ctx context.Context) (bool, error) {
142+
_ = wait.PollUntilContextCancel(dis.informerCtx, time.Second, true, func(_ context.Context) (bool, error) {
143143
if sharedIndexInf.HasSynced() {
144144
syncOnce()
145145
return true, nil

0 commit comments

Comments
 (0)