Skip to content

Commit 43e19c6

Browse files
authored
[cache/linear] Propagate err in SetResources (#1466)
1 parent 0e543df commit 43e19c6

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

pkg/cache/v3/linear.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ func (cache *LinearCache) UpdateResources(toUpdate map[string]types.Resource, to
443443
// SetResources replaces current resources with a new set of resources.
444444
// Given the use of lazy serialization, if most resources are actually the same
445445
// using UpdateResources instead will be much more efficient.
446-
func (cache *LinearCache) SetResources(resources map[string]types.Resource) {
446+
func (cache *LinearCache) SetResources(resources map[string]types.Resource) error {
447447
cache.mu.Lock()
448448
defer cache.mu.Unlock()
449449

@@ -468,7 +468,10 @@ func (cache *LinearCache) SetResources(resources map[string]types.Resource) {
468468

469469
if err := cache.notifyAll(modified); err != nil {
470470
cache.log.Errorf("Failed to notify watches: %s", err.Error())
471+
return err
471472
}
473+
474+
return nil
472475
}
473476

474477
// GetResources returns current resources stored in the cache.

pkg/cache/v3/linear_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,10 @@ func TestLinearSetResources(t *testing.T) {
336336
require.NoError(t, err)
337337
mustBlock(t, w2)
338338

339-
c.SetResources(map[string]types.Resource{
339+
require.NoError(t, c.SetResources(map[string]types.Resource{
340340
"a": testResource("a"),
341341
"b": testResource("b"),
342-
})
342+
}))
343343
resp1 := verifyResponse(t, w1, "1", 1)
344344
updateFromSotwResponse(resp1, &sub1, req1)
345345
resp2 := verifyResponse(t, w2, "1", 2) // the version was only incremented once for all resources
@@ -353,11 +353,11 @@ func TestLinearSetResources(t *testing.T) {
353353
require.NoError(t, err)
354354
mustBlock(t, w2)
355355

356-
c.SetResources(map[string]types.Resource{
356+
require.NoError(t, c.SetResources(map[string]types.Resource{
357357
"a": testResource("aa"),
358358
"b": testResource("b"),
359359
"c": testResource("c"),
360-
})
360+
}))
361361
resp1 = verifyResponse(t, w1, "2", 1)
362362
updateFromSotwResponse(resp1, &sub1, req1)
363363
resp2 = verifyResponse(t, w2, "2", 3)
@@ -371,10 +371,10 @@ func TestLinearSetResources(t *testing.T) {
371371
require.NoError(t, err)
372372
mustBlock(t, w2)
373373

374-
c.SetResources(map[string]types.Resource{
374+
require.NoError(t, c.SetResources(map[string]types.Resource{
375375
"b": testResource("b"),
376376
"c": testResource("c"),
377-
})
377+
}))
378378
mustBlock(t, w1) // removing a resource from the set does not trigger the watch for non full state resources
379379
verifyResponse(t, w2, "3", 2)
380380
}
@@ -387,7 +387,7 @@ func TestLinearGetResources(t *testing.T) {
387387
"b": testResource("b"),
388388
}
389389

390-
c.SetResources(expectedResources)
390+
require.NoError(t, c.SetResources(expectedResources))
391391

392392
resources := c.GetResources()
393393

@@ -778,7 +778,7 @@ func TestLinearDeltaResourceDelete(t *testing.T) {
778778
{Priority: 10},
779779
}}
780780
hashA = hashResource(t, a)
781-
c.SetResources(map[string]types.Resource{"a": a})
781+
require.NoError(t, c.SetResources(map[string]types.Resource{"a": a}))
782782
verifyDeltaResponse(t, w, []resourceInfo{{"a", hashA}}, []string{"b"})
783783
}
784784

0 commit comments

Comments
 (0)