refactor: update worker processes in EvoBGP to accept dependencies for shared store and job registry. Enhance scheduler, ingest, render, and deploy components to utilize a unified context and improve logging for drift detection. Update architecture documentation to reflect changes in process interactions and worker functionalities.
CI / changes (push) Successful in 5s
CI / go (push) Failing after 9s
CI / openapi (push) Has been skipped
CI / bird2 (push) Has been skipped

This commit is contained in:
Denozordec
2026-04-05 17:42:07 +07:00
parent 5d21f013cf
commit b7968db4e0
22 changed files with 936 additions and 77 deletions
+53 -5
View File
@@ -1,4 +1,3 @@
// Package deploy delivers generated BIRD fragments to evobgp-agent / publishes signed bundles for evobgp-node.
package deploy
import (
@@ -10,18 +9,67 @@ import (
"evobgp/internal/broker"
"evobgp/internal/config"
"evobgp/internal/store"
)
// Run blocks until ctx is cancelled. Reference deployment: worker after render, talks to agent API or shared volume.
func Run(ctx context.Context) {
// Deps enables deploy-side drift logging between published and last-applied revision per speaker.
type Deps struct {
Store store.Backend
}
// Run blocks until ctx is cancelled.
func Run(ctx context.Context, deps *Deps) {
cfg := config.Load()
broker.LogConnect(ctx, cfg.BrokerURL)
if d := strings.TrimSpace(os.Getenv("EVOBGP_BIRD_ACTIVE_DIR")); d != "" {
log.Printf("evobgp-deploy: EVOBGP_BIRD_ACTIVE_DIR=%q (apply handled by API jobs + birddeploy when set on API)", d)
log.Printf("evobgp-deploy: EVOBGP_BIRD_ACTIVE_DIR=%q (apply via API jobs when API has same env)", d)
}
if deps == nil || deps.Store == nil {
runStub(ctx)
return
}
t := time.NewTicker(90 * time.Second)
defer t.Stop()
log.Printf("evobgp-deploy: active (speaker published vs applied drift log)")
for {
select {
case <-ctx.Done():
log.Printf("evobgp-deploy: stopped")
return
case <-t.C:
logDrift(context.Background(), deps.Store)
}
}
}
func logDrift(ctx context.Context, st store.Backend) {
_ = ctx
tenants, err := st.ListTenantIDs()
if err != nil {
log.Printf("evobgp-deploy: list tenants: %v", err)
return
}
for _, tid := range tenants {
for _, sp := range st.ListSpeakersForTenant(tid) {
pub, _, err := st.LatestPublishedRevision(sp.ID)
if err != nil {
continue
}
applied := ""
if sp.LastAppliedRevisionID != nil {
applied = *sp.LastAppliedRevisionID
}
if applied != "" && applied != pub {
log.Printf("evobgp-deploy: drift speaker=%s applied=%s published=%s", sp.ID, applied, pub)
}
}
}
}
func runStub(ctx context.Context) {
t := time.NewTicker(60 * time.Second)
defer t.Stop()
log.Printf("evobgp-deploy: started (orchestration stub; two-phase apply runs in evobgp-api/evobgp-all job worker when EVOBGP_BIRD_ACTIVE_DIR is set)")
log.Printf("evobgp-deploy: idle stub (no store in Deps)")
for {
select {
case <-ctx.Done():