Review of the two previous commits found the split was incomplete in both directions: the checks moved off the file load path were still enforced anywhere the value could enter the system, and the fold reached only one of the three overlay paths. A stale database-owned TOML value could still stop archie-state-store. The process seeds every control-plane resource from the same file config on a fresh database, and the seed runs the resource's own validator; three of the five values the loader now accepts aborted the boot there (verified by booting RunStateStore before the fix). A seed that does not validate is now SKIPPED and reported instead of fatal: the resource stays absent, so the file's value is the one in effect and editing config.toml is still the fix -- the daemon and the Gateway are where it fails closed, at boot.runtimeConfig. The resource validators were weaker than configuration.Validate for exactly the fields the split reclassified, so a value the file path used to refuse at load became storable in the database, and then un-fixable by editing config.toml. The trigger enum and the test-glob rule now come from the configuration package rather than being restated, the container image is required there as it is in the file, and a table test ties the two layers together value by value. The directory form of -config-overlay kept the archie-core-e2e2 failure: it decoded each overlay file straight into the populated config, so a map-valued entry it only partly addressed still cleared the fields it did not name. Both the overlay layer's main file and its feature files now fold, which is what Loader.Dir's documented parity with Loader.Overlay has always claimed. The overlay file's key report is derived from the apply's own view of the file as well as the file decode's, because TOML matches keys case-insensitively and the fold's yaml decode does not: a key only the file decode matched was consumed by the report and dropped by the apply, a silent no-op that worked in the base file. Tests: the state-store boot is asserted against the real process, the directory overlay and the case-mismatched key each have one, and ImportConfig pins that a refused seed is not stored.
110 lines
4.8 KiB
Go
110 lines
4.8 KiB
Go
package controlplane
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
|
)
|
|
|
|
const (
|
|
RepositoryPoliciesKind = "repository-policies"
|
|
ChannelSettingsKind = "channel-settings"
|
|
SchedulingPolicyKind = "scheduling-policy"
|
|
ToolSettingsKind = "tool-settings"
|
|
PluginSettingsKind = "plugin-settings"
|
|
ContainerRuntimePoliciesKind = "container-runtime-policies"
|
|
)
|
|
|
|
type schedulingPolicy struct {
|
|
PollInterval string `json:"poll_interval"`
|
|
MaxRetries int `json:"max_retries"`
|
|
Dispatch config.Dispatch `json:"dispatch"`
|
|
}
|
|
|
|
type pluginSettings struct {
|
|
PluginDir string `json:"plugin_dir"`
|
|
ModuleDir string `json:"module_dir"`
|
|
SecretEngineDir string `json:"secret_engine_dir"`
|
|
SkillsDir string `json:"skills_dir"`
|
|
}
|
|
|
|
func operationalDefinitions() []Definition {
|
|
return []Definition{
|
|
{Kind: RepositoryPoliciesKind, Title: "Repository policies", ApplyMode: "restart-required", Schema: arraySchema, Seed: func(cfg config.Config) any { return cfg.Repos }, Validate: validateRepositories},
|
|
{Kind: ChannelSettingsKind, Title: "Channel settings", ApplyMode: "restart-required", Schema: objectSchema, Seed: seedChannels, Validate: validateChannels},
|
|
{Kind: SchedulingPolicyKind, Title: "Scheduling policy", ApplyMode: "restart-required", Schema: objectSchema, Seed: func(cfg config.Config) any {
|
|
return schedulingPolicy{cfg.PollInterval.Std().String(), cfg.MaxRetries, cfg.Dispatch}
|
|
}, Validate: validateScheduling},
|
|
{Kind: ToolSettingsKind, Title: "Tool and MCP settings", ApplyMode: "restart-required", Schema: objectSchema, Seed: seedTools, Validate: validateTools},
|
|
{Kind: PluginSettingsKind, Title: "Plugin settings", ApplyMode: "restart-required", Schema: objectSchema, Seed: func(cfg config.Config) any {
|
|
return pluginSettings{cfg.PluginDir, cfg.ModuleDir, cfg.SecretEngineDir, cfg.SkillsDir}
|
|
}, Validate: func(input []byte) error { return validateAs(input, func(pluginSettings) error { return nil }) }},
|
|
{Kind: ContainerRuntimePoliciesKind, Title: "Container runtime policies", ApplyMode: "restart-required", Schema: objectSchema, Seed: func(cfg config.Config) any { return cfg.Containers }, Validate: validateContainers},
|
|
}
|
|
}
|
|
|
|
func validateRepositories(input []byte) error {
|
|
return validateAs(input, func(repos []config.Repo) error {
|
|
seen := make(map[string]struct{}, len(repos))
|
|
for _, repo := range repos {
|
|
if strings.TrimSpace(repo.Owner) == "" || strings.TrimSpace(repo.Name) == "" {
|
|
return fmt.Errorf("repository owner and name are required")
|
|
}
|
|
if _, exists := seen[repo.FullName()]; exists {
|
|
return fmt.Errorf("duplicate repository %q", repo.FullName())
|
|
}
|
|
seen[repo.FullName()] = struct{}{}
|
|
// The repository-policies resource replaces the file's list, so the
|
|
// rules that judge the file's list have to hold here too. They come
|
|
// from the configuration package rather than being restated: a
|
|
// resource that accepts what configuration.Validate rejects becomes a
|
|
// stored value the operator cannot clear by editing config.toml.
|
|
if err := configuration.ValidateTestGlob(repo.ResolvedTestGlob()); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func validateScheduling(input []byte) error {
|
|
return validateAs(input, func(policy schedulingPolicy) error {
|
|
if policy.MaxRetries < 0 {
|
|
return fmt.Errorf("max_retries must not be negative")
|
|
}
|
|
if policy.PollInterval != "0s" {
|
|
interval, err := time.ParseDuration(policy.PollInterval)
|
|
if err != nil || interval < 0 {
|
|
return fmt.Errorf("poll_interval must be a non-negative duration")
|
|
}
|
|
}
|
|
// Same reason as the repository glob above: RuntimeConfig replaces
|
|
// cfg.Dispatch from this resource, and the daemon refuses to start with a
|
|
// trigger it does not know.
|
|
if !configuration.DispatchTriggerValid(policy.Dispatch.Trigger) {
|
|
return fmt.Errorf("dispatch.trigger %q is not a discovery rule the daemon can poll with", policy.Dispatch.Trigger)
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
func validateContainers(input []byte) error {
|
|
return validateAs(input, func(settings config.ContainerConfig) error {
|
|
if settings.MaxConcurrency < 0 || time.Duration(settings.MaxUptime) < 0 || time.Duration(settings.VolumeTTL) < 0 {
|
|
return fmt.Errorf("container limits must not be negative")
|
|
}
|
|
if settings.PullPolicy != "" && settings.PullPolicy != "missing" && settings.PullPolicy != "always" {
|
|
return fmt.Errorf("pull_policy must be missing or always")
|
|
}
|
|
// The image is required for autonomous workflow workers; the same rule
|
|
// holds for the stored policies that replace the file's [containers].
|
|
if strings.TrimSpace(settings.Image) == "" {
|
|
return fmt.Errorf("container image is required for autonomous workflow workers")
|
|
}
|
|
return nil
|
|
})
|
|
}
|