@@ -2,15 +2,13 @@ package spec
22
33import (
44 "fmt"
5- "os"
65 "strings"
76
8- "github.com/imdario/mergo"
97 "github.com/pkg/errors"
8+ "github.com/wandb/operator/pkg/utils"
109
1110 "helm.sh/helm/v3/pkg/chartutil"
1211 "helm.sh/helm/v3/pkg/strvals"
13- "sigs.k8s.io/yaml"
1412)
1513
1614// Values holds an arbitrary tree-like data structure, such as parsed JSON or
@@ -172,18 +170,8 @@ func (v Values) SetValue(key string, value interface{}) error {
172170// Merge uses deep copy to merge the content of another data structure. It
173171// overrides the existing keys with their associated new values and copies the
174172// missing keys.
175- //
176- // Merge can traverse nested values, it does not deep copy slices and treats
177- // them as scalar values. It does not do any type checking and treats `nil`
178- // values as valid values.
179- //
180- // It retruns an error if the underlying merge utility encounters an error.
181- func (v Values ) Merge (newValues Values ) error {
182- if err := mergo .Merge (& v , newValues , mergo .WithOverride ); err != nil {
183- return errors .Wrapf (err , "can not merge new values" )
184- }
185-
186- return nil
173+ func (v Values ) Merge (newValues Values ) (Values , error ) {
174+ return utils .MergeMapString (v .AsMap (), newValues .AsMap ())
187175}
188176
189177// Coalesce uses Helm-style coalesce to merge the content of another data
@@ -209,38 +197,3 @@ func (v Values) AddHelmValue(key, value string) error {
209197
210198 return nil
211199}
212-
213- // AddFromYAML merges the values from the provided YAML.
214- //
215- // It will return an error if it fails to parse the YAML content or encounters
216- // an error while merging. For more details see `Merge` function.
217- func (v Values ) AddFromYAML (content string ) error {
218- return v .AddFromYAMLBuffer ([]byte (content ))
219- }
220-
221- // AddFromYAMLBuffer merges the values from the provided YAML.
222- //
223- // It will return an error if it fails to parse the YAML content or encounters
224- // an error while merging. For more details see `Merge` function.
225- func (v Values ) AddFromYAMLBuffer (content []byte ) error {
226- newValues := Values {}
227-
228- if err := yaml .Unmarshal (content , & newValues ); err != nil {
229- return errors .Wrapf (err , "failed to parse yaml content" )
230- }
231-
232- return v .Merge (newValues )
233- }
234-
235- // AddFromYAMLFile merges the values from the specified YAML file.
236- //
237- // It will return an error if it fails to read or parse the YAML file or
238- // encounters an error while merging. For more details see `Merge` function.
239- func (v Values ) AddFromYAMLFile (filePath string ) error {
240- fileContent , err := os .ReadFile (filePath )
241- if err != nil {
242- return errors .Wrapf (err , "failed to read file: %s" , filePath )
243- }
244-
245- return v .AddFromYAMLBuffer (fileContent )
246- }
0 commit comments