Skip to content

Commit

Permalink
fix(kuma-cp) call eventWriter.Send in separate goroutine (#1695)
Browse files Browse the repository at this point in the history
(cherry picked from commit 0fd45e6)
  • Loading branch information
lobkovilya authored and mergify-bot committed Mar 17, 2021
1 parent decf6ba commit b577f68
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions pkg/plugins/resources/memory/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (
"sync"
"time"

"github.com/kumahq/kuma/pkg/core/resources/registry"
"github.com/kumahq/kuma/pkg/events"

"github.com/kumahq/kuma/pkg/core/resources/model"
"github.com/kumahq/kuma/pkg/core/resources/registry"
"github.com/kumahq/kuma/pkg/core/resources/store"
"github.com/kumahq/kuma/pkg/events"
util_proto "github.com/kumahq/kuma/pkg/util/proto"
)

Expand Down Expand Up @@ -133,11 +132,13 @@ func (c *memoryStore) Create(_ context.Context, r model.Resource, fs ...store.Cr
// persist
c.records = append(c.records, record)
if c.eventWriter != nil {
c.eventWriter.Send(events.ResourceChangedEvent{
Operation: events.Create,
Type: r.GetType(),
Key: model.MetaToResourceKey(r.GetMeta()),
})
go func() {
c.eventWriter.Send(events.ResourceChangedEvent{
Operation: events.Create,
Type: r.GetType(),
Key: model.MetaToResourceKey(r.GetMeta()),
})
}()
}
return nil
}
Expand Down Expand Up @@ -174,11 +175,13 @@ func (c *memoryStore) Update(_ context.Context, r model.Resource, fs ...store.Up

r.SetMeta(meta)
if c.eventWriter != nil {
c.eventWriter.Send(events.ResourceChangedEvent{
Operation: events.Update,
Type: r.GetType(),
Key: model.MetaToResourceKey(r.GetMeta()),
})
go func() {
c.eventWriter.Send(events.ResourceChangedEvent{
Operation: events.Update,
Type: r.GetType(),
Key: model.MetaToResourceKey(r.GetMeta()),
})
}()
}
return nil
}
Expand Down Expand Up @@ -219,14 +222,16 @@ func (c *memoryStore) delete(ctx context.Context, r model.Resource, fs ...store.
}
c.records = append(c.records[:idx], c.records[idx+1:]...)
if c.eventWriter != nil {
c.eventWriter.Send(events.ResourceChangedEvent{
Operation: events.Delete,
Type: r.GetType(),
Key: model.ResourceKey{
Mesh: opts.Mesh,
Name: opts.Name,
},
})
go func() {
c.eventWriter.Send(events.ResourceChangedEvent{
Operation: events.Delete,
Type: r.GetType(),
Key: model.ResourceKey{
Mesh: opts.Mesh,
Name: opts.Name,
},
})
}()
}
return nil
}
Expand Down

0 comments on commit b577f68

Please sign in to comment.