mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-03 10:22:36 +02:00
* fix: 0.68.0: go panic w/ multiple bases/layers Fixes #623 * fix: 0.64.1+: getOrNil/hasKey fails on Environment.Values with nested maps Fixes #624
51 lines
942 B
Go
51 lines
942 B
Go
package environment
|
|
|
|
import (
|
|
"github.com/imdario/mergo"
|
|
"github.com/roboll/helmfile/pkg/maputil"
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
type Environment struct {
|
|
Name string
|
|
Values map[string]interface{}
|
|
}
|
|
|
|
var EmptyEnvironment Environment
|
|
|
|
func (e Environment) DeepCopy() Environment {
|
|
bytes, err := yaml.Marshal(e.Values)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
var values map[string]interface{}
|
|
if err := yaml.Unmarshal(bytes, &values); err != nil {
|
|
panic(err)
|
|
}
|
|
values, err = maputil.CastKeysToStrings(values)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return Environment{
|
|
Name: e.Name,
|
|
Values: values,
|
|
}
|
|
}
|
|
|
|
func (e *Environment) Merge(other *Environment) (*Environment, error) {
|
|
if e == nil {
|
|
if other != nil {
|
|
copy := other.DeepCopy()
|
|
return ©, nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
copy := e.DeepCopy()
|
|
if other != nil {
|
|
if err := mergo.Merge(©, other, mergo.WithOverride); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return ©, nil
|
|
}
|