layer1: add namespace manager model step 7

This commit is contained in:
Naeel
2026-04-26 09:54:23 +03:00
parent 97b13a13c2
commit ac2638f17d
3 changed files with 198 additions and 0 deletions
+95
View File
@@ -0,0 +1,95 @@
package utils
import "time"
type NamespacePhase string
const (
NamespacePhaseDiscovered NamespacePhase = "discovered"
NamespacePhaseRegistering NamespacePhase = "registering"
NamespacePhaseActive NamespacePhase = "active"
NamespacePhaseDeregistering NamespacePhase = "deregistering"
NamespacePhaseRemoved NamespacePhase = "removed"
NamespacePhaseFailed NamespacePhase = "failed"
)
type NamespaceSource string
const (
NamespaceSourceEnv NamespaceSource = "env"
NamespaceSourceWatcher NamespaceSource = "watcher"
NamespaceSourceBackfill NamespaceSource = "backfill"
)
type NamespaceEventType string
const (
NamespaceEventAdd NamespaceEventType = "add"
NamespaceEventUpdate NamespaceEventType = "update"
NamespaceEventRemove NamespaceEventType = "remove"
NamespaceEventResync NamespaceEventType = "resync"
)
type NamespacePartState struct {
State string
LastError string
UpdatedAt time.Time
}
type NamespaceRecord struct {
Name string
Source NamespaceSource
Labels map[string]string
Phase NamespacePhase
LastError string
Generation int64
UpdatedAt time.Time
RegisteredParts map[string]NamespacePartState
}
type NamespaceEvent struct {
Type NamespaceEventType
Name string
Labels map[string]string
Source NamespaceSource
ObservedAt time.Time
}
func (nr NamespaceRecord) Clone() NamespaceRecord {
clone := nr
clone.Labels = cloneStringMap(nr.Labels)
clone.RegisteredParts = cloneNamespacePartStates(nr.RegisteredParts)
return clone
}
func (nr NamespaceRecord) IsActive() bool {
return nr.Phase == NamespacePhaseActive
}
func (nr NamespaceRecord) IsTerminal() bool {
return nr.Phase == NamespacePhaseRemoved || nr.Phase == NamespacePhaseFailed
}
func cloneStringMap(input map[string]string) map[string]string {
if input == nil {
return nil
}
clone := make(map[string]string, len(input))
for key, value := range input {
clone[key] = value
}
return clone
}
func cloneNamespacePartStates(input map[string]NamespacePartState) map[string]NamespacePartState {
if input == nil {
return nil
}
clone := make(map[string]NamespacePartState, len(input))
for key, value := range input {
clone[key] = value
}
return clone
}