layer1: add namespace bootstrap step 11
This commit is contained in:
@@ -14,6 +14,7 @@ type NamespaceManager interface {
|
||||
Snapshot() []string
|
||||
SnapshotRecords() []NamespaceRecord
|
||||
Get(name string) (NamespaceRecord, bool)
|
||||
Bootstrap(namespaces []string, source NamespaceSource, observedAt time.Time) []NamespaceRecord
|
||||
Subscribe(subscriber NamespaceSubscriber)
|
||||
SnapshotSubscribers() []string
|
||||
Upsert(event NamespaceEvent) NamespaceRecord
|
||||
@@ -40,6 +41,22 @@ func (m *inMemoryNamespaceManager) Subscribe(subscriber NamespaceSubscriber) {
|
||||
m.subs[subscriber.Name()] = subscriber
|
||||
}
|
||||
|
||||
func (m *inMemoryNamespaceManager) Bootstrap(namespaces []string, source NamespaceSource, observedAt time.Time) []NamespaceRecord {
|
||||
records := make([]NamespaceRecord, 0, len(namespaces))
|
||||
for _, namespace := range namespaces {
|
||||
records = append(records, m.Upsert(NamespaceEvent{
|
||||
Type: NamespaceEventAdd,
|
||||
Name: namespace,
|
||||
Source: source,
|
||||
ObservedAt: observedAt,
|
||||
}))
|
||||
}
|
||||
sort.Slice(records, func(i, j int) bool {
|
||||
return records[i].Name < records[j].Name
|
||||
})
|
||||
return records
|
||||
}
|
||||
|
||||
func (m *inMemoryNamespaceManager) SnapshotSubscribers() []string {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
|
||||
Reference in New Issue
Block a user