feat: add spec definition api with versioning
All checks were successful
arcad/emissary/pipeline/head This commit looks good
arcad/emissary/pipeline/pr-master This commit looks good

This commit is contained in:
2024-03-12 16:22:35 +01:00
parent 0b34b485da
commit f612721b4e
69 changed files with 1468 additions and 273 deletions

View File

@ -9,13 +9,12 @@ import (
"path/filepath"
"forge.cadoles.com/Cadoles/emissary/internal/agent"
"forge.cadoles.com/Cadoles/emissary/internal/spec"
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger"
)
type Controller struct {
trackedSpecRevisions map[spec.Name]int
trackedSpecRevisions map[string]map[string]int
filename string
loaded bool
}
@ -78,36 +77,39 @@ func (c *Controller) specChanged(specs agent.Specs) bool {
return true
}
for name, spec := range specs {
trackedRevision, exists := c.trackedSpecRevisions[name]
for name, specVersions := range specs {
trackedSpecs, exists := c.trackedSpecRevisions[name]
if !exists {
return true
}
if trackedRevision != spec.SpecRevision() {
return true
}
}
for version, spec := range specVersions {
trackedRevision, exists := trackedSpecs[version]
if !exists {
return true
}
for trackedSpecName, trackedRevision := range c.trackedSpecRevisions {
spec, exists := specs[trackedSpecName]
if !exists {
return true
if trackedRevision != spec.SpecRevision() {
return true
}
}
if trackedRevision != spec.SpecRevision() {
return true
}
}
return false
}
func (c *Controller) trackSpecsRevisions(specs agent.Specs) {
c.trackedSpecRevisions = make(map[spec.Name]int)
c.trackedSpecRevisions = make(map[string]map[string]int)
for name, spec := range specs {
c.trackedSpecRevisions[name] = spec.SpecRevision()
for name, specVersions := range specs {
if _, exists := c.trackedSpecRevisions[name]; !exists {
c.trackedSpecRevisions[name] = make(map[string]int)
}
for version, spec := range specVersions {
c.trackedSpecRevisions[name][version] = spec.SpecRevision()
}
}
}
@ -167,7 +169,7 @@ func (c *Controller) writeState(ctx context.Context, state *agent.State) error {
}
name := f.Name()
if err := ioutil.WriteFile(name, data, os.ModePerm); err != nil {
if err := os.WriteFile(name, data, os.ModePerm); err != nil {
return errors.Errorf("cannot write data to temporary file %q: %v", name, err)
}
@ -213,7 +215,7 @@ func (c *Controller) writeState(ctx context.Context, state *agent.State) error {
func NewController(filename string) *Controller {
return &Controller{
filename: filename,
trackedSpecRevisions: make(map[spec.Name]int),
trackedSpecRevisions: make(map[string]map[string]int),
}
}