fix: config fields not generated on first startup (#1016)

* fix: config fields not generated on first startup

* cleanup

* fix reference

* replace yaml module

* remove duplicated fields

* remove yaml.v3 as a direct dependency

* update dependency

* chore
This commit is contained in:
UUBulb
2025-03-03 19:02:25 +08:00
committed by GitHub
parent d972d331e2
commit f1e3613daf
9 changed files with 143 additions and 62 deletions

View File

@@ -5,6 +5,7 @@ import (
"reflect"
"github.com/go-viper/mapstructure/v2"
"sigs.k8s.io/yaml"
)
// TextUnmarshalerHookFunc is a fixed version of mapstructure.TextUnmarshallerHookFunc.
@@ -69,3 +70,21 @@ func TextUnmarshalerHookFunc() mapstructure.DecodeHookFuncType {
return result, nil
}
}
// KubeYAML implements a YAML parser.
type KubeYAML struct{}
// Unmarshal parses the given YAML bytes.
func (p *KubeYAML) Unmarshal(b []byte) (map[string]any, error) {
var out map[string]any
if err := yaml.Unmarshal(b, &out); err != nil {
return nil, err
}
return out, nil
}
// Marshal marshals the given config map to YAML bytes.
func (p *KubeYAML) Marshal(o map[string]any) ([]byte, error) {
return yaml.Marshal(o)
}