aboutsummaryrefslogtreecommitdiffstats
path: root/syz-cluster/pkg/app
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2025-04-24 17:04:38 +0200
committerAleksandr Nogikh <nogikh@google.com>2025-04-30 12:32:14 +0000
commit937aafd76e698830e784cf8af849eaae479a6ace (patch)
tree1cf7050e4136b688fbac482cef6b415d181605bf /syz-cluster/pkg/app
parent7c6d304203f2c91fd2927dc473e0b56379eb0dd5 (diff)
syz-cluster: separate global env from global config
Environment variables are convenient for storing values like DB or GCS bucket names, but structured formats are more convenient for the actual service configuration. Separate global-config from global-config-env and add the functionality that queries and parses the config options.
Diffstat (limited to 'syz-cluster/pkg/app')
-rw-r--r--syz-cluster/pkg/app/config.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/syz-cluster/pkg/app/config.go b/syz-cluster/pkg/app/config.go
new file mode 100644
index 000000000..b56d32dbd
--- /dev/null
+++ b/syz-cluster/pkg/app/config.go
@@ -0,0 +1,61 @@
+// Copyright 2025 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+package app
+
+import (
+ "fmt"
+ "os"
+ "sync"
+
+ "gopkg.in/yaml.v3"
+)
+
+type AppConfig struct {
+ // How many workflows are scheduled in parallel.
+ ParallelWorkflows int `yaml:"parallelWorkflows"`
+ // What Lore archives are to be polled for new patch series.
+ LoreArchives []string `yaml:"loreArchives"`
+}
+
+// The project configuration is expected to be mounted at /config/config.yaml.
+
+func Config() (*AppConfig, error) {
+ configLoadedOnce.Do(loadConfig)
+ return config, configErr
+}
+
+const configPath = `/config/config.yaml`
+
+var configLoadedOnce sync.Once
+var configErr error
+var config *AppConfig
+
+func loadConfig() {
+ data, err := os.ReadFile(configPath)
+ if err != nil {
+ configErr = fmt.Errorf("failed to read %q: %w", configPath, err)
+ return
+ }
+ obj := AppConfig{
+ ParallelWorkflows: 1,
+ }
+ err = yaml.Unmarshal(data, &obj)
+ if err != nil {
+ configErr = fmt.Errorf("failed to parse: %w", err)
+ return
+ }
+ err = obj.Validate()
+ if err != nil {
+ configErr = err
+ return
+ }
+ config = &obj
+}
+
+func (c AppConfig) Validate() error {
+ if c.ParallelWorkflows < 0 {
+ return fmt.Errorf("parallelWorkflows must be non-negative")
+ }
+ return nil
+}