Andrey Smirnov 75a9f3ee9f
feat: use sqlite as secondary resource storage
This pulls in https://github.com/cosi-project/state-sqlite/pull/2

Fixes https://github.com/siderolabs/omni/issues/1770

See https://github.com/siderolabs/omni/issues/1768

Sample migration logs:

```
2025-11-05T11:18:47.340Z        ESC[34mINFOESC[0m       omni/state_sqlite.go:122        migrated resources from BoltDB to SQLite        {"namespace": "metrics"
, "type": "EtcdBackupOverallStatuses.omni.sidero.dev", "count": 1}
2025-11-05T11:18:47.340Z        ESC[34mINFOESC[0m       omni/state_sqlite.go:122        migrated resources from BoltDB to SQLite        {"namespace": "metrics"
, "type": "EtcdBackupStatuses.omni.sidero.dev", "count": 0}
2025-11-05T11:18:47.342Z        ESC[34mINFOESC[0m       omni/state_sqlite.go:122        migrated resources from BoltDB to SQLite        {"namespace": "metrics"
, "type": "MachineStatusLinks.omni.sidero.dev", "count": 2}
2025-11-05T11:18:47.342Z        ESC[34mINFOESC[0m       omni/state_sqlite.go:67 removed old BoltDB database after migration     {"path": "_out/secondary-storag
e/bolt.db"}
```

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
2025-11-05 15:40:24 +04:00

49 lines
1.1 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package operations
import (
"fmt"
"io"
"github.com/cosi-project/runtime/pkg/resource"
"go.yaml.in/yaml/v4"
"github.com/siderolabs/omni/client/pkg/template"
)
// RenderTemplate outputs the rendered template to the given output.
func RenderTemplate(templateReader io.Reader, output io.Writer) error {
tmpl, err := template.Load(templateReader)
if err != nil {
return fmt.Errorf("error loading template: %w", err)
}
if err = tmpl.Validate(); err != nil {
return err
}
resources, err := tmpl.Translate()
if err != nil {
return fmt.Errorf("error rendering template: %w", err)
}
enc := yaml.NewEncoder(output)
enc.SetIndent(2)
for _, r := range resources {
m, err := resource.MarshalYAML(r)
if err != nil {
return fmt.Errorf("error marshaling resource: %w", err)
}
if err = enc.Encode(m); err != nil {
return fmt.Errorf("error encoding resource: %w", err)
}
}
return nil
}