Files
tomswall/internal/agent/cache.go
T
unkin-agent 9092b463a0
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
Apply agent generations as a pending try with a revert timer
2026-10-05 13:52:32 +11:00

31 lines
678 B
Go

package agent
import (
"os"
"git.unkin.net/unkin/tomswall/internal/tryapply"
)
// Cache persists the last known-good rendered config to disk so the agent can
// keep applying it when the control plane is unreachable (never fail closed).
type Cache struct {
Path string
}
// Write durably stores the raw config bytes.
func (c Cache) Write(raw []byte) error {
return tryapply.WriteFile(c.Path, raw)
}
// Read returns the cached config, or (nil, nil) when no cache exists yet.
func (c Cache) Read() (*RenderedConfig, error) {
raw, err := os.ReadFile(c.Path)
if os.IsNotExist(err) {
return nil, nil
}
if err != nil {
return nil, err
}
return ParseRendered(raw)
}