layer1: add namespace snapshot api step 1
This commit is contained in:
+26
-2
@@ -2,6 +2,7 @@ package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -96,10 +97,23 @@ func (nsr *NamespaceResolver) AddNamespace(ns string) bool {
|
||||
return false
|
||||
}
|
||||
nsr.FissionResourceNS[ns] = ns
|
||||
nsr.Logger.Info("dynamically added namespace to resolver", zap.String("namespace", ns))
|
||||
if nsr.Logger != nil {
|
||||
nsr.Logger.Info("dynamically added namespace to resolver", zap.String("namespace", ns))
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Snapshot returns a stable copy of the currently registered resource namespaces.
|
||||
// The returned slice is detached from the internal mutable map and safe to iterate.
|
||||
func (nsr *NamespaceResolver) Snapshot() []string {
|
||||
nsr.mu.RLock()
|
||||
defer nsr.mu.RUnlock()
|
||||
|
||||
namespaces := listNamespaces(nsr.FissionResourceNS)
|
||||
sort.Strings(namespaces)
|
||||
return namespaces
|
||||
}
|
||||
|
||||
func (nsr *NamespaceResolver) FissionNSWithOptions(option ...option) map[string]string {
|
||||
var options options
|
||||
for _, opt := range option {
|
||||
@@ -122,10 +136,20 @@ func (nsr *NamespaceResolver) FissionNSWithOptions(option ...option) map[string]
|
||||
if options.defaultNs && nsr.DefaultNamespace != "" {
|
||||
fissionResourceNS[nsr.DefaultNamespace] = nsr.DefaultNamespace
|
||||
}
|
||||
nsr.Logger.Debug("fission resource namespaces", zap.Any("namespaces", listNamespaces(fissionResourceNS)))
|
||||
if nsr.Logger != nil {
|
||||
nsr.Logger.Debug("fission resource namespaces", zap.Any("namespaces", listNamespaces(fissionResourceNS)))
|
||||
}
|
||||
return fissionResourceNS
|
||||
}
|
||||
|
||||
// SnapshotWithOptions returns a stable slice copy of Fission namespaces after applying
|
||||
// optional builder/function/default namespace expansion.
|
||||
func (nsr *NamespaceResolver) SnapshotWithOptions(option ...option) []string {
|
||||
namespaces := listNamespaces(nsr.FissionNSWithOptions(option...))
|
||||
sort.Strings(namespaces)
|
||||
return namespaces
|
||||
}
|
||||
|
||||
func GetNamespaces() map[string]string {
|
||||
namespaces := make(map[string]string)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user