Replace interface{} by any (#901)
Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
parent
94fe519ed5
commit
c55fa0f765
|
|
@ -41,7 +41,7 @@ type App struct {
|
||||||
Selectors []string
|
Selectors []string
|
||||||
Args string
|
Args string
|
||||||
ValuesFiles []string
|
ValuesFiles []string
|
||||||
Set map[string]interface{}
|
Set map[string]any
|
||||||
|
|
||||||
FileOrDir string
|
FileOrDir string
|
||||||
|
|
||||||
|
|
@ -1056,7 +1056,7 @@ func (a *App) visitStatesWithSelectorsAndRemoteSupport(fileOrDir string, converg
|
||||||
o(&opts)
|
o(&opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
envvals := []interface{}{}
|
envvals := []any{}
|
||||||
|
|
||||||
for _, v := range a.ValuesFiles {
|
for _, v := range a.ValuesFiles {
|
||||||
envvals = append(envvals, v)
|
envvals = append(envvals, v)
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ func injectFs(app *App, fs *testhelper.TestFs) *App {
|
||||||
if app.Set == nil {
|
if app.Set == nil {
|
||||||
// Consistent behavior with NewGlobalImpl.
|
// Consistent behavior with NewGlobalImpl.
|
||||||
// Doesn't really belong here, but simplest place for it until some refactoring happens
|
// Doesn't really belong here, but simplest place for it until some refactoring happens
|
||||||
app.Set = make(map[string]interface{})
|
app.Set = make(map[string]any)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.fs = fs.ToFileSystem()
|
app.fs = fs.ToFileSystem()
|
||||||
|
|
@ -1019,7 +1019,7 @@ bar: "bar1"
|
||||||
Selectors: []string{},
|
Selectors: []string{},
|
||||||
Env: "default",
|
Env: "default",
|
||||||
ValuesFiles: []string{"overrides.yaml"},
|
ValuesFiles: []string{"overrides.yaml"},
|
||||||
Set: map[string]interface{}{"bar": "bar2", "baz": "baz1"},
|
Set: map[string]any{"bar": "bar2", "baz": "baz1"},
|
||||||
FileOrDir: "helmfile.yaml",
|
FileOrDir: "helmfile.yaml",
|
||||||
}, files)
|
}, files)
|
||||||
|
|
||||||
|
|
@ -1140,7 +1140,7 @@ x:
|
||||||
Selectors: []string{},
|
Selectors: []string{},
|
||||||
Env: testcase.env,
|
Env: testcase.env,
|
||||||
ValuesFiles: []string{"overrides.yaml"},
|
ValuesFiles: []string{"overrides.yaml"},
|
||||||
Set: map[string]interface{}{"x": map[string]interface{}{"hoge": "hoge_set", "fuga": "fuga_set"}},
|
Set: map[string]any{"x": map[string]any{"hoge": "hoge_set", "fuga": "fuga_set"}},
|
||||||
FileOrDir: "helmfile.yaml",
|
FileOrDir: "helmfile.yaml",
|
||||||
}, files)
|
}, files)
|
||||||
|
|
||||||
|
|
@ -1920,15 +1920,15 @@ releases:
|
||||||
// See https://github.com/roboll/helmfile/issues/623
|
// See https://github.com/roboll/helmfile/issues/623
|
||||||
func TestLoadDesiredStateFromYaml_MultiPartTemplate_MergeMapsVariousKeys(t *testing.T) {
|
func TestLoadDesiredStateFromYaml_MultiPartTemplate_MergeMapsVariousKeys(t *testing.T) {
|
||||||
type testcase struct {
|
type testcase struct {
|
||||||
overrideValues interface{}
|
overrideValues any
|
||||||
expected string
|
expected string
|
||||||
}
|
}
|
||||||
testcases := []testcase{
|
testcases := []testcase{
|
||||||
{map[interface{}]interface{}{"foo": "FOO"}, `FOO`},
|
{map[any]any{"foo": "FOO"}, `FOO`},
|
||||||
{map[interface{}]interface{}{"foo": map[interface{}]interface{}{"foo": "FOO"}}, `map[foo:FOO]`},
|
{map[any]any{"foo": map[any]any{"foo": "FOO"}}, `map[foo:FOO]`},
|
||||||
{map[interface{}]interface{}{"foo": map[string]interface{}{"foo": "FOO"}}, `map[foo:FOO]`},
|
{map[any]any{"foo": map[string]any{"foo": "FOO"}}, `map[foo:FOO]`},
|
||||||
{map[interface{}]interface{}{"foo": []interface{}{"foo"}}, `[foo]`},
|
{map[any]any{"foo": []any{"foo"}}, `[foo]`},
|
||||||
{map[interface{}]interface{}{"foo": "FOO"}, `FOO`},
|
{map[any]any{"foo": "FOO"}, `FOO`},
|
||||||
}
|
}
|
||||||
for i := range testcases {
|
for i := range testcases {
|
||||||
tc := testcases[i]
|
tc := testcases[i]
|
||||||
|
|
@ -1960,7 +1960,7 @@ releases:
|
||||||
opts := LoadOpts{
|
opts := LoadOpts{
|
||||||
CalleePath: statePath,
|
CalleePath: statePath,
|
||||||
Environment: state.SubhelmfileEnvironmentSpec{
|
Environment: state.SubhelmfileEnvironmentSpec{
|
||||||
OverrideValues: []interface{}{tc.overrideValues},
|
OverrideValues: []any{tc.overrideValues},
|
||||||
},
|
},
|
||||||
Reverse: true,
|
Reverse: true,
|
||||||
}
|
}
|
||||||
|
|
@ -2017,7 +2017,7 @@ releases:
|
||||||
{stateInline, `{{ if hasKey .Environment.Values "bar" }}{{ .Environment.Values.bar.baz }}{{ end }}`, `BAZ`},
|
{stateInline, `{{ if hasKey .Environment.Values "bar" }}{{ .Environment.Values.bar.baz }}{{ end }}`, `BAZ`},
|
||||||
{stateInline, `{{ if (keys .Environment.Values | has "foo") }}{{ .Environment.Values.foo }}{{ end }}`, `FOO`},
|
{stateInline, `{{ if (keys .Environment.Values | has "foo") }}{{ .Environment.Values.foo }}{{ end }}`, `FOO`},
|
||||||
// See https://github.com/roboll/helmfile/issues/624
|
// See https://github.com/roboll/helmfile/issues/624
|
||||||
// This fails when .Environment.Values.bar is not map[string]interface{}. At the time of #624 it was map[interface{}]interface{}, which sprig's dict funcs don't support.
|
// This fails when .Environment.Values.bar is not map[string]any. At the time of #624 it was map[any]any, which sprig's dict funcs don't support.
|
||||||
{stateInline, `{{ if (keys .Environment.Values | has "bar") }}{{ if (keys .Environment.Values.bar | has "baz") }}{{ .Environment.Values.bar.baz }}{{ end }}{{ end }}`, `BAZ`},
|
{stateInline, `{{ if (keys .Environment.Values | has "bar") }}{{ if (keys .Environment.Values.bar | has "baz") }}{{ .Environment.Values.bar.baz }}{{ end }}{{ end }}`, `BAZ`},
|
||||||
{stateExternal, `{{ getOrNil "foo" .Environment.Values }}`, `FOO`},
|
{stateExternal, `{{ getOrNil "foo" .Environment.Values }}`, `FOO`},
|
||||||
{stateExternal, `{{ getOrNil "baz" (getOrNil "bar" .Environment.Values) }}`, `BAZ`},
|
{stateExternal, `{{ getOrNil "baz" (getOrNil "bar" .Environment.Values) }}`, `BAZ`},
|
||||||
|
|
@ -2035,7 +2035,7 @@ releases:
|
||||||
{stateInline, `{{ if hasKey .Values "bar" }}{{ .Values.bar.baz }}{{ end }}`, `BAZ`},
|
{stateInline, `{{ if hasKey .Values "bar" }}{{ .Values.bar.baz }}{{ end }}`, `BAZ`},
|
||||||
{stateInline, `{{ if (keys .Values | has "foo") }}{{ .Values.foo }}{{ end }}`, `FOO`},
|
{stateInline, `{{ if (keys .Values | has "foo") }}{{ .Values.foo }}{{ end }}`, `FOO`},
|
||||||
// See https://github.com/roboll/helmfile/issues/624
|
// See https://github.com/roboll/helmfile/issues/624
|
||||||
// This fails when .Values.bar is not map[string]interface{}. At the time of #624 it was map[interface{}]interface{}, which sprig's dict funcs don't support.
|
// This fails when .Values.bar is not map[string]any. At the time of #624 it was map[any]any, which sprig's dict funcs don't support.
|
||||||
{stateInline, `{{ if (keys .Values | has "bar") }}{{ if (keys .Values.bar | has "baz") }}{{ .Values.bar.baz }}{{ end }}{{ end }}`, `BAZ`},
|
{stateInline, `{{ if (keys .Values | has "bar") }}{{ if (keys .Values.bar | has "baz") }}{{ .Values.bar.baz }}{{ end }}{{ end }}`, `BAZ`},
|
||||||
{stateExternal, `{{ getOrNil "foo" .Values }}`, `FOO`},
|
{stateExternal, `{{ getOrNil "foo" .Values }}`, `FOO`},
|
||||||
{stateExternal, `{{ getOrNil "baz" (getOrNil "bar" .Values) }}`, `BAZ`},
|
{stateExternal, `{{ getOrNil "baz" (getOrNil "bar" .Values) }}`, `BAZ`},
|
||||||
|
|
@ -4204,9 +4204,9 @@ releases:
|
||||||
value: val-{{"{{ .Release.Name }}"}}
|
value: val-{{"{{ .Release.Name }}"}}
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
expectedValues := []interface{}{
|
expectedValues := []any{
|
||||||
map[string]interface{}{"val1": "zipkin"},
|
map[string]any{"val1": "zipkin"},
|
||||||
map[string]interface{}{"val2": "val2"}}
|
map[string]any{"val2": "val2"}}
|
||||||
expectedSetValues := []state.SetValue{
|
expectedSetValues := []state.SetValue{
|
||||||
{Name: "name-zipkin", Value: "val-zipkin"},
|
{Name: "name-zipkin", Value: "val-zipkin"},
|
||||||
{Name: "name", Value: "val"}}
|
{Name: "name", Value: "val"}}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ type ConfigProvider interface {
|
||||||
Namespace() string
|
Namespace() string
|
||||||
Chart() string
|
Chart() string
|
||||||
Selectors() []string
|
Selectors() []string
|
||||||
StateValuesSet() map[string]interface{}
|
StateValuesSet() map[string]any
|
||||||
StateValuesFiles() []string
|
StateValuesFiles() []string
|
||||||
Env() string
|
Env() string
|
||||||
|
|
||||||
|
|
@ -266,7 +266,7 @@ type ListConfigProvider interface {
|
||||||
SkipCharts() bool
|
SkipCharts() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type CacheConfigProvider interface{}
|
type CacheConfigProvider any
|
||||||
|
|
||||||
type InitConfigProvider interface {
|
type InitConfigProvider interface {
|
||||||
Force() bool
|
Force() bool
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ func (r *desiredStateLoader) renderPrestate(firstPassEnv, overrode *environment.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return firstPassEnv, nil
|
return firstPassEnv, nil
|
||||||
}
|
}
|
||||||
tmplData := state.NewEnvironmentTemplateData(*initEnv, r.namespace, map[string]interface{}{})
|
tmplData := state.NewEnvironmentTemplateData(*initEnv, r.namespace, map[string]any{})
|
||||||
firstPassRenderer := tmpl.NewFirstPassRenderer(baseDir, tmplData)
|
firstPassRenderer := tmpl.NewFirstPassRenderer(baseDir, tmplData)
|
||||||
|
|
||||||
// parse as much as we can, tolerate errors, this is a preparse
|
// parse as much as we can, tolerate errors, this is a preparse
|
||||||
|
|
@ -72,7 +72,7 @@ type RenderOpts struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *desiredStateLoader) renderTemplatesToYaml(baseDir, filename string, content []byte) (*bytes.Buffer, error) {
|
func (r *desiredStateLoader) renderTemplatesToYaml(baseDir, filename string, content []byte) (*bytes.Buffer, error) {
|
||||||
env := &environment.Environment{Name: r.env, Values: map[string]interface{}(nil)}
|
env := &environment.Environment{Name: r.env, Values: map[string]any(nil)}
|
||||||
|
|
||||||
return r.renderTemplatesToYamlWithEnv(baseDir, filename, content, env, nil)
|
return r.renderTemplatesToYamlWithEnv(baseDir, filename, content, env, nil)
|
||||||
}
|
}
|
||||||
|
|
@ -97,7 +97,7 @@ func (r *desiredStateLoader) twoPassRenderTemplateToYaml(inherited, overrode *en
|
||||||
var (
|
var (
|
||||||
renderingPhase string
|
renderingPhase string
|
||||||
finalEnv *environment.Environment
|
finalEnv *environment.Environment
|
||||||
vals map[string]interface{}
|
vals map[string]any
|
||||||
)
|
)
|
||||||
|
|
||||||
if runtime.V1Mode {
|
if runtime.V1Mode {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
func NewCLIConfigImpl(g *GlobalImpl) error {
|
func NewCLIConfigImpl(g *GlobalImpl) error {
|
||||||
optsSet := g.RawStateValuesSet()
|
optsSet := g.RawStateValuesSet()
|
||||||
if len(optsSet) > 0 {
|
if len(optsSet) > 0 {
|
||||||
set := map[string]interface{}{}
|
set := map[string]any{}
|
||||||
for i := range optsSet {
|
for i := range optsSet {
|
||||||
ops := strings.Split(optsSet[i], ",")
|
ops := strings.Split(optsSet[i], ",")
|
||||||
for j := range ops {
|
for j := range ops {
|
||||||
|
|
|
||||||
|
|
@ -72,19 +72,19 @@ func (g *GlobalOptions) SetLogger(logger *zap.SugaredLogger) {
|
||||||
// GlobalImpl is the global configuration for the Helmfile CLI.
|
// GlobalImpl is the global configuration for the Helmfile CLI.
|
||||||
type GlobalImpl struct {
|
type GlobalImpl struct {
|
||||||
*GlobalOptions
|
*GlobalOptions
|
||||||
set map[string]interface{}
|
set map[string]any
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGlobalImpl creates a new GlobalImpl.
|
// NewGlobalImpl creates a new GlobalImpl.
|
||||||
func NewGlobalImpl(opts *GlobalOptions) *GlobalImpl {
|
func NewGlobalImpl(opts *GlobalOptions) *GlobalImpl {
|
||||||
return &GlobalImpl{
|
return &GlobalImpl{
|
||||||
GlobalOptions: opts,
|
GlobalOptions: opts,
|
||||||
set: make(map[string]interface{}),
|
set: make(map[string]any),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setset sets the set
|
// Setset sets the set
|
||||||
func (g *GlobalImpl) SetSet(set map[string]interface{}) {
|
func (g *GlobalImpl) SetSet(set map[string]any) {
|
||||||
g.set = set
|
g.set = set
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,7 +119,7 @@ func (g *GlobalImpl) Selectors() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// StateValuesSet returns the set
|
// StateValuesSet returns the set
|
||||||
func (g *GlobalImpl) StateValuesSet() map[string]interface{} {
|
func (g *GlobalImpl) StateValuesSet() map[string]any {
|
||||||
return g.set
|
return g.set
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ import (
|
||||||
type Environment struct {
|
type Environment struct {
|
||||||
Name string
|
Name string
|
||||||
KubeContext string
|
KubeContext string
|
||||||
Values map[string]interface{}
|
Values map[string]any
|
||||||
Defaults map[string]interface{}
|
Defaults map[string]any
|
||||||
}
|
}
|
||||||
|
|
||||||
var EmptyEnvironment Environment
|
var EmptyEnvironment Environment
|
||||||
|
|
@ -21,8 +21,8 @@ func New(name string) *Environment {
|
||||||
return &Environment{
|
return &Environment{
|
||||||
Name: name,
|
Name: name,
|
||||||
KubeContext: "",
|
KubeContext: "",
|
||||||
Values: map[string]interface{}{},
|
Values: map[string]any{},
|
||||||
Defaults: map[string]interface{}{},
|
Defaults: map[string]any{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ func (e Environment) DeepCopy() Environment {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
var values map[string]interface{}
|
var values map[string]any
|
||||||
if err := yaml.Unmarshal(valuesBytes, &values); err != nil {
|
if err := yaml.Unmarshal(valuesBytes, &values); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
@ -44,7 +44,7 @@ func (e Environment) DeepCopy() Environment {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
var defaults map[string]interface{}
|
var defaults map[string]any
|
||||||
if err := yaml.Unmarshal(defaultsBytes, &defaults); err != nil {
|
if err := yaml.Unmarshal(defaultsBytes, &defaults); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
@ -78,8 +78,8 @@ func (e *Environment) Merge(other *Environment) (*Environment, error) {
|
||||||
return ©, nil
|
return ©, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Environment) GetMergedValues() (map[string]interface{}, error) {
|
func (e *Environment) GetMergedValues() (map[string]any, error) {
|
||||||
vals := map[string]interface{}{}
|
vals := map[string]any{}
|
||||||
|
|
||||||
if err := mergo.Merge(&vals, e.Defaults, mergo.WithOverride); err != nil {
|
if err := mergo.Merge(&vals, e.Defaults, mergo.WithOverride); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ import (
|
||||||
func TestMerge_OverwriteNilValue_Issue1150(t *testing.T) {
|
func TestMerge_OverwriteNilValue_Issue1150(t *testing.T) {
|
||||||
dst := &Environment{
|
dst := &Environment{
|
||||||
Name: "dst",
|
Name: "dst",
|
||||||
Values: map[string]interface{}{
|
Values: map[string]any{
|
||||||
"components": map[string]interface{}{
|
"components": map[string]any{
|
||||||
"etcd-operator": nil,
|
"etcd-operator": nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -21,9 +21,9 @@ func TestMerge_OverwriteNilValue_Issue1150(t *testing.T) {
|
||||||
|
|
||||||
src := &Environment{
|
src := &Environment{
|
||||||
Name: "src",
|
Name: "src",
|
||||||
Values: map[string]interface{}{
|
Values: map[string]any{
|
||||||
"components": map[string]interface{}{
|
"components": map[string]any{
|
||||||
"etcd-operator": map[string]interface{}{
|
"etcd-operator": map[string]any{
|
||||||
"version": "0.10.3",
|
"version": "0.10.3",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -38,9 +38,9 @@ func TestMerge_OverwriteNilValue_Issue1150(t *testing.T) {
|
||||||
|
|
||||||
actual := merged.Values
|
actual := merged.Values
|
||||||
|
|
||||||
expected := map[string]interface{}{
|
expected := map[string]any{
|
||||||
"components": map[string]interface{}{
|
"components": map[string]any{
|
||||||
"etcd-operator": map[string]interface{}{
|
"etcd-operator": map[string]any{
|
||||||
"version": "0.10.3",
|
"version": "0.10.3",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -55,9 +55,9 @@ func TestMerge_OverwriteNilValue_Issue1150(t *testing.T) {
|
||||||
func TestMerge_OverwriteWithNilValue_Issue1154(t *testing.T) {
|
func TestMerge_OverwriteWithNilValue_Issue1154(t *testing.T) {
|
||||||
dst := &Environment{
|
dst := &Environment{
|
||||||
Name: "dst",
|
Name: "dst",
|
||||||
Values: map[string]interface{}{
|
Values: map[string]any{
|
||||||
"components": map[string]interface{}{
|
"components": map[string]any{
|
||||||
"etcd-operator": map[string]interface{}{
|
"etcd-operator": map[string]any{
|
||||||
"version": "0.10.0",
|
"version": "0.10.0",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -67,9 +67,9 @@ func TestMerge_OverwriteWithNilValue_Issue1154(t *testing.T) {
|
||||||
|
|
||||||
src := &Environment{
|
src := &Environment{
|
||||||
Name: "src",
|
Name: "src",
|
||||||
Values: map[string]interface{}{
|
Values: map[string]any{
|
||||||
"components": map[string]interface{}{
|
"components": map[string]any{
|
||||||
"etcd-operator": map[string]interface{}{
|
"etcd-operator": map[string]any{
|
||||||
"version": "0.10.3",
|
"version": "0.10.3",
|
||||||
},
|
},
|
||||||
"prometheus": nil,
|
"prometheus": nil,
|
||||||
|
|
@ -85,9 +85,9 @@ func TestMerge_OverwriteWithNilValue_Issue1154(t *testing.T) {
|
||||||
|
|
||||||
actual := merged.Values
|
actual := merged.Values
|
||||||
|
|
||||||
expected := map[string]interface{}{
|
expected := map[string]any{
|
||||||
"components": map[string]interface{}{
|
"components": map[string]any{
|
||||||
"etcd-operator": map[string]interface{}{
|
"etcd-operator": map[string]any{
|
||||||
"version": "0.10.3",
|
"version": "0.10.3",
|
||||||
},
|
},
|
||||||
"prometheus": nil,
|
"prometheus": nil,
|
||||||
|
|
|
||||||
|
|
@ -51,11 +51,11 @@ type ExitCoder interface {
|
||||||
// ExitError fulfills both the builtin `error` interface and `ExitCoder`
|
// ExitError fulfills both the builtin `error` interface and `ExitCoder`
|
||||||
type ExitError struct {
|
type ExitError struct {
|
||||||
exitCode int
|
exitCode int
|
||||||
message interface{}
|
message any
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewExitError makes a new *ExitError
|
// NewExitError makes a new *ExitError
|
||||||
func NewExitError(message interface{}, exitCode int) *ExitError {
|
func NewExitError(message any, exitCode int) *ExitError {
|
||||||
return &ExitError{
|
return &ExitError{
|
||||||
exitCode: exitCode,
|
exitCode: exitCode,
|
||||||
message: message,
|
message: message,
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func expect(t *testing.T, a interface{}, b interface{}) {
|
func expect(t *testing.T, a any, b any) {
|
||||||
_, fn, line, _ := runtime.Caller(1)
|
_, fn, line, _ := runtime.Caller(1)
|
||||||
fn = strings.Replace(fn, wd+"/", "", -1)
|
fn = strings.Replace(fn, wd+"/", "", -1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ type Bus struct {
|
||||||
Logger *zap.SugaredLogger
|
Logger *zap.SugaredLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bus *Bus) Trigger(evt string, evtErr error, context map[string]interface{}) (bool, error) {
|
func (bus *Bus) Trigger(evt string, evtErr error, context map[string]any) (bool, error) {
|
||||||
if bus.Runner == nil {
|
if bus.Runner == nil {
|
||||||
bus.Runner = helmexec.ShellRunner{
|
bus.Runner = helmexec.ShellRunner{
|
||||||
Dir: bus.BasePath,
|
Dir: bus.BasePath,
|
||||||
|
|
@ -94,7 +94,7 @@ func (bus *Bus) Trigger(evt string, evtErr error, context map[string]interface{}
|
||||||
|
|
||||||
bus.Logger.Debugf("hook[%s]: stateFilePath=%s, basePath=%s\n", name, bus.StateFilePath, bus.BasePath)
|
bus.Logger.Debugf("hook[%s]: stateFilePath=%s, basePath=%s\n", name, bus.StateFilePath, bus.BasePath)
|
||||||
|
|
||||||
data := map[string]interface{}{
|
data := map[string]any{
|
||||||
"Environment": bus.Env,
|
"Environment": bus.Env,
|
||||||
"Namespace": bus.Namespace,
|
"Namespace": bus.Namespace,
|
||||||
"Event": event{
|
"Event": event{
|
||||||
|
|
|
||||||
|
|
@ -159,7 +159,7 @@ func TestTrigger(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bus.Runner = &runner{}
|
bus.Runner = &runner{}
|
||||||
data := map[string]interface{}{
|
data := map[string]any{
|
||||||
"Release": "myrel",
|
"Release": "myrel",
|
||||||
"HelmfileCommand": "mycmd",
|
"HelmfileCommand": "mycmd",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CastKeysToStrings(s interface{}) (map[string]interface{}, error) {
|
func CastKeysToStrings(s any) (map[string]any, error) {
|
||||||
new := map[string]interface{}{}
|
new := map[string]any{}
|
||||||
switch src := s.(type) {
|
switch src := s.(type) {
|
||||||
case map[interface{}]interface{}:
|
case map[any]any:
|
||||||
for k, v := range src {
|
for k, v := range src {
|
||||||
var strK string
|
var strK string
|
||||||
switch typedK := k.(type) {
|
switch typedK := k.(type) {
|
||||||
|
|
@ -25,7 +25,7 @@ func CastKeysToStrings(s interface{}) (map[string]interface{}, error) {
|
||||||
|
|
||||||
new[strK] = castedV
|
new[strK] = castedV
|
||||||
}
|
}
|
||||||
case map[string]interface{}:
|
case map[string]any:
|
||||||
for k, v := range src {
|
for k, v := range src {
|
||||||
castedV, err := recursivelyStringifyMapKey(v)
|
castedV, err := recursivelyStringifyMapKey(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -38,17 +38,17 @@ func CastKeysToStrings(s interface{}) (map[string]interface{}, error) {
|
||||||
return new, nil
|
return new, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func recursivelyStringifyMapKey(v interface{}) (interface{}, error) {
|
func recursivelyStringifyMapKey(v any) (any, error) {
|
||||||
var castedV interface{}
|
var castedV any
|
||||||
switch typedV := v.(type) {
|
switch typedV := v.(type) {
|
||||||
case map[interface{}]interface{}, map[string]interface{}:
|
case map[any]any, map[string]any:
|
||||||
tmp, err := CastKeysToStrings(typedV)
|
tmp, err := CastKeysToStrings(typedV)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
castedV = tmp
|
castedV = tmp
|
||||||
case []interface{}:
|
case []any:
|
||||||
a := []interface{}{}
|
a := []any{}
|
||||||
for i := range typedV {
|
for i := range typedV {
|
||||||
res, err := recursivelyStringifyMapKey(typedV[i])
|
res, err := recursivelyStringifyMapKey(typedV[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -64,28 +64,28 @@ func recursivelyStringifyMapKey(v interface{}) (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type arg interface {
|
type arg interface {
|
||||||
getMap(map[string]interface{}) map[string]interface{}
|
getMap(map[string]any) map[string]any
|
||||||
set(map[string]interface{}, string)
|
set(map[string]any, string)
|
||||||
}
|
}
|
||||||
|
|
||||||
type keyArg struct {
|
type keyArg struct {
|
||||||
key string
|
key string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a keyArg) getMap(m map[string]interface{}) map[string]interface{} {
|
func (a keyArg) getMap(m map[string]any) map[string]any {
|
||||||
_, ok := m[a.key]
|
_, ok := m[a.key]
|
||||||
if !ok {
|
if !ok {
|
||||||
m[a.key] = map[string]interface{}{}
|
m[a.key] = map[string]any{}
|
||||||
}
|
}
|
||||||
switch t := m[a.key].(type) {
|
switch t := m[a.key].(type) {
|
||||||
case map[string]interface{}:
|
case map[string]any:
|
||||||
return t
|
return t
|
||||||
default:
|
default:
|
||||||
panic(fmt.Errorf("unexpected type: %v(%T)", t, t))
|
panic(fmt.Errorf("unexpected type: %v(%T)", t, t))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a keyArg) set(m map[string]interface{}, value string) {
|
func (a keyArg) set(m map[string]any, value string) {
|
||||||
m[a.key] = value
|
m[a.key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,15 +94,15 @@ type indexedKeyArg struct {
|
||||||
index int
|
index int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a indexedKeyArg) getArray(m map[string]interface{}) []interface{} {
|
func (a indexedKeyArg) getArray(m map[string]any) []any {
|
||||||
_, ok := m[a.key]
|
_, ok := m[a.key]
|
||||||
if !ok {
|
if !ok {
|
||||||
m[a.key] = make([]interface{}, a.index+1)
|
m[a.key] = make([]any, a.index+1)
|
||||||
}
|
}
|
||||||
switch t := m[a.key].(type) {
|
switch t := m[a.key].(type) {
|
||||||
case []interface{}:
|
case []any:
|
||||||
if len(t) <= a.index {
|
if len(t) <= a.index {
|
||||||
t2 := make([]interface{}, a.index+1)
|
t2 := make([]any, a.index+1)
|
||||||
copy(t2, t)
|
copy(t2, t)
|
||||||
t = t2
|
t = t2
|
||||||
}
|
}
|
||||||
|
|
@ -112,20 +112,20 @@ func (a indexedKeyArg) getArray(m map[string]interface{}) []interface{} {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a indexedKeyArg) getMap(m map[string]interface{}) map[string]interface{} {
|
func (a indexedKeyArg) getMap(m map[string]any) map[string]any {
|
||||||
t := a.getArray(m)
|
t := a.getArray(m)
|
||||||
if t[a.index] == nil {
|
if t[a.index] == nil {
|
||||||
t[a.index] = map[string]interface{}{}
|
t[a.index] = map[string]any{}
|
||||||
}
|
}
|
||||||
switch t := t[a.index].(type) {
|
switch t := t[a.index].(type) {
|
||||||
case map[string]interface{}:
|
case map[string]any:
|
||||||
return t
|
return t
|
||||||
default:
|
default:
|
||||||
panic(fmt.Errorf("unexpected type: %v(%T)", t, t))
|
panic(fmt.Errorf("unexpected type: %v(%T)", t, t))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a indexedKeyArg) set(m map[string]interface{}, value string) {
|
func (a indexedKeyArg) set(m map[string]any, value string) {
|
||||||
t := a.getArray(m)
|
t := a.getArray(m)
|
||||||
t[a.index] = value
|
t[a.index] = value
|
||||||
m[a.key] = t
|
m[a.key] = t
|
||||||
|
|
@ -178,7 +178,7 @@ func ParseKey(key string) []string {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func Set(m map[string]interface{}, key []string, value string) {
|
func Set(m map[string]any, key []string, value string) {
|
||||||
if len(key) == 0 {
|
if len(key) == 0 {
|
||||||
panic(fmt.Errorf("bug: unexpected length of key: %d", len(key)))
|
panic(fmt.Errorf("bug: unexpected length of key: %d", len(key)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMapUtil_StrKeys(t *testing.T) {
|
func TestMapUtil_StrKeys(t *testing.T) {
|
||||||
m := map[string]interface{}{
|
m := map[string]any{
|
||||||
"a": []interface{}{
|
"a": []any{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"b": []interface{}{
|
"b": []any{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"c": "C",
|
"c": "C",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -24,10 +24,10 @@ func TestMapUtil_StrKeys(t *testing.T) {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a := r["a"].([]interface{})
|
a := r["a"].([]any)
|
||||||
a0 := a[0].(map[string]interface{})
|
a0 := a[0].(map[string]any)
|
||||||
b := a0["b"].([]interface{})
|
b := a0["b"].([]any)
|
||||||
b0 := b[0].(map[string]interface{})
|
b0 := b[0].(map[string]any)
|
||||||
c := b0["c"]
|
c := b0["c"]
|
||||||
|
|
||||||
if c != "C" {
|
if c != "C" {
|
||||||
|
|
@ -36,11 +36,11 @@ func TestMapUtil_StrKeys(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMapUtil_IFKeys(t *testing.T) {
|
func TestMapUtil_IFKeys(t *testing.T) {
|
||||||
m := map[interface{}]interface{}{
|
m := map[any]any{
|
||||||
"a": []interface{}{
|
"a": []any{
|
||||||
map[interface{}]interface{}{
|
map[any]any{
|
||||||
"b": []interface{}{
|
"b": []any{
|
||||||
map[interface{}]interface{}{
|
map[any]any{
|
||||||
"c": "C",
|
"c": "C",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -53,10 +53,10 @@ func TestMapUtil_IFKeys(t *testing.T) {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
a := r["a"].([]interface{})
|
a := r["a"].([]any)
|
||||||
a0 := a[0].(map[string]interface{})
|
a0 := a[0].(map[string]any)
|
||||||
b := a0["b"].([]interface{})
|
b := a0["b"].([]any)
|
||||||
b0 := b[0].(map[string]interface{})
|
b0 := b[0].(map[string]any)
|
||||||
c := b0["c"]
|
c := b0["c"]
|
||||||
|
|
||||||
if c != "C" {
|
if c != "C" {
|
||||||
|
|
@ -65,13 +65,13 @@ func TestMapUtil_IFKeys(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMapUtil_KeyArg(t *testing.T) {
|
func TestMapUtil_KeyArg(t *testing.T) {
|
||||||
m := map[string]interface{}{}
|
m := map[string]any{}
|
||||||
|
|
||||||
key := []string{"a", "b", "c"}
|
key := []string{"a", "b", "c"}
|
||||||
|
|
||||||
Set(m, key, "C")
|
Set(m, key, "C")
|
||||||
|
|
||||||
c := (((m["a"].(map[string]interface{}))["b"]).(map[string]interface{}))["c"]
|
c := (((m["a"].(map[string]any))["b"]).(map[string]any))["c"]
|
||||||
|
|
||||||
if c != "C" {
|
if c != "C" {
|
||||||
t.Errorf("unexpected c: expected=C, got=%s", c)
|
t.Errorf("unexpected c: expected=C, got=%s", c)
|
||||||
|
|
@ -79,13 +79,13 @@ func TestMapUtil_KeyArg(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMapUtil_IndexedKeyArg(t *testing.T) {
|
func TestMapUtil_IndexedKeyArg(t *testing.T) {
|
||||||
m := map[string]interface{}{}
|
m := map[string]any{}
|
||||||
|
|
||||||
key := []string{"a", "b[0]", "c"}
|
key := []string{"a", "b[0]", "c"}
|
||||||
|
|
||||||
Set(m, key, "C")
|
Set(m, key, "C")
|
||||||
|
|
||||||
c := (((m["a"].(map[string]interface{}))["b"].([]interface{}))[0].(map[string]interface{}))["c"]
|
c := (((m["a"].(map[string]any))["b"].([]any))[0].(map[string]any))["c"]
|
||||||
|
|
||||||
if c != "C" {
|
if c != "C" {
|
||||||
t.Errorf("unexpected c: expected=C, got=%s", c)
|
t.Errorf("unexpected c: expected=C, got=%s", c)
|
||||||
|
|
@ -96,27 +96,27 @@ func TestMapUtil_IndexedKeyArg2(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
stateValuesSet []string
|
stateValuesSet []string
|
||||||
want map[string]interface{}
|
want map[string]any
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "IndexedKeyArg",
|
name: "IndexedKeyArg",
|
||||||
stateValuesSet: []string{"myvalues[0]=HELLO,myvalues[1]=HELMFILE"},
|
stateValuesSet: []string{"myvalues[0]=HELLO,myvalues[1]=HELMFILE"},
|
||||||
want: map[string]interface{}{"myvalues": []interface{}{"HELLO", "HELMFILE"}},
|
want: map[string]any{"myvalues": []any{"HELLO", "HELMFILE"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "two state value",
|
name: "two state value",
|
||||||
stateValuesSet: []string{"myvalues[0]=HELLO,myvalues[1]=HELMFILE", "myvalues[2]=HELLO"},
|
stateValuesSet: []string{"myvalues[0]=HELLO,myvalues[1]=HELMFILE", "myvalues[2]=HELLO"},
|
||||||
want: map[string]interface{}{"myvalues": []interface{}{"HELLO", "HELMFILE", "HELLO"}},
|
want: map[string]any{"myvalues": []any{"HELLO", "HELMFILE", "HELLO"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "different key",
|
name: "different key",
|
||||||
stateValuesSet: []string{"myvalues[0]=HELLO,key2[0]=HELMFILE", "myvalues[1]=HELLO2"},
|
stateValuesSet: []string{"myvalues[0]=HELLO,key2[0]=HELMFILE", "myvalues[1]=HELLO2"},
|
||||||
want: map[string]interface{}{"myvalues": []interface{}{"HELLO", "HELLO2"}, "key2": []interface{}{"HELMFILE"}},
|
want: map[string]any{"myvalues": []any{"HELLO", "HELLO2"}, "key2": []any{"HELMFILE"}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
set := map[string]interface{}{}
|
set := map[string]any{}
|
||||||
for i := range c.stateValuesSet {
|
for i := range c.stateValuesSet {
|
||||||
ops := strings.Split(c.stateValuesSet[i], ",")
|
ops := strings.Split(c.stateValuesSet[i], ",")
|
||||||
for j := range ops {
|
for j := range ops {
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,9 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// checkerFunc is a function that checks the helmState.
|
// checkerFunc is a function that checks the helmState.
|
||||||
type checkerFunc func(string, map[string]interface{}) (bool, error)
|
type checkerFunc func(string, map[string]any) (bool, error)
|
||||||
|
|
||||||
func forbidEnvironmentsWithReleases(filePath string, releaseState map[string]interface{}) (bool, error) {
|
func forbidEnvironmentsWithReleases(filePath string, releaseState map[string]any) (bool, error) {
|
||||||
// forbid environments and releases to be defined at the same yaml part
|
// forbid environments and releases to be defined at the same yaml part
|
||||||
_, hasEnvironments := releaseState["environments"]
|
_, hasEnvironments := releaseState["environments"]
|
||||||
_, hasReleases := releaseState["releases"]
|
_, hasReleases := releaseState["releases"]
|
||||||
|
|
@ -30,7 +30,7 @@ var checkerFuncs = []checkerFunc{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checker is a policy checker for the helmfile state.
|
// Checker is a policy checker for the helmfile state.
|
||||||
func Checker(filePath string, helmState map[string]interface{}) (bool, error) {
|
func Checker(filePath string, helmState map[string]any) (bool, error) {
|
||||||
for _, fn := range checkerFuncs {
|
for _, fn := range checkerFuncs {
|
||||||
if isStrict, err := fn(filePath, helmState); err != nil {
|
if isStrict, err := fn(filePath, helmState); err != nil {
|
||||||
return isStrict, err
|
return isStrict, err
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ func TestForbidEnvironmentsWithReleases(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
filePath string
|
filePath string
|
||||||
v1mode bool
|
v1mode bool
|
||||||
helmState map[string]interface{}
|
helmState map[string]any
|
||||||
expectedErr bool
|
expectedErr bool
|
||||||
isStrict bool
|
isStrict bool
|
||||||
}{
|
}{
|
||||||
|
|
@ -21,8 +21,8 @@ func TestForbidEnvironmentsWithReleases(t *testing.T) {
|
||||||
name: "no error when only releases",
|
name: "no error when only releases",
|
||||||
filePath: "helmfile.yaml",
|
filePath: "helmfile.yaml",
|
||||||
v1mode: false,
|
v1mode: false,
|
||||||
helmState: map[string]interface{}{
|
helmState: map[string]any{
|
||||||
"releases": interface{}(nil),
|
"releases": any(nil),
|
||||||
},
|
},
|
||||||
expectedErr: false,
|
expectedErr: false,
|
||||||
isStrict: false,
|
isStrict: false,
|
||||||
|
|
@ -31,8 +31,8 @@ func TestForbidEnvironmentsWithReleases(t *testing.T) {
|
||||||
name: "no error when only environments",
|
name: "no error when only environments",
|
||||||
filePath: "helmfile.yaml",
|
filePath: "helmfile.yaml",
|
||||||
v1mode: false,
|
v1mode: false,
|
||||||
helmState: map[string]interface{}{
|
helmState: map[string]any{
|
||||||
"environments": map[string]interface{}{},
|
"environments": map[string]any{},
|
||||||
},
|
},
|
||||||
expectedErr: false,
|
expectedErr: false,
|
||||||
isStrict: false,
|
isStrict: false,
|
||||||
|
|
@ -41,9 +41,9 @@ func TestForbidEnvironmentsWithReleases(t *testing.T) {
|
||||||
name: "error when both releases and environments",
|
name: "error when both releases and environments",
|
||||||
filePath: "helmfile.yaml",
|
filePath: "helmfile.yaml",
|
||||||
v1mode: false,
|
v1mode: false,
|
||||||
helmState: map[string]interface{}{
|
helmState: map[string]any{
|
||||||
"environments": interface{}(nil),
|
"environments": any(nil),
|
||||||
"releases": interface{}(nil),
|
"releases": any(nil),
|
||||||
},
|
},
|
||||||
expectedErr: true,
|
expectedErr: true,
|
||||||
isStrict: false,
|
isStrict: false,
|
||||||
|
|
@ -52,9 +52,9 @@ func TestForbidEnvironmentsWithReleases(t *testing.T) {
|
||||||
name: "no error when both releases and environments for plain yaml on v1",
|
name: "no error when both releases and environments for plain yaml on v1",
|
||||||
filePath: "helmfile.yaml",
|
filePath: "helmfile.yaml",
|
||||||
v1mode: true,
|
v1mode: true,
|
||||||
helmState: map[string]interface{}{
|
helmState: map[string]any{
|
||||||
"environments": interface{}(nil),
|
"environments": any(nil),
|
||||||
"releases": interface{}(nil),
|
"releases": any(nil),
|
||||||
},
|
},
|
||||||
expectedErr: false,
|
expectedErr: false,
|
||||||
isStrict: false,
|
isStrict: false,
|
||||||
|
|
|
||||||
|
|
@ -222,7 +222,7 @@ func (c *StateCreator) loadBases(envValues, overrodeEnv *environment.Environment
|
||||||
|
|
||||||
// nolint: unparam
|
// nolint: unparam
|
||||||
func (c *StateCreator) loadEnvValues(st *HelmState, name string, failOnMissingEnv bool, ctxEnv, overrode *environment.Environment) (*environment.Environment, error) {
|
func (c *StateCreator) loadEnvValues(st *HelmState, name string, failOnMissingEnv bool, ctxEnv, overrode *environment.Environment) (*environment.Environment, error) {
|
||||||
envVals := map[string]interface{}{}
|
envVals := map[string]any{}
|
||||||
envSpec, ok := st.Environments[name]
|
envSpec, ok := st.Environments[name]
|
||||||
if ok {
|
if ok {
|
||||||
var err error
|
var err error
|
||||||
|
|
@ -277,7 +277,7 @@ func (c *StateCreator) loadEnvValues(st *HelmState, name string, failOnMissingEn
|
||||||
return newEnv, nil
|
return newEnv, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *StateCreator) scatterGatherEnvSecretFiles(st *HelmState, envSecretFiles []string, envVals map[string]interface{}) error {
|
func (c *StateCreator) scatterGatherEnvSecretFiles(st *HelmState, envSecretFiles []string, envVals map[string]any) error {
|
||||||
var errs []error
|
var errs []error
|
||||||
|
|
||||||
helm := c.getHelm(st)
|
helm := c.getHelm(st)
|
||||||
|
|
@ -286,7 +286,7 @@ func (c *StateCreator) scatterGatherEnvSecretFiles(st *HelmState, envSecretFiles
|
||||||
|
|
||||||
type secretResult struct {
|
type secretResult struct {
|
||||||
id int
|
id int
|
||||||
result map[string]interface{}
|
result map[string]any
|
||||||
err error
|
err error
|
||||||
path string
|
path string
|
||||||
}
|
}
|
||||||
|
|
@ -327,13 +327,13 @@ func (c *StateCreator) scatterGatherEnvSecretFiles(st *HelmState, envSecretFiles
|
||||||
results <- secretResult{secret.id, nil, fmt.Errorf("failed to load environment secrets file \"%s\": %v", secret.path, err), secret.path}
|
results <- secretResult{secret.id, nil, fmt.Errorf("failed to load environment secrets file \"%s\": %v", secret.path, err), secret.path}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
m := map[string]interface{}{}
|
m := map[string]any{}
|
||||||
if err := yaml.Unmarshal(bytes, &m); err != nil {
|
if err := yaml.Unmarshal(bytes, &m); err != nil {
|
||||||
results <- secretResult{secret.id, nil, fmt.Errorf("failed to load environment secrets file \"%s\": %v", secret.path, err), secret.path}
|
results <- secretResult{secret.id, nil, fmt.Errorf("failed to load environment secrets file \"%s\": %v", secret.path, err), secret.path}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// All the nested map key should be string. Otherwise we get strange errors due to that
|
// All the nested map key should be string. Otherwise we get strange errors due to that
|
||||||
// mergo or reflect is unable to merge map[interface{}]interface{} with map[string]interface{} or vice versa.
|
// mergo or reflect is unable to merge map[any]any with map[string]any or vice versa.
|
||||||
// See https://github.com/roboll/helmfile/issues/677
|
// See https://github.com/roboll/helmfile/issues/677
|
||||||
vals, err := maputil.CastKeysToStrings(m)
|
vals, err := maputil.CastKeysToStrings(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -373,10 +373,10 @@ func (c *StateCreator) scatterGatherEnvSecretFiles(st *HelmState, envSecretFiles
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *HelmState) loadValuesEntries(missingFileHandler *string, entries []interface{}, remote *remote.Remote, ctxEnv *environment.Environment, envName string) (map[string]interface{}, error) {
|
func (st *HelmState) loadValuesEntries(missingFileHandler *string, entries []any, remote *remote.Remote, ctxEnv *environment.Environment, envName string) (map[string]any, error) {
|
||||||
var envVals map[string]interface{}
|
var envVals map[string]any
|
||||||
|
|
||||||
valuesEntries := append([]interface{}{}, entries...)
|
valuesEntries := append([]any{}, entries...)
|
||||||
ld := NewEnvironmentValuesLoader(st.storage(), st.fs, st.logger, remote)
|
ld := NewEnvironmentValuesLoader(st.storage(), st.fs, st.logger, remote)
|
||||||
var err error
|
var err error
|
||||||
envVals, err = ld.LoadEnvironmentValues(missingFileHandler, valuesEntries, ctxEnv, envName)
|
envVals, err = ld.LoadEnvironmentValues(missingFileHandler, valuesEntries, ctxEnv, envName)
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ env: {{ .Environment.Name }}
|
||||||
barTextFile := "/example/path/to/bar.txt"
|
barTextFile := "/example/path/to/bar.txt"
|
||||||
barTextContent := []byte("BAR")
|
barTextContent := []byte("BAR")
|
||||||
|
|
||||||
expected := map[string]interface{}{
|
expected := map[string]any{
|
||||||
"foo": "FOO",
|
"foo": "FOO",
|
||||||
"bar": "BAR",
|
"bar": "BAR",
|
||||||
// As the file doesn't have an file extension ".gotmpl", this template expression should not be evaluated
|
// As the file doesn't have an file extension ".gotmpl", this template expression should not be evaluated
|
||||||
|
|
@ -212,7 +212,7 @@ bar: {{ readFile "bar.txt" }}
|
||||||
barTextFile := "/example/path/to/bar.txt"
|
barTextFile := "/example/path/to/bar.txt"
|
||||||
barTextContent := []byte("BAR")
|
barTextContent := []byte("BAR")
|
||||||
|
|
||||||
expected := map[string]interface{}{
|
expected := map[string]any{
|
||||||
"foo": "FOO",
|
"foo": "FOO",
|
||||||
"bar": "BAR",
|
"bar": "BAR",
|
||||||
// As the file doesn't have an file extension ".gotmpl", this template expression should not be evaluated
|
// As the file doesn't have an file extension ".gotmpl", this template expression should not be evaluated
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package state
|
package state
|
||||||
|
|
||||||
type EnvironmentSpec struct {
|
type EnvironmentSpec struct {
|
||||||
Values []interface{} `yaml:"values,omitempty"`
|
Values []any `yaml:"values,omitempty"`
|
||||||
Secrets []string `yaml:"secrets,omitempty"`
|
Secrets []string `yaml:"secrets,omitempty"`
|
||||||
KubeContext string `yaml:"kubeContext,omitempty"`
|
KubeContext string `yaml:"kubeContext,omitempty"`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,11 @@ func NewEnvironmentValuesLoader(storage *Storage, fs *filesystem.FileSystem, log
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ld *EnvironmentValuesLoader) LoadEnvironmentValues(missingFileHandler *string, valuesEntries []interface{}, ctxEnv *environment.Environment, envName string) (map[string]interface{}, error) {
|
func (ld *EnvironmentValuesLoader) LoadEnvironmentValues(missingFileHandler *string, valuesEntries []any, ctxEnv *environment.Environment, envName string) (map[string]any, error) {
|
||||||
result := map[string]interface{}{}
|
result := map[string]any{}
|
||||||
|
|
||||||
for _, entry := range valuesEntries {
|
for _, entry := range valuesEntries {
|
||||||
maps := []interface{}{}
|
maps := []any{}
|
||||||
|
|
||||||
switch strOrMap := entry.(type) {
|
switch strOrMap := entry.(type) {
|
||||||
case string:
|
case string:
|
||||||
|
|
@ -58,27 +58,27 @@ func (ld *EnvironmentValuesLoader) LoadEnvironmentValues(missingFileHandler *str
|
||||||
env = *ctxEnv
|
env = *ctxEnv
|
||||||
}
|
}
|
||||||
|
|
||||||
tmplData := NewEnvironmentTemplateData(env, "", map[string]interface{}{})
|
tmplData := NewEnvironmentTemplateData(env, "", map[string]any{})
|
||||||
r := tmpl.NewFileRenderer(ld.fs, filepath.Dir(f), tmplData)
|
r := tmpl.NewFileRenderer(ld.fs, filepath.Dir(f), tmplData)
|
||||||
bytes, err := r.RenderToBytes(f)
|
bytes, err := r.RenderToBytes(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to load environment values file \"%s\": %v", f, err)
|
return nil, fmt.Errorf("failed to load environment values file \"%s\": %v", f, err)
|
||||||
}
|
}
|
||||||
m := map[string]interface{}{}
|
m := map[string]any{}
|
||||||
if err := yaml.Unmarshal(bytes, &m); err != nil {
|
if err := yaml.Unmarshal(bytes, &m); err != nil {
|
||||||
return nil, fmt.Errorf("failed to load environment values file \"%s\": %v\n\nOffending YAML:\n%s", f, err, bytes)
|
return nil, fmt.Errorf("failed to load environment values file \"%s\": %v\n\nOffending YAML:\n%s", f, err, bytes)
|
||||||
}
|
}
|
||||||
maps = append(maps, m)
|
maps = append(maps, m)
|
||||||
ld.logger.Debugf("envvals_loader: loaded %s:%v", strOrMap, m)
|
ld.logger.Debugf("envvals_loader: loaded %s:%v", strOrMap, m)
|
||||||
}
|
}
|
||||||
case map[interface{}]interface{}, map[string]interface{}:
|
case map[any]any, map[string]any:
|
||||||
maps = append(maps, strOrMap)
|
maps = append(maps, strOrMap)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unexpected type of value: value=%v, type=%T", strOrMap, strOrMap)
|
return nil, fmt.Errorf("unexpected type of value: value=%v, type=%T", strOrMap, strOrMap)
|
||||||
}
|
}
|
||||||
for _, m := range maps {
|
for _, m := range maps {
|
||||||
// All the nested map key should be string. Otherwise we get strange errors due to that
|
// All the nested map key should be string. Otherwise we get strange errors due to that
|
||||||
// mergo or reflect is unable to merge map[interface{}]interface{} with map[string]interface{} or vice versa.
|
// mergo or reflect is unable to merge map[any]any with map[string]any or vice versa.
|
||||||
// See https://github.com/roboll/helmfile/issues/677
|
// See https://github.com/roboll/helmfile/issues/677
|
||||||
vals, err := maputil.CastKeysToStrings(m)
|
vals, err := maputil.CastKeysToStrings(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -29,13 +29,13 @@ func newLoader() *EnvironmentValuesLoader {
|
||||||
func TestEnvValsLoad_SingleValuesFile(t *testing.T) {
|
func TestEnvValsLoad_SingleValuesFile(t *testing.T) {
|
||||||
l := newLoader()
|
l := newLoader()
|
||||||
|
|
||||||
actual, err := l.LoadEnvironmentValues(nil, []interface{}{"testdata/values.5.yaml"}, nil, "")
|
actual, err := l.LoadEnvironmentValues(nil, []any{"testdata/values.5.yaml"}, nil, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := map[string]interface{}{
|
expected := map[string]any{
|
||||||
"affinity": map[string]interface{}{},
|
"affinity": map[string]any{},
|
||||||
}
|
}
|
||||||
|
|
||||||
if diff := cmp.Diff(expected, actual); diff != "" {
|
if diff := cmp.Diff(expected, actual); diff != "" {
|
||||||
|
|
@ -46,10 +46,10 @@ func TestEnvValsLoad_SingleValuesFile(t *testing.T) {
|
||||||
func TestEnvValsLoad_EnvironmentNameFile(t *testing.T) {
|
func TestEnvValsLoad_EnvironmentNameFile(t *testing.T) {
|
||||||
l := newLoader()
|
l := newLoader()
|
||||||
|
|
||||||
expected := map[string]interface{}{
|
expected := map[string]any{
|
||||||
"envName": "test",
|
"envName": "test",
|
||||||
}
|
}
|
||||||
emptyExpected := map[string]interface{}{
|
emptyExpected := map[string]any{
|
||||||
"envName": nil,
|
"envName": nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,7 +57,7 @@ func TestEnvValsLoad_EnvironmentNameFile(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
env *environment.Environment
|
env *environment.Environment
|
||||||
envName string
|
envName string
|
||||||
expected map[string]interface{}
|
expected map[string]any
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "env is nil but envName is not",
|
name: "env is nil but envName is not",
|
||||||
|
|
@ -87,7 +87,7 @@ func TestEnvValsLoad_EnvironmentNameFile(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
actual, err := l.LoadEnvironmentValues(nil, []interface{}{"testdata/values.6.yaml.gotmpl"}, tt.env, tt.envName)
|
actual, err := l.LoadEnvironmentValues(nil, []any{"testdata/values.6.yaml.gotmpl"}, tt.env, tt.envName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -103,12 +103,12 @@ func TestEnvValsLoad_EnvironmentNameFile(t *testing.T) {
|
||||||
func TestEnvValsLoad_SingleValuesFileRemote(t *testing.T) {
|
func TestEnvValsLoad_SingleValuesFileRemote(t *testing.T) {
|
||||||
l := newLoader()
|
l := newLoader()
|
||||||
|
|
||||||
actual, err := l.LoadEnvironmentValues(nil, []interface{}{"git::https://github.com/helm/helm.git@cmd/helm/testdata/output/values.yaml?ref=v3.8.1"}, nil, "")
|
actual, err := l.LoadEnvironmentValues(nil, []any{"git::https://github.com/helm/helm.git@cmd/helm/testdata/output/values.yaml?ref=v3.8.1"}, nil, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := map[string]interface{}{
|
expected := map[string]any{
|
||||||
"name": string("value"),
|
"name": string("value"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,14 +121,14 @@ func TestEnvValsLoad_SingleValuesFileRemote(t *testing.T) {
|
||||||
func TestEnvValsLoad_OverwriteNilValue_Issue1150(t *testing.T) {
|
func TestEnvValsLoad_OverwriteNilValue_Issue1150(t *testing.T) {
|
||||||
l := newLoader()
|
l := newLoader()
|
||||||
|
|
||||||
actual, err := l.LoadEnvironmentValues(nil, []interface{}{"testdata/values.1.yaml", "testdata/values.2.yaml"}, nil, "")
|
actual, err := l.LoadEnvironmentValues(nil, []any{"testdata/values.1.yaml", "testdata/values.2.yaml"}, nil, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := map[string]interface{}{
|
expected := map[string]any{
|
||||||
"components": map[string]interface{}{
|
"components": map[string]any{
|
||||||
"etcd-operator": map[string]interface{}{
|
"etcd-operator": map[string]any{
|
||||||
"version": "0.10.3",
|
"version": "0.10.3",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -143,14 +143,14 @@ func TestEnvValsLoad_OverwriteNilValue_Issue1150(t *testing.T) {
|
||||||
func TestEnvValsLoad_OverwriteWithNilValue_Issue1154(t *testing.T) {
|
func TestEnvValsLoad_OverwriteWithNilValue_Issue1154(t *testing.T) {
|
||||||
l := newLoader()
|
l := newLoader()
|
||||||
|
|
||||||
actual, err := l.LoadEnvironmentValues(nil, []interface{}{"testdata/values.3.yaml", "testdata/values.4.yaml"}, nil, "")
|
actual, err := l.LoadEnvironmentValues(nil, []any{"testdata/values.3.yaml", "testdata/values.4.yaml"}, nil, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := map[string]interface{}{
|
expected := map[string]any{
|
||||||
"components": map[string]interface{}{
|
"components": map[string]any{
|
||||||
"etcd-operator": map[string]interface{}{
|
"etcd-operator": map[string]any{
|
||||||
"version": "0.10.3",
|
"version": "0.10.3",
|
||||||
},
|
},
|
||||||
"prometheus": nil,
|
"prometheus": nil,
|
||||||
|
|
@ -166,14 +166,14 @@ func TestEnvValsLoad_OverwriteWithNilValue_Issue1154(t *testing.T) {
|
||||||
func TestEnvValsLoad_OverwriteEmptyValue_Issue1168(t *testing.T) {
|
func TestEnvValsLoad_OverwriteEmptyValue_Issue1168(t *testing.T) {
|
||||||
l := newLoader()
|
l := newLoader()
|
||||||
|
|
||||||
actual, err := l.LoadEnvironmentValues(nil, []interface{}{"testdata/issues/1168/addons.yaml", "testdata/issues/1168/addons2.yaml"}, nil, "")
|
actual, err := l.LoadEnvironmentValues(nil, []any{"testdata/issues/1168/addons.yaml", "testdata/issues/1168/addons2.yaml"}, nil, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := map[string]interface{}{
|
expected := map[string]any{
|
||||||
"addons": map[string]interface{}{
|
"addons": map[string]any{
|
||||||
"mychart": map[string]interface{}{
|
"mychart": map[string]any{
|
||||||
"skip": false,
|
"skip": false,
|
||||||
"name": "mychart",
|
"name": "mychart",
|
||||||
"namespace": "kube-system",
|
"namespace": "kube-system",
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ func (r ReleaseSpec) ExecuteTemplateExpressions(renderer *tmpl.FileRenderer) (*R
|
||||||
if len(result.ValuesTemplate) > 0 {
|
if len(result.ValuesTemplate) > 0 {
|
||||||
for i, t := range result.ValuesTemplate {
|
for i, t := range result.ValuesTemplate {
|
||||||
switch ts := t.(type) {
|
switch ts := t.(type) {
|
||||||
case map[interface{}]interface{}, map[string]interface{}:
|
case map[any]any, map[string]any:
|
||||||
serialized, err := yaml.Marshal(ts)
|
serialized, err := yaml.Marshal(ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed executing template expressions in release \"%s\".values[%d] = \"%v\": %v", r.Name, i, ts, err)
|
return nil, fmt.Errorf("failed executing template expressions in release \"%s\".values[%d] = \"%v\": %v", r.Name, i, ts, err)
|
||||||
|
|
@ -99,7 +99,7 @@ func (r ReleaseSpec) ExecuteTemplateExpressions(renderer *tmpl.FileRenderer) (*R
|
||||||
return nil, fmt.Errorf("failed executing template expressions in release \"%s\".values[%d] = \"%v\": %v", r.Name, i, string(serialized), err)
|
return nil, fmt.Errorf("failed executing template expressions in release \"%s\".values[%d] = \"%v\": %v", r.Name, i, string(serialized), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var deserialized map[string]interface{}
|
var deserialized map[string]any
|
||||||
|
|
||||||
if err := yaml.Unmarshal(s.Bytes(), &deserialized); err != nil {
|
if err := yaml.Unmarshal(s.Bytes(), &deserialized); err != nil {
|
||||||
return nil, fmt.Errorf("failed executing template expressions in release \"%s\".values[%d] = \"%v\": %v", r.Name, i, ts, err)
|
return nil, fmt.Errorf("failed executing template expressions in release \"%s\".values[%d] = \"%v\": %v", r.Name, i, ts, err)
|
||||||
|
|
@ -114,7 +114,7 @@ func (r ReleaseSpec) ExecuteTemplateExpressions(renderer *tmpl.FileRenderer) (*R
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var newvals []interface{}
|
var newvals []any
|
||||||
newvals = append(newvals, result.ValuesTemplate...)
|
newvals = append(newvals, result.ValuesTemplate...)
|
||||||
result.Values = append(newvals, result.Values...)
|
result.Values = append(newvals, result.Values...)
|
||||||
}
|
}
|
||||||
|
|
@ -127,7 +127,7 @@ func (r ReleaseSpec) ExecuteTemplateExpressions(renderer *tmpl.FileRenderer) (*R
|
||||||
return nil, fmt.Errorf("failed executing template expressions in release \"%s\".values[%d] = \"%s\": %v", r.Name, i, ts, err)
|
return nil, fmt.Errorf("failed executing template expressions in release \"%s\".values[%d] = \"%s\": %v", r.Name, i, ts, err)
|
||||||
}
|
}
|
||||||
result.Values[i] = s.String()
|
result.Values[i] = s.String()
|
||||||
case map[interface{}]interface{}:
|
case map[any]any:
|
||||||
m, err := maputil.CastKeysToStrings(ts)
|
m, err := maputil.CastKeysToStrings(ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed executing template expressions in release \"%s\".values[%d] = \"%s\": %v", r.Name, i, ts, err)
|
return nil, fmt.Errorf("failed executing template expressions in release \"%s\".values[%d] = \"%s\": %v", r.Name, i, ts, err)
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExecuteTemplateExpressions(t *testing.T) {
|
func TestExecuteTemplateExpressions(t *testing.T) {
|
||||||
render := tmpl.NewFileRenderer(filesystem.DefaultFileSystem(), "", map[string]interface{}{
|
render := tmpl.NewFileRenderer(filesystem.DefaultFileSystem(), "", map[string]any{
|
||||||
"Values": map[string]interface{}{
|
"Values": map[string]any{
|
||||||
"foo": map[string]interface{}{
|
"foo": map[string]any{
|
||||||
"releaseName": "foo",
|
"releaseName": "foo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Release": map[string]interface{}{
|
"Release": map[string]any{
|
||||||
"Name": "foo",
|
"Name": "foo",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
@ -32,8 +32,8 @@ func TestExecuteTemplateExpressions(t *testing.T) {
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Chart: "bar",
|
Chart: "bar",
|
||||||
Namespace: "baz",
|
Namespace: "baz",
|
||||||
ValuesTemplate: []interface{}{
|
ValuesTemplate: []any{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"fullnameOverride": "{{ .Values | get (printf \"%s.releaseName\" .Release.Name) .Release.Name }}",
|
"fullnameOverride": "{{ .Values | get (printf \"%s.releaseName\" .Release.Name) .Release.Name }}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -41,5 +41,5 @@ func TestExecuteTemplateExpressions(t *testing.T) {
|
||||||
result, err := rs.ExecuteTemplateExpressions(render)
|
result, err := rs.ExecuteTemplateExpressions(render)
|
||||||
|
|
||||||
require.NoErrorf(t, err, "failed to execute template expressions: %v", err)
|
require.NoErrorf(t, err, "failed to execute template expressions: %v", err)
|
||||||
require.Equalf(t, result.ValuesTemplate[0].(map[string]interface{})["fullnameOverride"], "foo", "failed to execute template expressions")
|
require.Equalf(t, result.ValuesTemplate[0].(map[string]any)["fullnameOverride"], "foo", "failed to execute template expressions")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ type ReleaseSetSpec struct {
|
||||||
DefaultHelmBinary string `yaml:"helmBinary,omitempty"`
|
DefaultHelmBinary string `yaml:"helmBinary,omitempty"`
|
||||||
|
|
||||||
// DefaultValues is the default values to be overrode by environment values and command-line overrides
|
// DefaultValues is the default values to be overrode by environment values and command-line overrides
|
||||||
DefaultValues []interface{} `yaml:"values,omitempty"`
|
DefaultValues []any `yaml:"values,omitempty"`
|
||||||
|
|
||||||
Environments map[string]EnvironmentSpec `yaml:"environments,omitempty"`
|
Environments map[string]EnvironmentSpec `yaml:"environments,omitempty"`
|
||||||
|
|
||||||
|
|
@ -101,8 +101,8 @@ type MissingFileHandlerConfig struct {
|
||||||
// helmStateAlias is helm state alias
|
// helmStateAlias is helm state alias
|
||||||
type helmStateAlias HelmState
|
type helmStateAlias HelmState
|
||||||
|
|
||||||
func (hs *HelmState) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
func (hs *HelmState) UnmarshalYAML(unmarshal func(any) error) error {
|
||||||
helmStateInfo := make(map[string]interface{})
|
helmStateInfo := make(map[string]any)
|
||||||
if err := unmarshal(&helmStateInfo); err != nil {
|
if err := unmarshal(&helmStateInfo); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -134,7 +134,7 @@ type HelmState struct {
|
||||||
// RenderedValues is the helmfile-wide values that is `.Values`
|
// RenderedValues is the helmfile-wide values that is `.Values`
|
||||||
// which is accessible from within the whole helmfile go template.
|
// which is accessible from within the whole helmfile go template.
|
||||||
// Note that this is usually computed by DesiredStateLoader from ReleaseSetSpec.Env
|
// Note that this is usually computed by DesiredStateLoader from ReleaseSetSpec.Env
|
||||||
RenderedValues map[string]interface{}
|
RenderedValues map[string]any
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubHelmfileSpec defines the subhelmfile path and options
|
// SubHelmfileSpec defines the subhelmfile path and options
|
||||||
|
|
@ -151,7 +151,7 @@ type SubHelmfileSpec struct {
|
||||||
|
|
||||||
// SubhelmfileEnvironmentSpec is the environment spec for a subhelmfile
|
// SubhelmfileEnvironmentSpec is the environment spec for a subhelmfile
|
||||||
type SubhelmfileEnvironmentSpec struct {
|
type SubhelmfileEnvironmentSpec struct {
|
||||||
OverrideValues []interface{} `yaml:"values,omitempty"`
|
OverrideValues []any `yaml:"values,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// HelmSpec to defines helmDefault values
|
// HelmSpec to defines helmDefault values
|
||||||
|
|
@ -293,12 +293,12 @@ type ReleaseSpec struct {
|
||||||
Name string `yaml:"name,omitempty"`
|
Name string `yaml:"name,omitempty"`
|
||||||
Namespace string `yaml:"namespace,omitempty"`
|
Namespace string `yaml:"namespace,omitempty"`
|
||||||
Labels map[string]string `yaml:"labels,omitempty"`
|
Labels map[string]string `yaml:"labels,omitempty"`
|
||||||
Values []interface{} `yaml:"values,omitempty"`
|
Values []any `yaml:"values,omitempty"`
|
||||||
Secrets []interface{} `yaml:"secrets,omitempty"`
|
Secrets []any `yaml:"secrets,omitempty"`
|
||||||
SetValues []SetValue `yaml:"set,omitempty"`
|
SetValues []SetValue `yaml:"set,omitempty"`
|
||||||
duration time.Duration
|
duration time.Duration
|
||||||
|
|
||||||
ValuesTemplate []interface{} `yaml:"valuesTemplate,omitempty"`
|
ValuesTemplate []any `yaml:"valuesTemplate,omitempty"`
|
||||||
SetValuesTemplate []SetValue `yaml:"setTemplate,omitempty"`
|
SetValuesTemplate []SetValue `yaml:"setTemplate,omitempty"`
|
||||||
|
|
||||||
// Capabilities.APIVersions
|
// Capabilities.APIVersions
|
||||||
|
|
@ -324,15 +324,15 @@ type ReleaseSpec struct {
|
||||||
|
|
||||||
// These settings requires helm-x integration to work
|
// These settings requires helm-x integration to work
|
||||||
Dependencies []Dependency `yaml:"dependencies,omitempty"`
|
Dependencies []Dependency `yaml:"dependencies,omitempty"`
|
||||||
JSONPatches []interface{} `yaml:"jsonPatches,omitempty"`
|
JSONPatches []any `yaml:"jsonPatches,omitempty"`
|
||||||
StrategicMergePatches []interface{} `yaml:"strategicMergePatches,omitempty"`
|
StrategicMergePatches []any `yaml:"strategicMergePatches,omitempty"`
|
||||||
|
|
||||||
// Transformers is the list of Kustomize transformers
|
// Transformers is the list of Kustomize transformers
|
||||||
//
|
//
|
||||||
// Each item can be a path to a YAML or go template file, or an embedded transformer declaration as a YAML hash.
|
// Each item can be a path to a YAML or go template file, or an embedded transformer declaration as a YAML hash.
|
||||||
// It's often used to add common labels and annotations to your resources.
|
// It's often used to add common labels and annotations to your resources.
|
||||||
// See https://github.com/kubernetes-sigs/kustomize/blob/master/examples/configureBuiltinPlugin.md#configuring-the-builtin-plugins-instead for more information.
|
// See https://github.com/kubernetes-sigs/kustomize/blob/master/examples/configureBuiltinPlugin.md#configuring-the-builtin-plugins-instead for more information.
|
||||||
Transformers []interface{} `yaml:"transformers,omitempty"`
|
Transformers []any `yaml:"transformers,omitempty"`
|
||||||
Adopt []string `yaml:"adopt,omitempty"`
|
Adopt []string `yaml:"adopt,omitempty"`
|
||||||
|
|
||||||
//version of the chart that has really been installed cause desired version may be fuzzy (~2.0.0)
|
//version of the chart that has really been installed cause desired version may be fuzzy (~2.0.0)
|
||||||
|
|
@ -367,7 +367,7 @@ type ReleaseSpec struct {
|
||||||
Inherit Inherits `yaml:"inherit,omitempty"`
|
Inherit Inherits `yaml:"inherit,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Inherits) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
func (r *Inherits) UnmarshalYAML(unmarshal func(any) error) error {
|
||||||
var v0151 []Inherit
|
var v0151 []Inherit
|
||||||
if err := unmarshal(&v0151); err != nil {
|
if err := unmarshal(&v0151); err != nil {
|
||||||
var v0150 Inherit
|
var v0150 Inherit
|
||||||
|
|
@ -1561,10 +1561,10 @@ func (st *HelmState) WriteReleasesValues(helm helmexec.Interface, additionalValu
|
||||||
|
|
||||||
st.logger.Infof("Writing values file %s", outputValuesFile)
|
st.logger.Infof("Writing values file %s", outputValuesFile)
|
||||||
|
|
||||||
merged := map[string]interface{}{}
|
merged := map[string]any{}
|
||||||
|
|
||||||
for _, f := range append(generatedFiles, additionalValues...) {
|
for _, f := range append(generatedFiles, additionalValues...) {
|
||||||
src := map[string]interface{}{}
|
src := map[string]any{}
|
||||||
|
|
||||||
srcBytes, err := st.fs.ReadFile(f)
|
srcBytes, err := st.fs.ReadFile(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -2152,7 +2152,7 @@ func (st *HelmState) SelectReleases(includeTransitiveNeeds bool) ([]Release, err
|
||||||
return rs, nil
|
return rs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func markExcludedReleases(releases []ReleaseSpec, selectors []string, commonLabels map[string]string, values map[string]interface{}, includeTransitiveNeeds bool) ([]Release, error) {
|
func markExcludedReleases(releases []ReleaseSpec, selectors []string, commonLabels map[string]string, values map[string]any, includeTransitiveNeeds bool) ([]Release, error) {
|
||||||
var filteredReleases []Release
|
var filteredReleases []Release
|
||||||
filters := []ReleaseFilter{}
|
filters := []ReleaseFilter{}
|
||||||
for _, label := range selectors {
|
for _, label := range selectors {
|
||||||
|
|
@ -2203,7 +2203,7 @@ func markExcludedReleases(releases []ReleaseSpec, selectors []string, commonLabe
|
||||||
return filteredReleases, nil
|
return filteredReleases, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConditionEnabled(r ReleaseSpec, values map[string]interface{}) (bool, error) {
|
func ConditionEnabled(r ReleaseSpec, values map[string]any) (bool, error) {
|
||||||
var conditionMatch bool
|
var conditionMatch bool
|
||||||
if len(r.Condition) == 0 {
|
if len(r.Condition) == 0 {
|
||||||
return true, nil
|
return true, nil
|
||||||
|
|
@ -2216,7 +2216,7 @@ func ConditionEnabled(r ReleaseSpec, values map[string]interface{}) (bool, error
|
||||||
if v == nil {
|
if v == nil {
|
||||||
panic(fmt.Sprintf("environment values field '%s' is nil", conditionSplit[0]))
|
panic(fmt.Sprintf("environment values field '%s' is nil", conditionSplit[0]))
|
||||||
}
|
}
|
||||||
if v.(map[string]interface{})["enabled"] == true {
|
if v.(map[string]any)["enabled"] == true {
|
||||||
conditionMatch = true
|
conditionMatch = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -2308,7 +2308,7 @@ func (st *HelmState) triggerGlobalReleaseEvent(evt string, evtErr error, helmfil
|
||||||
Logger: st.logger,
|
Logger: st.logger,
|
||||||
Fs: st.fs,
|
Fs: st.fs,
|
||||||
}
|
}
|
||||||
data := map[string]interface{}{
|
data := map[string]any{
|
||||||
"HelmfileCommand": helmfileCmd,
|
"HelmfileCommand": helmfileCmd,
|
||||||
}
|
}
|
||||||
return bus.Trigger(evt, evtErr, data)
|
return bus.Trigger(evt, evtErr, data)
|
||||||
|
|
@ -2346,7 +2346,7 @@ func (st *HelmState) triggerReleaseEvent(evt string, evtErr error, r *ReleaseSpe
|
||||||
Fs: st.fs,
|
Fs: st.fs,
|
||||||
}
|
}
|
||||||
vals := st.Values()
|
vals := st.Values()
|
||||||
data := map[string]interface{}{
|
data := map[string]any{
|
||||||
"Values": vals,
|
"Values": vals,
|
||||||
"Release": r,
|
"Release": r,
|
||||||
"HelmfileCommand": helmfileCmd,
|
"HelmfileCommand": helmfileCmd,
|
||||||
|
|
@ -2730,7 +2730,7 @@ func (st *HelmState) RenderReleaseValuesFileToBytes(release *ReleaseSpec, path s
|
||||||
}
|
}
|
||||||
|
|
||||||
if match {
|
if match {
|
||||||
var rawYaml map[string]interface{}
|
var rawYaml map[string]any
|
||||||
|
|
||||||
if err := yaml.Unmarshal(rawBytes, &rawYaml); err != nil {
|
if err := yaml.Unmarshal(rawBytes, &rawYaml); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -2823,7 +2823,7 @@ func (c MissingFileHandlerConfig) resolveFileOptions() []resolveFileOption {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *HelmState) generateTemporaryReleaseValuesFiles(release *ReleaseSpec, values []interface{}, missingFileHandler *string) ([]string, error) {
|
func (st *HelmState) generateTemporaryReleaseValuesFiles(release *ReleaseSpec, values []any, missingFileHandler *string) ([]string, error) {
|
||||||
generatedFiles := []string{}
|
generatedFiles := []string{}
|
||||||
|
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
|
|
@ -2862,7 +2862,7 @@ func (st *HelmState) generateTemporaryReleaseValuesFiles(release *ReleaseSpec, v
|
||||||
st.logger.Debugf("Successfully generated the value file at %s. produced:\n%s", path, string(yamlBytes))
|
st.logger.Debugf("Successfully generated the value file at %s. produced:\n%s", path, string(yamlBytes))
|
||||||
|
|
||||||
generatedFiles = append(generatedFiles, valfile.Name())
|
generatedFiles = append(generatedFiles, valfile.Name())
|
||||||
case map[interface{}]interface{}, map[string]interface{}:
|
case map[any]any, map[string]any:
|
||||||
valfile, err := createTempValuesFile(release, typedValue)
|
valfile, err := createTempValuesFile(release, typedValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return generatedFiles, err
|
return generatedFiles, err
|
||||||
|
|
@ -2889,7 +2889,7 @@ func (st *HelmState) generateTemporaryReleaseValuesFiles(release *ReleaseSpec, v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *HelmState) generateVanillaValuesFiles(release *ReleaseSpec) ([]string, error) {
|
func (st *HelmState) generateVanillaValuesFiles(release *ReleaseSpec) ([]string, error) {
|
||||||
values := []interface{}{}
|
values := []any{}
|
||||||
for _, v := range release.Values {
|
for _, v := range release.Values {
|
||||||
switch typedValue := v.(type) {
|
switch typedValue := v.(type) {
|
||||||
case string:
|
case string:
|
||||||
|
|
@ -2900,12 +2900,12 @@ func (st *HelmState) generateVanillaValuesFiles(release *ReleaseSpec) ([]string,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
valuesMapSecretsRendered, err := st.valsRuntime.Eval(map[string]interface{}{"values": values})
|
valuesMapSecretsRendered, err := st.valsRuntime.Eval(map[string]any{"values": values})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
valuesSecretsRendered, ok := valuesMapSecretsRendered["values"].([]interface{})
|
valuesSecretsRendered, ok := valuesMapSecretsRendered["values"].([]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("Failed to render values in %s for release %s: type %T isn't supported", st.FilePath, release.Name, valuesMapSecretsRendered["values"])
|
return nil, fmt.Errorf("Failed to render values in %s for release %s: type %T isn't supported", st.FilePath, release.Name, valuesMapSecretsRendered["values"])
|
||||||
}
|
}
|
||||||
|
|
@ -2919,7 +2919,7 @@ func (st *HelmState) generateVanillaValuesFiles(release *ReleaseSpec) ([]string,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *HelmState) generateSecretValuesFiles(helm helmexec.Interface, release *ReleaseSpec, workerIndex int) ([]string, error) {
|
func (st *HelmState) generateSecretValuesFiles(helm helmexec.Interface, release *ReleaseSpec, workerIndex int) ([]string, error) {
|
||||||
var generatedDecryptedFiles []interface{}
|
var generatedDecryptedFiles []any
|
||||||
|
|
||||||
for _, v := range release.Secrets {
|
for _, v := range release.Secrets {
|
||||||
var (
|
var (
|
||||||
|
|
@ -3091,12 +3091,12 @@ func (st *HelmState) setFlags(setValues []SetValue) ([]string, error) {
|
||||||
func renderValsSecrets(e vals.Evaluator, input ...string) ([]string, error) {
|
func renderValsSecrets(e vals.Evaluator, input ...string) ([]string, error) {
|
||||||
output := make([]string, len(input))
|
output := make([]string, len(input))
|
||||||
if len(input) > 0 {
|
if len(input) > 0 {
|
||||||
mapRendered, err := e.Eval(map[string]interface{}{"values": input})
|
mapRendered, err := e.Eval(map[string]any{"values": input})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
rendered, ok := mapRendered["values"].([]interface{})
|
rendered, ok := mapRendered["values"].([]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("type %T isn't supported", mapRendered["values"])
|
return nil, fmt.Errorf("type %T isn't supported", mapRendered["values"])
|
||||||
}
|
}
|
||||||
|
|
@ -3165,12 +3165,12 @@ func escape(value string) string {
|
||||||
|
|
||||||
// MarshalYAML will ensure we correctly marshal SubHelmfileSpec structure correctly so it can be unmarshalled at some
|
// MarshalYAML will ensure we correctly marshal SubHelmfileSpec structure correctly so it can be unmarshalled at some
|
||||||
// future time
|
// future time
|
||||||
func (p SubHelmfileSpec) MarshalYAML() (interface{}, error) {
|
func (p SubHelmfileSpec) MarshalYAML() (any, error) {
|
||||||
type SubHelmfileSpecTmp struct {
|
type SubHelmfileSpecTmp struct {
|
||||||
Path string `yaml:"path,omitempty"`
|
Path string `yaml:"path,omitempty"`
|
||||||
Selectors []string `yaml:"selectors,omitempty"`
|
Selectors []string `yaml:"selectors,omitempty"`
|
||||||
SelectorsInherited bool `yaml:"selectorsInherited,omitempty"`
|
SelectorsInherited bool `yaml:"selectorsInherited,omitempty"`
|
||||||
OverrideValues []interface{} `yaml:"values,omitempty"`
|
OverrideValues []any `yaml:"values,omitempty"`
|
||||||
}
|
}
|
||||||
return &SubHelmfileSpecTmp{
|
return &SubHelmfileSpecTmp{
|
||||||
Path: p.Path,
|
Path: p.Path,
|
||||||
|
|
@ -3182,8 +3182,8 @@ func (p SubHelmfileSpec) MarshalYAML() (interface{}, error) {
|
||||||
|
|
||||||
// UnmarshalYAML will unmarshal the helmfile yaml section and fill the SubHelmfileSpec structure
|
// UnmarshalYAML will unmarshal the helmfile yaml section and fill the SubHelmfileSpec structure
|
||||||
// this is required go-yto keep allowing string scalar for defining helmfile
|
// this is required go-yto keep allowing string scalar for defining helmfile
|
||||||
func (hf *SubHelmfileSpec) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
func (hf *SubHelmfileSpec) UnmarshalYAML(unmarshal func(any) error) error {
|
||||||
var tmp interface{}
|
var tmp any
|
||||||
if err := unmarshal(&tmp); err != nil {
|
if err := unmarshal(&tmp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -3191,7 +3191,7 @@ func (hf *SubHelmfileSpec) UnmarshalYAML(unmarshal func(interface{}) error) erro
|
||||||
switch i := tmp.(type) {
|
switch i := tmp.(type) {
|
||||||
case string: // single path definition without sub items, legacy sub helmfile definition
|
case string: // single path definition without sub items, legacy sub helmfile definition
|
||||||
hf.Path = i
|
hf.Path = i
|
||||||
case map[interface{}]interface{}, map[string]interface{}: // helmfile path with sub section
|
case map[any]any, map[string]any: // helmfile path with sub section
|
||||||
var subHelmfileSpecTmp struct {
|
var subHelmfileSpecTmp struct {
|
||||||
Path string `yaml:"path"`
|
Path string `yaml:"path"`
|
||||||
Selectors []string `yaml:"selectors"`
|
Selectors []string `yaml:"selectors"`
|
||||||
|
|
@ -3391,13 +3391,13 @@ func (st *HelmState) ToYaml() (string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *HelmState) LoadYAMLForEmbedding(release *ReleaseSpec, entries []interface{}, missingFileHandler *string, pathPrefix string) ([]interface{}, error) {
|
func (st *HelmState) LoadYAMLForEmbedding(release *ReleaseSpec, entries []any, missingFileHandler *string, pathPrefix string) ([]any, error) {
|
||||||
var result []interface{}
|
var result []any
|
||||||
|
|
||||||
for _, v := range entries {
|
for _, v := range entries {
|
||||||
switch t := v.(type) {
|
switch t := v.(type) {
|
||||||
case string:
|
case string:
|
||||||
var values map[string]interface{}
|
var values map[string]any
|
||||||
|
|
||||||
paths, skip, err := st.storage().resolveFile(missingFileHandler, "values", pathPrefix+t, st.MissingFileHandlerConfig.resolveFileOptions()...)
|
paths, skip, err := st.storage().resolveFile(missingFileHandler, "values", pathPrefix+t, st.MissingFileHandlerConfig.resolveFileOptions()...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/helmfile/helmfile/pkg/yaml"
|
"github.com/helmfile/helmfile/pkg/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (st *HelmState) Values() map[string]interface{} {
|
func (st *HelmState) Values() map[string]any {
|
||||||
if st.RenderedValues == nil {
|
if st.RenderedValues == nil {
|
||||||
panic("[bug] RenderedValues is nil")
|
panic("[bug] RenderedValues is nil")
|
||||||
}
|
}
|
||||||
|
|
@ -20,7 +20,7 @@ func (st *HelmState) Values() map[string]interface{} {
|
||||||
return st.RenderedValues
|
return st.RenderedValues
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *HelmState) createReleaseTemplateData(release *ReleaseSpec, vals map[string]interface{}) releaseTemplateData {
|
func (st *HelmState) createReleaseTemplateData(release *ReleaseSpec, vals map[string]any) releaseTemplateData {
|
||||||
tmplData := releaseTemplateData{
|
tmplData := releaseTemplateData{
|
||||||
Environment: st.Env,
|
Environment: st.Env,
|
||||||
KubeContext: st.OverrideKubeContext,
|
KubeContext: st.OverrideKubeContext,
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,8 @@ func TestHelmState_executeTemplates(t *testing.T) {
|
||||||
Version: "{{ .Release.Name }}-0.1",
|
Version: "{{ .Release.Name }}-0.1",
|
||||||
Name: "test-app",
|
Name: "test-app",
|
||||||
Namespace: "test-namespace-{{ .Release.Name }}",
|
Namespace: "test-namespace-{{ .Release.Name }}",
|
||||||
ValuesTemplate: []interface{}{"config/{{ .Environment.Name }}/{{ .Release.Name }}/values.yaml"},
|
ValuesTemplate: []any{"config/{{ .Environment.Name }}/{{ .Release.Name }}/values.yaml"},
|
||||||
Secrets: []interface{}{"config/{{ .Environment.Name }}/{{ .Release.Name }}/secrets.yaml"},
|
Secrets: []any{"config/{{ .Environment.Name }}/{{ .Release.Name }}/secrets.yaml"},
|
||||||
Labels: map[string]string{"id": "{{ .Release.Name }}"},
|
Labels: map[string]string{"id": "{{ .Release.Name }}"},
|
||||||
},
|
},
|
||||||
want: ReleaseSpec{
|
want: ReleaseSpec{
|
||||||
|
|
@ -40,8 +40,8 @@ func TestHelmState_executeTemplates(t *testing.T) {
|
||||||
Version: "test-app-0.1",
|
Version: "test-app-0.1",
|
||||||
Name: "test-app",
|
Name: "test-app",
|
||||||
Namespace: "test-namespace-test-app",
|
Namespace: "test-namespace-test-app",
|
||||||
Values: []interface{}{"config/test_env/test-app/values.yaml"},
|
Values: []any{"config/test_env/test-app/values.yaml"},
|
||||||
Secrets: []interface{}{"config/test_env/test-app/secrets.yaml"},
|
Secrets: []any{"config/test_env/test-app/secrets.yaml"},
|
||||||
Labels: map[string]string{"id": "test-app"},
|
Labels: map[string]string{"id": "test-app"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -112,14 +112,14 @@ func TestHelmState_executeTemplates(t *testing.T) {
|
||||||
Verify: nil,
|
Verify: nil,
|
||||||
Name: "app",
|
Name: "app",
|
||||||
Namespace: "dev",
|
Namespace: "dev",
|
||||||
ValuesTemplate: []interface{}{map[string]string{"key": "{{ .Release.Name }}-val0"}},
|
ValuesTemplate: []any{map[string]string{"key": "{{ .Release.Name }}-val0"}},
|
||||||
},
|
},
|
||||||
want: ReleaseSpec{
|
want: ReleaseSpec{
|
||||||
Chart: "test-charts/chart",
|
Chart: "test-charts/chart",
|
||||||
Verify: nil,
|
Verify: nil,
|
||||||
Name: "app",
|
Name: "app",
|
||||||
Namespace: "dev",
|
Namespace: "dev",
|
||||||
Values: []interface{}{map[string]interface{}{"key": "app-val0"}},
|
Values: []any{map[string]any{"key": "app-val0"}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -140,7 +140,7 @@ func TestHelmState_executeTemplates(t *testing.T) {
|
||||||
tt.input,
|
tt.input,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RenderedValues: map[string]interface{}{},
|
RenderedValues: map[string]any{},
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := state.ExecuteTemplates()
|
r, err := state.ExecuteTemplates()
|
||||||
|
|
@ -237,7 +237,7 @@ func TestHelmState_recursiveRefsTemplates(t *testing.T) {
|
||||||
tt.input,
|
tt.input,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RenderedValues: map[string]interface{}{},
|
RenderedValues: map[string]any{},
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := state.ExecuteTemplates()
|
r, err := state.ExecuteTemplates()
|
||||||
|
|
|
||||||
|
|
@ -1350,7 +1350,7 @@ func TestHelmState_SyncReleases(t *testing.T) {
|
||||||
},
|
},
|
||||||
logger: logger,
|
logger: logger,
|
||||||
valsRuntime: valsRuntime,
|
valsRuntime: valsRuntime,
|
||||||
RenderedValues: map[string]interface{}{},
|
RenderedValues: map[string]any{},
|
||||||
}
|
}
|
||||||
if errs := state.SyncReleases(&AffectedReleases{}, tt.helm, []string{}, 1); len(errs) > 0 {
|
if errs := state.SyncReleases(&AffectedReleases{}, tt.helm, []string{}, 1); len(errs) > 0 {
|
||||||
if len(errs) != len(tt.wantErrorMsgs) {
|
if len(errs) != len(tt.wantErrorMsgs) {
|
||||||
|
|
@ -1418,7 +1418,7 @@ func TestHelmState_SyncReleases_MissingValuesFileForUndesiredRelease(t *testing.
|
||||||
release: ReleaseSpec{
|
release: ReleaseSpec{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Chart: "../../foo-bar",
|
Chart: "../../foo-bar",
|
||||||
Values: []interface{}{"noexistent.values.yaml"},
|
Values: []any{"noexistent.values.yaml"},
|
||||||
},
|
},
|
||||||
listResult: ``,
|
listResult: ``,
|
||||||
expectedError: `failed processing release foo: values file matching "noexistent.values.yaml" does not exist in "."`,
|
expectedError: `failed processing release foo: values file matching "noexistent.values.yaml" does not exist in "."`,
|
||||||
|
|
@ -1428,7 +1428,7 @@ func TestHelmState_SyncReleases_MissingValuesFileForUndesiredRelease(t *testing.
|
||||||
release: ReleaseSpec{
|
release: ReleaseSpec{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Chart: "../../foo-bar",
|
Chart: "../../foo-bar",
|
||||||
Values: []interface{}{"noexistent.values.yaml"},
|
Values: []any{"noexistent.values.yaml"},
|
||||||
},
|
},
|
||||||
listResult: `NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
|
listResult: `NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
|
||||||
foo 1 Wed Apr 17 17:39:04 2019 DEPLOYED foo-bar-2.0.4 0.1.0 default`,
|
foo 1 Wed Apr 17 17:39:04 2019 DEPLOYED foo-bar-2.0.4 0.1.0 default`,
|
||||||
|
|
@ -1439,7 +1439,7 @@ func TestHelmState_SyncReleases_MissingValuesFileForUndesiredRelease(t *testing.
|
||||||
release: ReleaseSpec{
|
release: ReleaseSpec{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Chart: "../../foo-bar",
|
Chart: "../../foo-bar",
|
||||||
Values: []interface{}{"noexistent.values.yaml"},
|
Values: []any{"noexistent.values.yaml"},
|
||||||
Installed: &no,
|
Installed: &no,
|
||||||
},
|
},
|
||||||
listResult: `NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
|
listResult: `NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
|
||||||
|
|
@ -1457,7 +1457,7 @@ func TestHelmState_SyncReleases_MissingValuesFileForUndesiredRelease(t *testing.
|
||||||
},
|
},
|
||||||
logger: logger,
|
logger: logger,
|
||||||
valsRuntime: valsRuntime,
|
valsRuntime: valsRuntime,
|
||||||
RenderedValues: map[string]interface{}{},
|
RenderedValues: map[string]any{},
|
||||||
}
|
}
|
||||||
fs := testhelper.NewTestFs(map[string]string{})
|
fs := testhelper.NewTestFs(map[string]string{})
|
||||||
state = injectFs(state, fs)
|
state = injectFs(state, fs)
|
||||||
|
|
@ -1604,7 +1604,7 @@ func TestHelmState_SyncReleasesAffectedRealeases(t *testing.T) {
|
||||||
},
|
},
|
||||||
logger: logger,
|
logger: logger,
|
||||||
valsRuntime: valsRuntime,
|
valsRuntime: valsRuntime,
|
||||||
RenderedValues: map[string]interface{}{},
|
RenderedValues: map[string]any{},
|
||||||
}
|
}
|
||||||
helm := &exectest.Helm{
|
helm := &exectest.Helm{
|
||||||
Lists: map[exectest.ListKey]string{},
|
Lists: map[exectest.ListKey]string{},
|
||||||
|
|
@ -1717,7 +1717,7 @@ func TestGetDeployedVersion(t *testing.T) {
|
||||||
},
|
},
|
||||||
logger: logger,
|
logger: logger,
|
||||||
valsRuntime: valsRuntime,
|
valsRuntime: valsRuntime,
|
||||||
RenderedValues: map[string]interface{}{},
|
RenderedValues: map[string]any{},
|
||||||
}
|
}
|
||||||
|
|
||||||
helm := &exectest.Helm{
|
helm := &exectest.Helm{
|
||||||
|
|
@ -1836,7 +1836,7 @@ func TestHelmState_DiffReleases(t *testing.T) {
|
||||||
},
|
},
|
||||||
logger: logger,
|
logger: logger,
|
||||||
valsRuntime: valsRuntime,
|
valsRuntime: valsRuntime,
|
||||||
RenderedValues: map[string]interface{}{},
|
RenderedValues: map[string]any{},
|
||||||
}
|
}
|
||||||
_, errs := state.DiffReleases(tt.helm, []string{}, 1, false, false, false, []string{}, false, false, false, false, false)
|
_, errs := state.DiffReleases(tt.helm, []string{}, 1, false, false, false, []string{}, false, false, false, false, false)
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
|
|
@ -1879,7 +1879,7 @@ func TestHelmState_DiffFlags(t *testing.T) {
|
||||||
},
|
},
|
||||||
logger: logger,
|
logger: logger,
|
||||||
valsRuntime: valsRuntime,
|
valsRuntime: valsRuntime,
|
||||||
RenderedValues: map[string]interface{}{},
|
RenderedValues: map[string]any{},
|
||||||
}
|
}
|
||||||
for j := range tt.releases {
|
for j := range tt.releases {
|
||||||
flags, _, errs := state.flagsForDiff(tt.helm, &tt.releases[j], false, 1, nil)
|
flags, _, errs := state.flagsForDiff(tt.helm, &tt.releases[j], false, 1, nil)
|
||||||
|
|
@ -1918,8 +1918,8 @@ func TestHelmState_SyncReleasesCleanup(t *testing.T) {
|
||||||
{
|
{
|
||||||
Name: "releaseName",
|
Name: "releaseName",
|
||||||
Chart: "foo",
|
Chart: "foo",
|
||||||
Values: []interface{}{
|
Values: []any{
|
||||||
map[interface{}]interface{}{
|
map[any]any{
|
||||||
"someList": "a,b,c",
|
"someList": "a,b,c",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -1934,8 +1934,8 @@ func TestHelmState_SyncReleasesCleanup(t *testing.T) {
|
||||||
{
|
{
|
||||||
Name: "releaseName",
|
Name: "releaseName",
|
||||||
Chart: "foo",
|
Chart: "foo",
|
||||||
Values: []interface{}{
|
Values: []any{
|
||||||
map[interface{}]interface{}{
|
map[any]any{
|
||||||
"someList": "a,b,c",
|
"someList": "a,b,c",
|
||||||
},
|
},
|
||||||
"someFile",
|
"someFile",
|
||||||
|
|
@ -1956,7 +1956,7 @@ func TestHelmState_SyncReleasesCleanup(t *testing.T) {
|
||||||
},
|
},
|
||||||
logger: logger,
|
logger: logger,
|
||||||
valsRuntime: valsRuntime,
|
valsRuntime: valsRuntime,
|
||||||
RenderedValues: map[string]interface{}{},
|
RenderedValues: map[string]any{},
|
||||||
}
|
}
|
||||||
testfs := testhelper.NewTestFs(map[string]string{
|
testfs := testhelper.NewTestFs(map[string]string{
|
||||||
"/path/to/someFile": `foo: FOO`,
|
"/path/to/someFile": `foo: FOO`,
|
||||||
|
|
@ -2005,8 +2005,8 @@ func TestHelmState_DiffReleasesCleanup(t *testing.T) {
|
||||||
{
|
{
|
||||||
Name: "releaseName",
|
Name: "releaseName",
|
||||||
Chart: "foo",
|
Chart: "foo",
|
||||||
Values: []interface{}{
|
Values: []any{
|
||||||
map[interface{}]interface{}{
|
map[any]any{
|
||||||
"someList": "a,b,c",
|
"someList": "a,b,c",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -2021,8 +2021,8 @@ func TestHelmState_DiffReleasesCleanup(t *testing.T) {
|
||||||
{
|
{
|
||||||
Name: "releaseName",
|
Name: "releaseName",
|
||||||
Chart: "foo",
|
Chart: "foo",
|
||||||
Values: []interface{}{
|
Values: []any{
|
||||||
map[interface{}]interface{}{
|
map[any]any{
|
||||||
"someList": "a,b,c",
|
"someList": "a,b,c",
|
||||||
},
|
},
|
||||||
"someFile",
|
"someFile",
|
||||||
|
|
@ -2043,7 +2043,7 @@ func TestHelmState_DiffReleasesCleanup(t *testing.T) {
|
||||||
},
|
},
|
||||||
logger: logger,
|
logger: logger,
|
||||||
valsRuntime: valsRuntime,
|
valsRuntime: valsRuntime,
|
||||||
RenderedValues: map[string]interface{}{},
|
RenderedValues: map[string]any{},
|
||||||
}
|
}
|
||||||
testfs := testhelper.NewTestFs(map[string]string{
|
testfs := testhelper.NewTestFs(map[string]string{
|
||||||
"/path/to/someFile": `foo: bar
|
"/path/to/someFile": `foo: bar
|
||||||
|
|
@ -2301,7 +2301,7 @@ func TestHelmState_ReleaseStatuses(t *testing.T) {
|
||||||
releases: []ReleaseSpec{
|
releases: []ReleaseSpec{
|
||||||
{
|
{
|
||||||
Name: "error",
|
Name: "error",
|
||||||
Values: []interface{}{
|
Values: []any{
|
||||||
"foo.yaml",
|
"foo.yaml",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -2314,7 +2314,7 @@ func TestHelmState_ReleaseStatuses(t *testing.T) {
|
||||||
releases: []ReleaseSpec{
|
releases: []ReleaseSpec{
|
||||||
{
|
{
|
||||||
Name: "error",
|
Name: "error",
|
||||||
Values: []interface{}{
|
Values: []any{
|
||||||
"foo.yaml",
|
"foo.yaml",
|
||||||
},
|
},
|
||||||
Installed: boolValue(false),
|
Installed: boolValue(false),
|
||||||
|
|
@ -2425,7 +2425,7 @@ func TestConditionEnabled(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
condition string
|
condition string
|
||||||
values map[string]interface{}
|
values map[string]any
|
||||||
want bool
|
want bool
|
||||||
wantErr bool
|
wantErr bool
|
||||||
wantPanic bool
|
wantPanic bool
|
||||||
|
|
@ -2433,8 +2433,8 @@ func TestConditionEnabled(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "enabled",
|
name: "enabled",
|
||||||
condition: "foo.enabled",
|
condition: "foo.enabled",
|
||||||
values: map[string]interface{}{
|
values: map[string]any{
|
||||||
"foo": map[string]interface{}{
|
"foo": map[string]any{
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -2443,8 +2443,8 @@ func TestConditionEnabled(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "disabled",
|
name: "disabled",
|
||||||
condition: "foo.enabled",
|
condition: "foo.enabled",
|
||||||
values: map[string]interface{}{
|
values: map[string]any{
|
||||||
"foo": map[string]interface{}{
|
"foo": map[string]any{
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -2453,8 +2453,8 @@ func TestConditionEnabled(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "missing enabled",
|
name: "missing enabled",
|
||||||
condition: "foo.enabled",
|
condition: "foo.enabled",
|
||||||
values: map[string]interface{}{
|
values: map[string]any{
|
||||||
"foo": map[string]interface{}{
|
"foo": map[string]any{
|
||||||
"something else": false,
|
"something else": false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -2463,7 +2463,7 @@ func TestConditionEnabled(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "foo nil",
|
name: "foo nil",
|
||||||
condition: "foo.enabled",
|
condition: "foo.enabled",
|
||||||
values: map[string]interface{}{
|
values: map[string]any{
|
||||||
"foo": nil,
|
"foo": nil,
|
||||||
},
|
},
|
||||||
wantPanic: true,
|
wantPanic: true,
|
||||||
|
|
@ -2471,7 +2471,7 @@ func TestConditionEnabled(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "foo missing",
|
name: "foo missing",
|
||||||
condition: "foo.enabled",
|
condition: "foo.enabled",
|
||||||
values: map[string]interface{}{},
|
values: map[string]any{},
|
||||||
wantPanic: true,
|
wantPanic: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -2564,7 +2564,7 @@ func TestHelmState_NoReleaseMatched(t *testing.T) {
|
||||||
Releases: releases,
|
Releases: releases,
|
||||||
},
|
},
|
||||||
logger: logger,
|
logger: logger,
|
||||||
RenderedValues: map[string]interface{}{},
|
RenderedValues: map[string]any{},
|
||||||
}
|
}
|
||||||
state.Selectors = []string{tt.labels}
|
state.Selectors = []string{tt.labels}
|
||||||
errs := state.FilterReleases(false)
|
errs := state.FilterReleases(false)
|
||||||
|
|
@ -2725,7 +2725,7 @@ func TestHelmState_Delete(t *testing.T) {
|
||||||
Releases: releases,
|
Releases: releases,
|
||||||
},
|
},
|
||||||
logger: logger,
|
logger: logger,
|
||||||
RenderedValues: map[string]interface{}{},
|
RenderedValues: map[string]any{},
|
||||||
}
|
}
|
||||||
helm := &exectest.Helm{
|
helm := &exectest.Helm{
|
||||||
Lists: map[exectest.ListKey]string{},
|
Lists: map[exectest.ListKey]string{},
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"github.com/helmfile/helmfile/pkg/envvar"
|
"github.com/helmfile/helmfile/pkg/envvar"
|
||||||
)
|
)
|
||||||
|
|
||||||
func createTempValuesFile(release *ReleaseSpec, data interface{}) (*os.File, error) {
|
func createTempValuesFile(release *ReleaseSpec, data any) (*os.File, error) {
|
||||||
p, err := tempValuesFilePath(release, data)
|
p, err := tempValuesFilePath(release, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -28,7 +28,7 @@ func createTempValuesFile(release *ReleaseSpec, data interface{}) (*os.File, err
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func tempValuesFilePath(release *ReleaseSpec, data interface{}) (*string, error) {
|
func tempValuesFilePath(release *ReleaseSpec, data any) (*string, error) {
|
||||||
id, err := generateValuesID(release, data)
|
id, err := generateValuesID(release, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -54,7 +54,7 @@ func tempValuesFilePath(release *ReleaseSpec, data interface{}) (*string, error)
|
||||||
return &d, nil
|
return &d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateValuesID(release *ReleaseSpec, data interface{}) (string, error) {
|
func generateValuesID(release *ReleaseSpec, data any) (string, error) {
|
||||||
var id []string
|
var id []string
|
||||||
|
|
||||||
if release.Namespace != "" {
|
if release.Namespace != "" {
|
||||||
|
|
@ -63,7 +63,7 @@ func generateValuesID(release *ReleaseSpec, data interface{}) (string, error) {
|
||||||
|
|
||||||
id = append(id, release.Name, "values")
|
id = append(id, release.Name, "values")
|
||||||
|
|
||||||
hash, err := HashObject([]interface{}{release, data})
|
hash, err := HashObject([]any{release, data})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
@ -73,7 +73,7 @@ func generateValuesID(release *ReleaseSpec, data interface{}) (string, error) {
|
||||||
return strings.Join(id, "-"), nil
|
return strings.Join(id, "-"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func HashObject(obj interface{}) (string, error) {
|
func HashObject(obj any) (string, error) {
|
||||||
hash := fnv.New32a()
|
hash := fnv.New32a()
|
||||||
|
|
||||||
hash.Reset()
|
hash.Reset()
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ func TestGenerateID(t *testing.T) {
|
||||||
type testcase struct {
|
type testcase struct {
|
||||||
subject string
|
subject string
|
||||||
release ReleaseSpec
|
release ReleaseSpec
|
||||||
data interface{}
|
data any
|
||||||
want string
|
want string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,7 +51,7 @@ func TestGenerateID(t *testing.T) {
|
||||||
run(testcase{
|
run(testcase{
|
||||||
subject: "different map content",
|
subject: "different map content",
|
||||||
release: ReleaseSpec{Name: "foo", Chart: "incubator/raw"},
|
release: ReleaseSpec{Name: "foo", Chart: "incubator/raw"},
|
||||||
data: map[string]interface{}{"k": "v"},
|
data: map[string]any{"k": "v"},
|
||||||
want: "foo-values-77cdb7dbb6",
|
want: "foo-values-77cdb7dbb6",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,11 @@ type EnvironmentTemplateData struct {
|
||||||
// Namespace is accessible as `.Namespace` from any non-values template executed by the renderer
|
// Namespace is accessible as `.Namespace` from any non-values template executed by the renderer
|
||||||
Namespace string
|
Namespace string
|
||||||
// Values is accessible as `.Values` and it contains default state values overrode by environment values and override values.
|
// Values is accessible as `.Values` and it contains default state values overrode by environment values and override values.
|
||||||
Values map[string]interface{}
|
Values map[string]any
|
||||||
StateValues *map[string]interface{}
|
StateValues *map[string]any
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEnvironmentTemplateData(environment environment.Environment, namespace string, values map[string]interface{}) *EnvironmentTemplateData {
|
func NewEnvironmentTemplateData(environment environment.Environment, namespace string, values map[string]any) *EnvironmentTemplateData {
|
||||||
d := EnvironmentTemplateData{environment, namespace, values, nil}
|
d := EnvironmentTemplateData{environment, namespace, values, nil}
|
||||||
d.StateValues = &d.Values
|
d.StateValues = &d.Values
|
||||||
return &d
|
return &d
|
||||||
|
|
@ -35,8 +35,8 @@ type releaseTemplateData struct {
|
||||||
// It contains a subset of ReleaseSpec that is known to be useful to dynamically render values.
|
// It contains a subset of ReleaseSpec that is known to be useful to dynamically render values.
|
||||||
Release releaseTemplateDataRelease
|
Release releaseTemplateDataRelease
|
||||||
// Values is accessible as `.Values` and it contains default state values overrode by environment values and override values.
|
// Values is accessible as `.Values` and it contains default state values overrode by environment values and override values.
|
||||||
Values map[string]interface{}
|
Values map[string]any
|
||||||
StateValues *map[string]interface{}
|
StateValues *map[string]any
|
||||||
// KubeContext is HelmState.OverrideKubeContext.
|
// KubeContext is HelmState.OverrideKubeContext.
|
||||||
// You should better use Release.KubeContext as it might work as you'd expect even if HelmState.OverrideKubeContext is not set.
|
// You should better use Release.KubeContext as it might work as you'd expect even if HelmState.OverrideKubeContext is not set.
|
||||||
// See releaseTemplateDataRelease.KubeContext for more information.
|
// See releaseTemplateDataRelease.KubeContext for more information.
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import (
|
||||||
"github.com/helmfile/helmfile/pkg/yaml"
|
"github.com/helmfile/helmfile/pkg/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Values = map[string]interface{}
|
type Values = map[string]any
|
||||||
|
|
||||||
var DisableInsecureFeaturesErr = DisableInsecureFeaturesError{envvar.DisableInsecureFeatures + " is active, insecure function calls are disabled"}
|
var DisableInsecureFeaturesErr = DisableInsecureFeaturesError{envvar.DisableInsecureFeatures + " is active, insecure function calls are disabled"}
|
||||||
|
|
||||||
|
|
@ -65,10 +65,10 @@ func (c *Context) createFuncMap() template.FuncMap {
|
||||||
}
|
}
|
||||||
if c.preRender || skipInsecureTemplateFunctions {
|
if c.preRender || skipInsecureTemplateFunctions {
|
||||||
// disable potential side-effect template calls
|
// disable potential side-effect template calls
|
||||||
funcMap["exec"] = func(string, []interface{}, ...string) (string, error) {
|
funcMap["exec"] = func(string, []any, ...string) (string, error) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
funcMap["envExec"] = func(map[string]interface{}, string, []interface{}, ...string) (string, error) {
|
funcMap["envExec"] = func(map[string]any, string, []any, ...string) (string, error) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
funcMap["readFile"] = func(string) (string, error) {
|
funcMap["readFile"] = func(string) (string, error) {
|
||||||
|
|
@ -83,7 +83,7 @@ func (c *Context) createFuncMap() template.FuncMap {
|
||||||
}
|
}
|
||||||
if disableInsecureFeatures {
|
if disableInsecureFeatures {
|
||||||
// disable insecure functions
|
// disable insecure functions
|
||||||
funcMap["exec"] = func(string, []interface{}, ...string) (string, error) {
|
funcMap["exec"] = func(string, []any, ...string) (string, error) {
|
||||||
return "", DisableInsecureFeaturesErr
|
return "", DisableInsecureFeaturesErr
|
||||||
}
|
}
|
||||||
funcMap["readFile"] = func(string) (string, error) {
|
funcMap["readFile"] = func(string) (string, error) {
|
||||||
|
|
@ -101,7 +101,7 @@ func (c *Context) createFuncMap() template.FuncMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: in the next major version, remove this function.
|
// TODO: in the next major version, remove this function.
|
||||||
func (c *Context) EnvExec(envs map[string]interface{}, command string, args []interface{}, inputs ...string) (string, error) {
|
func (c *Context) EnvExec(envs map[string]any, command string, args []any, inputs ...string) (string, error) {
|
||||||
var input string
|
var input string
|
||||||
if len(inputs) > 0 {
|
if len(inputs) > 0 {
|
||||||
input = inputs[0]
|
input = inputs[0]
|
||||||
|
|
@ -192,7 +192,7 @@ func (c *Context) EnvExec(envs map[string]interface{}, command string, args []in
|
||||||
return string(bytes), nil
|
return string(bytes), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) Exec(command string, args []interface{}, inputs ...string) (string, error) {
|
func (c *Context) Exec(command string, args []any, inputs ...string) (string, error) {
|
||||||
return c.EnvExec(nil, command, args, inputs...)
|
return c.EnvExec(nil, command, args, inputs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -271,7 +271,7 @@ func (c *Context) ReadDirEntries(path string) ([]fs.DirEntry, error) {
|
||||||
return entries, nil
|
return entries, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) Tpl(text string, data interface{}) (string, error) {
|
func (c *Context) Tpl(text string, data any) (string, error) {
|
||||||
buf, err := c.RenderTemplateToBuffer(text, data)
|
buf, err := c.RenderTemplateToBuffer(text, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
@ -279,7 +279,7 @@ func (c *Context) Tpl(text string, data interface{}) (string, error) {
|
||||||
return buf.String(), nil
|
return buf.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToYaml(v interface{}) (string, error) {
|
func ToYaml(v any) (string, error) {
|
||||||
data, err := yaml.Marshal(v)
|
data, err := yaml.Marshal(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
@ -288,7 +288,7 @@ func ToYaml(v interface{}) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromYaml(str string) (Values, error) {
|
func FromYaml(str string) (Values, error) {
|
||||||
m := map[string]interface{}{}
|
m := map[string]any{}
|
||||||
|
|
||||||
if err := yaml.Unmarshal([]byte(str), &m); err != nil {
|
if err := yaml.Unmarshal([]byte(str), &m); err != nil {
|
||||||
return nil, fmt.Errorf("%s, offending yaml: %s", err, str)
|
return nil, fmt.Errorf("%s, offending yaml: %s", err, str)
|
||||||
|
|
@ -302,23 +302,23 @@ func FromYaml(str string) (Values, error) {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetValueAtPath(path string, value interface{}, values Values) (Values, error) {
|
func SetValueAtPath(path string, value any, values Values) (Values, error) {
|
||||||
var current interface{}
|
var current any
|
||||||
current = values
|
current = values
|
||||||
components := strings.Split(path, ".")
|
components := strings.Split(path, ".")
|
||||||
pathToMap := components[:len(components)-1]
|
pathToMap := components[:len(components)-1]
|
||||||
key := components[len(components)-1]
|
key := components[len(components)-1]
|
||||||
for _, k := range pathToMap {
|
for _, k := range pathToMap {
|
||||||
var elem interface{}
|
var elem any
|
||||||
|
|
||||||
switch typedCurrent := current.(type) {
|
switch typedCurrent := current.(type) {
|
||||||
case map[string]interface{}:
|
case map[string]any:
|
||||||
v, exists := typedCurrent[k]
|
v, exists := typedCurrent[k]
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, fmt.Errorf("failed to set value at path \"%s\": value for key \"%s\" does not exist", path, k)
|
return nil, fmt.Errorf("failed to set value at path \"%s\": value for key \"%s\" does not exist", path, k)
|
||||||
}
|
}
|
||||||
elem = v
|
elem = v
|
||||||
case map[interface{}]interface{}:
|
case map[any]any:
|
||||||
v, exists := typedCurrent[k]
|
v, exists := typedCurrent[k]
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, fmt.Errorf("failed to set value at path \"%s\": value for key \"%s\" does not exist", path, k)
|
return nil, fmt.Errorf("failed to set value at path \"%s\": value for key \"%s\" does not exist", path, k)
|
||||||
|
|
@ -329,7 +329,7 @@ func SetValueAtPath(path string, value interface{}, values Values) (Values, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
switch typedElem := elem.(type) {
|
switch typedElem := elem.(type) {
|
||||||
case map[string]interface{}, map[interface{}]interface{}:
|
case map[string]any, map[any]any:
|
||||||
current = typedElem
|
current = typedElem
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("failed to set value at path \"%s\": value for key \"%s\" was not a map", path, k)
|
return nil, fmt.Errorf("failed to set value at path \"%s\": value for key \"%s\" was not a map", path, k)
|
||||||
|
|
@ -337,9 +337,9 @@ func SetValueAtPath(path string, value interface{}, values Values) (Values, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
switch typedCurrent := current.(type) {
|
switch typedCurrent := current.(type) {
|
||||||
case map[string]interface{}:
|
case map[string]any:
|
||||||
typedCurrent[key] = value
|
typedCurrent[key] = value
|
||||||
case map[interface{}]interface{}:
|
case map[any]any:
|
||||||
typedCurrent[key] = value
|
typedCurrent[key] = value
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("failed to set value at path \"%s\": value for key \"%s\" was not a map", path, key)
|
return nil, fmt.Errorf("failed to set value at path \"%s\": value for key \"%s\" was not a map", path, key)
|
||||||
|
|
@ -355,7 +355,7 @@ func RequiredEnv(name string) (string, error) {
|
||||||
return "", fmt.Errorf("required env var `%s` is not set", name)
|
return "", fmt.Errorf("required env var `%s` is not set", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Required(warn string, val interface{}) (interface{}, error) {
|
func Required(warn string, val any) (any, error) {
|
||||||
if val == nil {
|
if val == nil {
|
||||||
return nil, fmt.Errorf(warn)
|
return nil, fmt.Errorf(warn)
|
||||||
} else if _, ok := val.(string); ok {
|
} else if _, ok := val.(string); ok {
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@ func TestCreateFuncMap(t *testing.T) {
|
||||||
disableInsecureFeatures = false
|
disableInsecureFeatures = false
|
||||||
ctx := &Context{basePath: "."}
|
ctx := &Context{basePath: "."}
|
||||||
funcMaps := ctx.createFuncMap()
|
funcMaps := ctx.createFuncMap()
|
||||||
args := make([]interface{}, 0)
|
args := make([]any, 0)
|
||||||
outputExec, _ := funcMaps["exec"].(func(command string, args []interface{}, inputs ...string) (string, error))("ls", args)
|
outputExec, _ := funcMaps["exec"].(func(command string, args []any, inputs ...string) (string, error))("ls", args)
|
||||||
require.Contains(t, outputExec, "context.go")
|
require.Contains(t, outputExec, "context.go")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -36,8 +36,8 @@ func TestCreateFuncMap_DisabledInsecureFeatures(t *testing.T) {
|
||||||
disableInsecureFeatures = true
|
disableInsecureFeatures = true
|
||||||
ctx := &Context{basePath: "."}
|
ctx := &Context{basePath: "."}
|
||||||
funcMaps := ctx.createFuncMap()
|
funcMaps := ctx.createFuncMap()
|
||||||
args := make([]interface{}, 0)
|
args := make([]any, 0)
|
||||||
_, err1 := funcMaps["exec"].(func(command string, args []interface{}, inputs ...string) (string, error))("ls", args)
|
_, err1 := funcMaps["exec"].(func(command string, args []any, inputs ...string) (string, error))("ls", args)
|
||||||
require.ErrorIs(t, err1, DisableInsecureFeaturesErr)
|
require.ErrorIs(t, err1, DisableInsecureFeaturesErr)
|
||||||
_, err2 := funcMaps["readFile"].(func(filename string) (string, error))("context_funcs_test.go")
|
_, err2 := funcMaps["readFile"].(func(filename string) (string, error))("context_funcs_test.go")
|
||||||
require.ErrorIs(t, err2, DisableInsecureFeaturesErr)
|
require.ErrorIs(t, err2, DisableInsecureFeaturesErr)
|
||||||
|
|
@ -53,8 +53,8 @@ func TestCreateFuncMap_SkipInsecureTemplateFunctions(t *testing.T) {
|
||||||
skipInsecureTemplateFunctions = true
|
skipInsecureTemplateFunctions = true
|
||||||
ctx := &Context{basePath: "."}
|
ctx := &Context{basePath: "."}
|
||||||
funcMaps := ctx.createFuncMap()
|
funcMaps := ctx.createFuncMap()
|
||||||
args := make([]interface{}, 0)
|
args := make([]any, 0)
|
||||||
actual1, err1 := funcMaps["exec"].(func(command string, args []interface{}, inputs ...string) (string, error))("ls", args)
|
actual1, err1 := funcMaps["exec"].(func(command string, args []any, inputs ...string) (string, error))("ls", args)
|
||||||
require.Equal(t, "", actual1)
|
require.Equal(t, "", actual1)
|
||||||
require.ErrorIs(t, err1, nil)
|
require.ErrorIs(t, err1, nil)
|
||||||
actual2, err2 := funcMaps["readFile"].(func(filename string) (string, error))("context_funcs_test.go")
|
actual2, err2 := funcMaps["readFile"].(func(filename string) (string, error))("context_funcs_test.go")
|
||||||
|
|
@ -185,8 +185,8 @@ func TestToYaml_NestedMapInterfaceKey(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
// nolint: unconvert
|
// nolint: unconvert
|
||||||
vals := Values(map[string]interface{}{
|
vals := Values(map[string]any{
|
||||||
"foo": map[interface{}]interface{}{
|
"foo": map[any]any{
|
||||||
"bar": "BAR",
|
"bar": "BAR",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
@ -209,8 +209,8 @@ func TestToYaml(t *testing.T) {
|
||||||
bar: BAR
|
bar: BAR
|
||||||
`
|
`
|
||||||
// nolint: unconvert
|
// nolint: unconvert
|
||||||
vals := Values(map[string]interface{}{
|
vals := Values(map[string]any{
|
||||||
"foo": map[string]interface{}{
|
"foo": map[string]any{
|
||||||
"bar": "BAR",
|
"bar": "BAR",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
@ -242,8 +242,8 @@ func TestFromYaml(t *testing.T) {
|
||||||
t,
|
t,
|
||||||
true,
|
true,
|
||||||
// nolint: unconvert
|
// nolint: unconvert
|
||||||
Values(map[string]interface{}{
|
Values(map[string]any{
|
||||||
"foo": map[string]interface{}{
|
"foo": map[string]any{
|
||||||
"bar": "BAR",
|
"bar": "BAR",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
@ -255,8 +255,8 @@ func TestFromYaml(t *testing.T) {
|
||||||
t,
|
t,
|
||||||
false,
|
false,
|
||||||
// nolint: unconvert
|
// nolint: unconvert
|
||||||
Values(map[string]interface{}{
|
Values(map[string]any{
|
||||||
"foo": map[string]interface{}{
|
"foo": map[string]any{
|
||||||
"bar": "BAR",
|
"bar": "BAR",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
@ -279,10 +279,10 @@ func TestFromYamlToJson(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetValueAtPath_OneComponent(t *testing.T) {
|
func TestSetValueAtPath_OneComponent(t *testing.T) {
|
||||||
input := map[string]interface{}{
|
input := map[string]any{
|
||||||
"foo": "",
|
"foo": "",
|
||||||
}
|
}
|
||||||
expected := map[string]interface{}{
|
expected := map[string]any{
|
||||||
"foo": "FOO",
|
"foo": "FOO",
|
||||||
}
|
}
|
||||||
actual, err := SetValueAtPath("foo", "FOO", input)
|
actual, err := SetValueAtPath("foo", "FOO", input)
|
||||||
|
|
@ -291,13 +291,13 @@ func TestSetValueAtPath_OneComponent(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetValueAtPath_TwoComponents(t *testing.T) {
|
func TestSetValueAtPath_TwoComponents(t *testing.T) {
|
||||||
input := map[string]interface{}{
|
input := map[string]any{
|
||||||
"foo": map[interface{}]interface{}{
|
"foo": map[any]any{
|
||||||
"bar": "",
|
"bar": "",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
expected := map[string]interface{}{
|
expected := map[string]any{
|
||||||
"foo": map[interface{}]interface{}{
|
"foo": map[any]any{
|
||||||
"bar": "FOO_BAR",
|
"bar": "FOO_BAR",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -313,13 +313,13 @@ func TestTpl(t *testing.T) {
|
||||||
input string
|
input string
|
||||||
expected string
|
expected string
|
||||||
hasErr bool
|
hasErr bool
|
||||||
data map[string]interface{}
|
data map[string]any
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "simple",
|
name: "simple",
|
||||||
input: `foo: {{ .foo }}`,
|
input: `foo: {{ .foo }}`,
|
||||||
expected: `foo: Foo`,
|
expected: `foo: Foo`,
|
||||||
data: map[string]interface{}{
|
data: map[string]any{
|
||||||
"foo": "Foo",
|
"foo": "Foo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -328,7 +328,7 @@ func TestTpl(t *testing.T) {
|
||||||
input: `{{ .name }}
|
input: `{{ .name }}
|
||||||
end`,
|
end`,
|
||||||
expected: "multiline\nend",
|
expected: "multiline\nend",
|
||||||
data: map[string]interface{}{
|
data: map[string]any{
|
||||||
"name": "multiline",
|
"name": "multiline",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -350,12 +350,12 @@ end`,
|
||||||
func TestRequired(t *testing.T) {
|
func TestRequired(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
warn string
|
warn string
|
||||||
val interface{}
|
val any
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args args
|
args args
|
||||||
want interface{}
|
want any
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
|
@ -422,12 +422,12 @@ func TestExec(t *testing.T) {
|
||||||
|
|
||||||
// test that the command is executed
|
// test that the command is executed
|
||||||
expected := "foo\n"
|
expected := "foo\n"
|
||||||
output, err := ctx.Exec("echo", []interface{}{"foo"}, "")
|
output, err := ctx.Exec("echo", []any{"foo"}, "")
|
||||||
require.Nilf(t, err, "Expected no error to be returned when executing command")
|
require.Nilf(t, err, "Expected no error to be returned when executing command")
|
||||||
require.Equalf(t, expected, output, "Expected %s to be returned when executing command", expected)
|
require.Equalf(t, expected, output, "Expected %s to be returned when executing command", expected)
|
||||||
|
|
||||||
// test that the command is executed with no-zero exit code
|
// test that the command is executed with no-zero exit code
|
||||||
_, err = ctx.Exec("bash", []interface{}{"-c", "exit 1"}, "")
|
_, err = ctx.Exec("bash", []any{"-c", "exit 1"}, "")
|
||||||
require.Error(t, err, "Expected error to be returned when executing command with non-zero exit code")
|
require.Error(t, err, "Expected error to be returned when executing command with non-zero exit code")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -441,27 +441,27 @@ func TestEnvExec(t *testing.T) {
|
||||||
testKey := "testkey"
|
testKey := "testkey"
|
||||||
|
|
||||||
// test that the command is executed with environment variables
|
// test that the command is executed with environment variables
|
||||||
output, err := ctx.EnvExec(map[string]interface{}{testKey: "foo"}, "bash", []interface{}{"-c", fmt.Sprintf("echo -n $%s", testKey)}, "")
|
output, err := ctx.EnvExec(map[string]any{testKey: "foo"}, "bash", []any{"-c", fmt.Sprintf("echo -n $%s", testKey)}, "")
|
||||||
|
|
||||||
require.Nilf(t, err, "Expected no error to be returned when executing command with environment variables")
|
require.Nilf(t, err, "Expected no error to be returned when executing command with environment variables")
|
||||||
|
|
||||||
require.Equalf(t, expected, output, "Expected %s to be returned when executing command with environment variables", expected)
|
require.Equalf(t, expected, output, "Expected %s to be returned when executing command with environment variables", expected)
|
||||||
|
|
||||||
// test that the command is executed with invalid environment variables
|
// test that the command is executed with invalid environment variables
|
||||||
output, err = ctx.EnvExec(map[string]interface{}{testKey: 123}, "bash", []interface{}{"-c", fmt.Sprintf("echo -n $%s", testKey)}, "")
|
output, err = ctx.EnvExec(map[string]any{testKey: 123}, "bash", []any{"-c", fmt.Sprintf("echo -n $%s", testKey)}, "")
|
||||||
|
|
||||||
require.Errorf(t, err, "Expected error to be returned when executing command with invalid environment variables")
|
require.Errorf(t, err, "Expected error to be returned when executing command with invalid environment variables")
|
||||||
require.Emptyf(t, output, "Expected empty string to be returned when executing command with invalid environment variables")
|
require.Emptyf(t, output, "Expected empty string to be returned when executing command with invalid environment variables")
|
||||||
|
|
||||||
// test that the command is executed with no environment variables
|
// test that the command is executed with no environment variables
|
||||||
output, err = ctx.EnvExec(nil, "bash", []interface{}{"-c", fmt.Sprintf("echo -n $%s", testKey)}, "")
|
output, err = ctx.EnvExec(nil, "bash", []any{"-c", fmt.Sprintf("echo -n $%s", testKey)}, "")
|
||||||
require.Nilf(t, err, "Expected no error to be returned when executing command with no environment variables")
|
require.Nilf(t, err, "Expected no error to be returned when executing command with no environment variables")
|
||||||
|
|
||||||
require.Emptyf(t, output, "Expected empty string to be returned when executing command with no environment variables")
|
require.Emptyf(t, output, "Expected empty string to be returned when executing command with no environment variables")
|
||||||
|
|
||||||
// test that the command is executed with os environment variables
|
// test that the command is executed with os environment variables
|
||||||
t.Setenv(testKey, "foo")
|
t.Setenv(testKey, "foo")
|
||||||
output, err = ctx.EnvExec(nil, "bash", []interface{}{"-c", fmt.Sprintf("echo -n $%s", testKey)}, "")
|
output, err = ctx.EnvExec(nil, "bash", []any{"-c", fmt.Sprintf("echo -n $%s", testKey)}, "")
|
||||||
|
|
||||||
require.Nilf(t, err, "Expected no error to be returned when executing command with environment variables")
|
require.Nilf(t, err, "Expected no error to be returned when executing command with environment variables")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,14 +43,14 @@ func (c *Context) newTemplate() *template.Template {
|
||||||
return tmpl
|
return tmpl
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) RenderTemplateToBuffer(s string, data ...interface{}) (*bytes.Buffer, error) {
|
func (c *Context) RenderTemplateToBuffer(s string, data ...any) (*bytes.Buffer, error) {
|
||||||
var t, parseErr = c.newTemplate().Parse(s)
|
var t, parseErr = c.newTemplate().Parse(s)
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
return nil, parseErr
|
return nil, parseErr
|
||||||
}
|
}
|
||||||
|
|
||||||
var tplString bytes.Buffer
|
var tplString bytes.Buffer
|
||||||
var d interface{}
|
var d any
|
||||||
if len(data) > 0 {
|
if len(data) > 0 {
|
||||||
d = data[0]
|
d = data[0]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@ func TestRenderTemplate_WithData(t *testing.T) {
|
||||||
bar: FOO_BAR
|
bar: FOO_BAR
|
||||||
`
|
`
|
||||||
expectedFilename := "values.yaml"
|
expectedFilename := "values.yaml"
|
||||||
data := map[string]interface{}{
|
data := map[string]any{
|
||||||
"foo": map[string]interface{}{
|
"foo": map[string]any{
|
||||||
"bar": "FOO_BAR",
|
"bar": "FOO_BAR",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -69,7 +69,7 @@ func TestRenderTemplate_AccessingMissingKeyWithGetOrNil(t *testing.T) {
|
||||||
bar: <no value>
|
bar: <no value>
|
||||||
`
|
`
|
||||||
expectedFilename := "values.yaml"
|
expectedFilename := "values.yaml"
|
||||||
data := map[string]interface{}{}
|
data := map[string]any{}
|
||||||
ctx := &Context{fs: &ffs.FileSystem{ReadFile: func(filename string) ([]byte, error) {
|
ctx := &Context{fs: &ffs.FileSystem{ReadFile: func(filename string) ([]byte, error) {
|
||||||
if filename != expectedFilename {
|
if filename != expectedFilename {
|
||||||
return nil, fmt.Errorf("unexpected filename: expected=%v, actual=%s", expectedFilename, filename)
|
return nil, fmt.Errorf("unexpected filename: expected=%v, actual=%s", expectedFilename, filename)
|
||||||
|
|
@ -94,7 +94,7 @@ func TestRenderTemplate_Defaulting(t *testing.T) {
|
||||||
bar: DEFAULT
|
bar: DEFAULT
|
||||||
`
|
`
|
||||||
expectedFilename := "values.yaml"
|
expectedFilename := "values.yaml"
|
||||||
data := map[string]interface{}{}
|
data := map[string]any{}
|
||||||
ctx := &Context{fs: &ffs.FileSystem{ReadFile: func(filename string) ([]byte, error) {
|
ctx := &Context{fs: &ffs.FileSystem{ReadFile: func(filename string) ([]byte, error) {
|
||||||
if filename != expectedFilename {
|
if filename != expectedFilename {
|
||||||
return nil, fmt.Errorf("unexpected filename: expected=%v, actual=%s", expectedFilename, filename)
|
return nil, fmt.Errorf("unexpected filename: expected=%v, actual=%s", expectedFilename, filename)
|
||||||
|
|
@ -111,7 +111,7 @@ func TestRenderTemplate_Defaulting(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderTemplateToString(s string, data ...interface{}) (string, error) {
|
func renderTemplateToString(s string, data ...any) (string, error) {
|
||||||
ctx := &Context{fs: &ffs.FileSystem{ReadFile: func(filename string) ([]byte, error) {
|
ctx := &Context{fs: &ffs.FileSystem{ReadFile: func(filename string) ([]byte, error) {
|
||||||
return nil, fmt.Errorf("unexpected call to readFile: filename=%s", filename)
|
return nil, fmt.Errorf("unexpected call to readFile: filename=%s", filename)
|
||||||
}}}
|
}}}
|
||||||
|
|
@ -126,7 +126,7 @@ func Test_renderTemplateToString(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
s string
|
s string
|
||||||
envs map[string]string
|
envs map[string]string
|
||||||
data interface{}
|
data any
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|
@ -184,7 +184,7 @@ func Test_renderTemplateToString(t *testing.T) {
|
||||||
args: args{
|
args: args{
|
||||||
s: `{{ . | get "Foo" }}, {{ . | get "Bar" "2" }}`,
|
s: `{{ . | get "Foo" }}, {{ . | get "Bar" "2" }}`,
|
||||||
envs: map[string]string{},
|
envs: map[string]string{},
|
||||||
data: map[string]interface{}{
|
data: map[string]any{
|
||||||
"Foo": "1",
|
"Foo": "1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -253,14 +253,14 @@ func TestRenderTemplate_Required(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
s string
|
s string
|
||||||
data map[string]interface{}
|
data map[string]any
|
||||||
want string
|
want string
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: ".foo is existed",
|
name: ".foo is existed",
|
||||||
s: `{{ required ".foo.bar is required" .foo }}`,
|
s: `{{ required ".foo.bar is required" .foo }}`,
|
||||||
data: map[string]interface{}{
|
data: map[string]any{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
},
|
},
|
||||||
want: "bar",
|
want: "bar",
|
||||||
|
|
@ -269,8 +269,8 @@ func TestRenderTemplate_Required(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: ".foo.bar is existed",
|
name: ".foo.bar is existed",
|
||||||
s: `{{ required "foo.bar is required" .foo.bar }}`,
|
s: `{{ required "foo.bar is required" .foo.bar }}`,
|
||||||
data: map[string]interface{}{
|
data: map[string]any{
|
||||||
"foo": map[string]interface{}{
|
"foo": map[string]any{
|
||||||
"bar": "FOO_BAR",
|
"bar": "FOO_BAR",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -280,8 +280,8 @@ func TestRenderTemplate_Required(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: ".foo.bar is existed but value is nil",
|
name: ".foo.bar is existed but value is nil",
|
||||||
s: `{{ required "foo.bar is required" .foo.bar }}`,
|
s: `{{ required "foo.bar is required" .foo.bar }}`,
|
||||||
data: map[string]interface{}{
|
data: map[string]any{
|
||||||
"foo": map[string]interface{}{
|
"foo": map[string]any{
|
||||||
"bar": nil,
|
"bar": nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -290,8 +290,8 @@ func TestRenderTemplate_Required(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: ".foo.bar is existed but value is empty string",
|
name: ".foo.bar is existed but value is empty string",
|
||||||
s: `{{ required "foo.bar is required" .foo.bar }}`,
|
s: `{{ required "foo.bar is required" .foo.bar }}`,
|
||||||
data: map[string]interface{}{
|
data: map[string]any{
|
||||||
"foo": map[string]interface{}{
|
"foo": map[string]any{
|
||||||
"bar": "",
|
"bar": "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -300,7 +300,7 @@ func TestRenderTemplate_Required(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: ".foo is nil",
|
name: ".foo is nil",
|
||||||
s: `{{ required "foo is required" .foo }}`,
|
s: `{{ required "foo is required" .foo }}`,
|
||||||
data: map[string]interface{}{
|
data: map[string]any{
|
||||||
"foo": nil,
|
"foo": nil,
|
||||||
},
|
},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
|
|
@ -308,7 +308,7 @@ func TestRenderTemplate_Required(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: ".foo is a empty string",
|
name: ".foo is a empty string",
|
||||||
s: `{{ required "foo is required" .foo }}`,
|
s: `{{ required "foo is required" .foo }}`,
|
||||||
data: map[string]interface{}{
|
data: map[string]any{
|
||||||
"foo": "",
|
"foo": "",
|
||||||
},
|
},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,14 @@ import (
|
||||||
|
|
||||||
// to generate mock run mockgen -source=expand_secret_ref.go -destination=expand_secrets_mock.go -package=tmpl
|
// to generate mock run mockgen -source=expand_secret_ref.go -destination=expand_secrets_mock.go -package=tmpl
|
||||||
type valClient interface {
|
type valClient interface {
|
||||||
Eval(template map[string]interface{}) (map[string]interface{}, error)
|
Eval(template map[string]any) (map[string]any, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
var once sync.Once
|
var once sync.Once
|
||||||
var secretsClient valClient
|
var secretsClient valClient
|
||||||
|
|
||||||
func fetchSecretValue(path string) (string, error) {
|
func fetchSecretValue(path string) (string, error) {
|
||||||
tmpMap := make(map[string]interface{})
|
tmpMap := make(map[string]any)
|
||||||
tmpMap["key"] = path
|
tmpMap["key"] = path
|
||||||
resultMap, err := fetchSecretValues(tmpMap)
|
resultMap, err := fetchSecretValues(tmpMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -38,7 +38,7 @@ func fetchSecretValue(path string) (string, error) {
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchSecretValues(values map[string]interface{}) (map[string]interface{}, error) {
|
func fetchSecretValues(values map[string]any) (map[string]any, error) {
|
||||||
var err error
|
var err error
|
||||||
// below lines are for tests
|
// below lines are for tests
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,10 @@ func Test_fetchSecretValue(t *testing.T) {
|
||||||
secretsClient = c
|
secretsClient = c
|
||||||
|
|
||||||
secretPath := "ref+vault://key/#path"
|
secretPath := "ref+vault://key/#path"
|
||||||
expectArg := make(map[string]interface{})
|
expectArg := make(map[string]any)
|
||||||
expectArg["key"] = secretPath
|
expectArg["key"] = secretPath
|
||||||
|
|
||||||
valsResult := make(map[string]interface{})
|
valsResult := make(map[string]any)
|
||||||
valsResult["key"] = "key_value"
|
valsResult["key"] = "key_value"
|
||||||
c.EXPECT().Eval(expectArg).Return(valsResult, nil)
|
c.EXPECT().Eval(expectArg).Return(valsResult, nil)
|
||||||
result, err := fetchSecretValue(secretPath)
|
result, err := fetchSecretValue(secretPath)
|
||||||
|
|
@ -33,7 +33,7 @@ func Test_fetchSecretValue_error(t *testing.T) {
|
||||||
secretsClient = c
|
secretsClient = c
|
||||||
|
|
||||||
secretPath := "ref+vault://key/#path"
|
secretPath := "ref+vault://key/#path"
|
||||||
expectArg := make(map[string]interface{})
|
expectArg := make(map[string]any)
|
||||||
expectArg["key"] = secretPath
|
expectArg["key"] = secretPath
|
||||||
|
|
||||||
expectedErr := errors.New("some error")
|
expectedErr := errors.New("some error")
|
||||||
|
|
@ -50,10 +50,10 @@ func Test_fetchSecretValue_no_key(t *testing.T) {
|
||||||
secretsClient = c
|
secretsClient = c
|
||||||
|
|
||||||
secretPath := "ref+vault://key/#path"
|
secretPath := "ref+vault://key/#path"
|
||||||
expectArg := make(map[string]interface{})
|
expectArg := make(map[string]any)
|
||||||
expectArg["key"] = secretPath
|
expectArg["key"] = secretPath
|
||||||
|
|
||||||
valsResult := make(map[string]interface{})
|
valsResult := make(map[string]any)
|
||||||
c.EXPECT().Eval(expectArg).Return(valsResult, nil)
|
c.EXPECT().Eval(expectArg).Return(valsResult, nil)
|
||||||
result, err := fetchSecretValue(secretPath)
|
result, err := fetchSecretValue(secretPath)
|
||||||
assert.Error(t, err, "unexpected error occurred, map[] doesn't have 'key' key")
|
assert.Error(t, err, "unexpected error occurred, map[] doesn't have 'key' key")
|
||||||
|
|
@ -67,10 +67,10 @@ func Test_fetchSecretValue_invalid_type(t *testing.T) {
|
||||||
secretsClient = c
|
secretsClient = c
|
||||||
|
|
||||||
secretPath := "ref+vault://key/#path"
|
secretPath := "ref+vault://key/#path"
|
||||||
expectArg := make(map[string]interface{})
|
expectArg := make(map[string]any)
|
||||||
expectArg["key"] = secretPath
|
expectArg["key"] = secretPath
|
||||||
|
|
||||||
valsResult := make(map[string]interface{})
|
valsResult := make(map[string]any)
|
||||||
valsResult["key"] = 10
|
valsResult["key"] = 10
|
||||||
c.EXPECT().Eval(expectArg).Return(valsResult, nil)
|
c.EXPECT().Eval(expectArg).Return(valsResult, nil)
|
||||||
result, err := fetchSecretValue(secretPath)
|
result, err := fetchSecretValue(secretPath)
|
||||||
|
|
|
||||||
|
|
@ -33,14 +33,14 @@ func (_m *MockvalClient) EXPECT() *MockvalClientMockRecorder {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Eval mocks base method
|
// Eval mocks base method
|
||||||
func (_m *MockvalClient) Eval(template map[string]interface{}) (map[string]interface{}, error) {
|
func (_m *MockvalClient) Eval(template map[string]any) (map[string]any, error) {
|
||||||
ret := _m.ctrl.Call(_m, "Eval", template)
|
ret := _m.ctrl.Call(_m, "Eval", template)
|
||||||
ret0, _ := ret[0].(map[string]interface{})
|
ret0, _ := ret[0].(map[string]any)
|
||||||
ret1, _ := ret[1].(error)
|
ret1, _ := ret[1].(error)
|
||||||
return ret0, ret1
|
return ret0, ret1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Eval indicates an expected call of Eval
|
// Eval indicates an expected call of Eval
|
||||||
func (_mr *MockvalClientMockRecorder) Eval(arg0 interface{}) *gomock.Call {
|
func (_mr *MockvalClientMockRecorder) Eval(arg0 any) *gomock.Call {
|
||||||
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Eval", reflect.TypeOf((*MockvalClient)(nil).Eval), arg0)
|
return _mr.mock.ctrl.RecordCallWithMethodType(_mr.mock, "Eval", reflect.TypeOf((*MockvalClient)(nil).Eval), arg0)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,10 @@ import (
|
||||||
type FileRenderer struct {
|
type FileRenderer struct {
|
||||||
fs *filesystem.FileSystem
|
fs *filesystem.FileSystem
|
||||||
Context *Context
|
Context *Context
|
||||||
Data interface{}
|
Data any
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFileRenderer(fs *filesystem.FileSystem, basePath string, data interface{}) *FileRenderer {
|
func NewFileRenderer(fs *filesystem.FileSystem, basePath string, data any) *FileRenderer {
|
||||||
return &FileRenderer{
|
return &FileRenderer{
|
||||||
fs: fs,
|
fs: fs,
|
||||||
Context: &Context{
|
Context: &Context{
|
||||||
|
|
@ -25,7 +25,7 @@ func NewFileRenderer(fs *filesystem.FileSystem, basePath string, data interface{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFirstPassRenderer(basePath string, data interface{}) *FileRenderer {
|
func NewFirstPassRenderer(basePath string, data any) *FileRenderer {
|
||||||
fs := filesystem.DefaultFileSystem()
|
fs := filesystem.DefaultFileSystem()
|
||||||
return &FileRenderer{
|
return &FileRenderer{
|
||||||
fs: fs,
|
fs: fs,
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/helmfile/helmfile/pkg/filesystem"
|
"github.com/helmfile/helmfile/pkg/filesystem"
|
||||||
)
|
)
|
||||||
|
|
||||||
var emptyEnvTmplData = map[string]interface{}{
|
var emptyEnvTmplData = map[string]any{
|
||||||
"Environment": environment.EmptyEnvironment,
|
"Environment": environment.EmptyEnvironment,
|
||||||
"Namespace": "",
|
"Namespace": "",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,10 @@ func (e *noValueError) Error() string {
|
||||||
return e.msg
|
return e.msg
|
||||||
}
|
}
|
||||||
|
|
||||||
func get(path string, varArgs ...interface{}) (interface{}, error) {
|
func get(path string, varArgs ...any) (any, error) {
|
||||||
var defSet bool
|
var defSet bool
|
||||||
var def interface{}
|
var def any
|
||||||
var obj interface{}
|
var obj any
|
||||||
switch len(varArgs) {
|
switch len(varArgs) {
|
||||||
case 1:
|
case 1:
|
||||||
defSet = false
|
defSet = false
|
||||||
|
|
@ -35,14 +35,14 @@ func get(path string, varArgs ...interface{}) (interface{}, error) {
|
||||||
return obj, nil
|
return obj, nil
|
||||||
}
|
}
|
||||||
keys := strings.Split(path, ".")
|
keys := strings.Split(path, ".")
|
||||||
var v interface{}
|
var v any
|
||||||
var ok bool
|
var ok bool
|
||||||
switch typedObj := obj.(type) {
|
switch typedObj := obj.(type) {
|
||||||
case *map[string]interface{}:
|
case *map[string]any:
|
||||||
obj = *typedObj
|
obj = *typedObj
|
||||||
}
|
}
|
||||||
switch typedObj := obj.(type) {
|
switch typedObj := obj.(type) {
|
||||||
case map[string]interface{}:
|
case map[string]any:
|
||||||
v, ok = typedObj[keys[0]]
|
v, ok = typedObj[keys[0]]
|
||||||
if !ok {
|
if !ok {
|
||||||
if defSet {
|
if defSet {
|
||||||
|
|
@ -59,7 +59,7 @@ func get(path string, varArgs ...interface{}) (interface{}, error) {
|
||||||
return nil, &noValueError{fmt.Sprintf("no value exist for key \"%s\" in %v", keys[0], typedObj)}
|
return nil, &noValueError{fmt.Sprintf("no value exist for key \"%s\" in %v", keys[0], typedObj)}
|
||||||
}
|
}
|
||||||
return v, nil
|
return v, nil
|
||||||
case map[interface{}]interface{}:
|
case map[any]any:
|
||||||
v, ok = typedObj[keys[0]]
|
v, ok = typedObj[keys[0]]
|
||||||
if !ok {
|
if !ok {
|
||||||
if defSet {
|
if defSet {
|
||||||
|
|
@ -70,7 +70,7 @@ func get(path string, varArgs ...interface{}) (interface{}, error) {
|
||||||
default:
|
default:
|
||||||
maybeStruct := reflect.ValueOf(typedObj)
|
maybeStruct := reflect.ValueOf(typedObj)
|
||||||
if maybeStruct.Kind() != reflect.Struct {
|
if maybeStruct.Kind() != reflect.Struct {
|
||||||
return nil, &noValueError{fmt.Sprintf("unexpected type(%v) of value for key \"%s\": it must be either map[string]interface{} or any struct", reflect.TypeOf(obj), keys[0])}
|
return nil, &noValueError{fmt.Sprintf("unexpected type(%v) of value for key \"%s\": it must be either map[string]any or any struct", reflect.TypeOf(obj), keys[0])}
|
||||||
} else if maybeStruct.NumField() < 1 {
|
} else if maybeStruct.NumField() < 1 {
|
||||||
return nil, &noValueError{fmt.Sprintf("no accessible struct fields for key \"%s\"", keys[0])}
|
return nil, &noValueError{fmt.Sprintf("no accessible struct fields for key \"%s\"", keys[0])}
|
||||||
}
|
}
|
||||||
|
|
@ -90,7 +90,7 @@ func get(path string, varArgs ...interface{}) (interface{}, error) {
|
||||||
return get(strings.Join(keys[1:], "."), v)
|
return get(strings.Join(keys[1:], "."), v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getOrNil(path string, o interface{}) (interface{}, error) {
|
func getOrNil(path string, o any) (any, error) {
|
||||||
v, err := get(path, o)
|
v, err := get(path, o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ func TestGetSimpleStruct(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetMap(t *testing.T) {
|
func TestGetMap(t *testing.T) {
|
||||||
obj := map[string]interface{}{"Foo": map[string]interface{}{"Bar": "Bar"}}
|
obj := map[string]any{"Foo": map[string]any{"Bar": "Bar"}}
|
||||||
|
|
||||||
v1, err := get("Foo.Bar", obj)
|
v1, err := get("Foo.Bar", obj)
|
||||||
|
|
||||||
|
|
@ -79,7 +79,7 @@ func TestGetMap(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetMapPtr(t *testing.T) {
|
func TestGetMapPtr(t *testing.T) {
|
||||||
obj := map[string]interface{}{"Foo": map[string]interface{}{"Bar": "Bar"}}
|
obj := map[string]any{"Foo": map[string]any{"Bar": "Bar"}}
|
||||||
objPrt := &obj
|
objPrt := &obj
|
||||||
|
|
||||||
v1, err := get("Foo.Bar", objPrt)
|
v1, err := get("Foo.Bar", objPrt)
|
||||||
|
|
@ -99,7 +99,7 @@ func TestGetMapPtr(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGet_Default(t *testing.T) {
|
func TestGet_Default(t *testing.T) {
|
||||||
obj := map[string]interface{}{"Foo": map[string]interface{}{}, "foo": 1}
|
obj := map[string]any{"Foo": map[string]any{}, "foo": 1}
|
||||||
|
|
||||||
v1, err := get("Foo.Bar", "Bar", obj)
|
v1, err := get("Foo.Bar", "Bar", obj)
|
||||||
|
|
||||||
|
|
@ -151,7 +151,7 @@ func TestGetOrNilStruct(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetOrNilMap(t *testing.T) {
|
func TestGetOrNilMap(t *testing.T) {
|
||||||
obj := map[string]interface{}{"Foo": map[string]interface{}{"Bar": "Bar"}}
|
obj := map[string]any{"Foo": map[string]any{"Bar": "Bar"}}
|
||||||
|
|
||||||
v1, err := getOrNil("Foo.Bar", obj)
|
v1, err := getOrNil("Foo.Bar", obj)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,14 @@ import (
|
||||||
type templateTextRenderer struct {
|
type templateTextRenderer struct {
|
||||||
ReadText func(string) ([]byte, error)
|
ReadText func(string) ([]byte, error)
|
||||||
Context *Context
|
Context *Context
|
||||||
Data interface{}
|
Data any
|
||||||
}
|
}
|
||||||
|
|
||||||
type TextRenderer interface {
|
type TextRenderer interface {
|
||||||
RenderTemplateText(text string) (string, error)
|
RenderTemplateText(text string) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTextRenderer(fs *filesystem.FileSystem, basePath string, data interface{}) *templateTextRenderer {
|
func NewTextRenderer(fs *filesystem.FileSystem, basePath string, data any) *templateTextRenderer {
|
||||||
return &templateTextRenderer{
|
return &templateTextRenderer{
|
||||||
ReadText: fs.ReadFile,
|
ReadText: fs.ReadFile,
|
||||||
Context: &Context{
|
Context: &Context{
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
// TestTextRenderer tests the text renderer.
|
// TestTextRenderer tests the text renderer.
|
||||||
func TestNewTextRenderer(t *testing.T) {
|
func TestNewTextRenderer(t *testing.T) {
|
||||||
tData := map[string]interface{}{
|
tData := map[string]any{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
}
|
}
|
||||||
tr := NewTextRenderer(filesystem.DefaultFileSystem(), ".", tData)
|
tr := NewTextRenderer(filesystem.DefaultFileSystem(), ".", tData)
|
||||||
|
|
@ -20,7 +20,7 @@ func TestNewTextRenderer(t *testing.T) {
|
||||||
|
|
||||||
// TestTextRenderer tests the text renderer.
|
// TestTextRenderer tests the text renderer.
|
||||||
func TestTextRender(t *testing.T) {
|
func TestTextRender(t *testing.T) {
|
||||||
tData := map[string]interface{}{
|
tData := map[string]any{
|
||||||
"foot": "bart",
|
"foot": "bart",
|
||||||
}
|
}
|
||||||
tr := NewTextRenderer(filesystem.DefaultFileSystem(), ".", tData)
|
tr := NewTextRenderer(filesystem.DefaultFileSystem(), ".", tData)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Encoder interface {
|
type Encoder interface {
|
||||||
Encode(interface{}) error
|
Encode(any) error
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24,7 +24,7 @@ func NewEncoder(w io.Writer) Encoder {
|
||||||
return v2.NewEncoder(w)
|
return v2.NewEncoder(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Unmarshal(data []byte, v interface{}) error {
|
func Unmarshal(data []byte, v any) error {
|
||||||
if runtime.GoccyGoYaml {
|
if runtime.GoccyGoYaml {
|
||||||
return yaml.Unmarshal(data, v)
|
return yaml.Unmarshal(data, v)
|
||||||
}
|
}
|
||||||
|
|
@ -36,7 +36,7 @@ func Unmarshal(data []byte, v interface{}) error {
|
||||||
// contained within the YAML document stream per each call.
|
// contained within the YAML document stream per each call.
|
||||||
// When strict is true, this function ensures that every field found in the YAML document
|
// When strict is true, this function ensures that every field found in the YAML document
|
||||||
// to have the corresponding field in the decoded Go struct.
|
// to have the corresponding field in the decoded Go struct.
|
||||||
func NewDecoder(data []byte, strict bool) func(interface{}) error {
|
func NewDecoder(data []byte, strict bool) func(any) error {
|
||||||
if runtime.GoccyGoYaml {
|
if runtime.GoccyGoYaml {
|
||||||
var opts []yaml.DecodeOption
|
var opts []yaml.DecodeOption
|
||||||
if strict {
|
if strict {
|
||||||
|
|
@ -48,7 +48,7 @@ func NewDecoder(data []byte, strict bool) func(interface{}) error {
|
||||||
opts...,
|
opts...,
|
||||||
)
|
)
|
||||||
|
|
||||||
return func(v interface{}) error {
|
return func(v any) error {
|
||||||
return decoder.Decode(v)
|
return decoder.Decode(v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -56,12 +56,12 @@ func NewDecoder(data []byte, strict bool) func(interface{}) error {
|
||||||
decoder := v2.NewDecoder(bytes.NewReader(data))
|
decoder := v2.NewDecoder(bytes.NewReader(data))
|
||||||
decoder.SetStrict(strict)
|
decoder.SetStrict(strict)
|
||||||
|
|
||||||
return func(v interface{}) error {
|
return func(v any) error {
|
||||||
return decoder.Decode(v)
|
return decoder.Decode(v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Marshal(v interface{}) ([]byte, error) {
|
func Marshal(v any) ([]byte, error) {
|
||||||
if runtime.GoccyGoYaml {
|
if runtime.GoccyGoYaml {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
yamlEncoder := yaml.NewEncoder(
|
yamlEncoder := yaml.NewEncoder(
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ func globYamlFilenames(dir string) (sets.Set[string], error) {
|
||||||
return set, nil
|
return set, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type resource map[string]interface{}
|
type resource map[string]any
|
||||||
|
|
||||||
type meta struct {
|
type meta struct {
|
||||||
apiVersion string
|
apiVersion string
|
||||||
|
|
@ -146,7 +146,7 @@ func (res resource) getMeta() meta {
|
||||||
m.apiVersion = apiVersion
|
m.apiVersion = apiVersion
|
||||||
kind, _ := res["kind"].(string)
|
kind, _ := res["kind"].(string)
|
||||||
m.kind = kind
|
m.kind = kind
|
||||||
metadata, _ := res["metadata"].(map[string]interface{})
|
metadata, _ := res["metadata"].(map[string]any)
|
||||||
name, _ := metadata["name"].(string)
|
name, _ := metadata["name"].(string)
|
||||||
m.name = name
|
m.name = name
|
||||||
namespace, _ := metadata["namespace"].(string)
|
namespace, _ := metadata["namespace"].(string)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ type tmplTestCase struct {
|
||||||
// tmplString is the template string to be parsed
|
// tmplString is the template string to be parsed
|
||||||
tmplString string
|
tmplString string
|
||||||
// data is the data to be passed to the template
|
// data is the data to be passed to the template
|
||||||
data interface{}
|
data any
|
||||||
// wantErr is true if the template should fail to parse
|
// wantErr is true if the template should fail to parse
|
||||||
wantErr bool
|
wantErr bool
|
||||||
// output is the expected output of the template
|
// output is the expected output of the template
|
||||||
|
|
@ -172,9 +172,9 @@ var fromYamlTestCases = []tmplTestCase{
|
||||||
|
|
||||||
var setValueAtPathTestCases = []tmplTestCase{
|
var setValueAtPathTestCases = []tmplTestCase{
|
||||||
{
|
{
|
||||||
data: map[string]interface{}{
|
data: map[string]any{
|
||||||
"root": map[string]interface{}{
|
"root": map[string]any{
|
||||||
"testKey": map[string]interface{}{
|
"testKey": map[string]any{
|
||||||
"testKey2": "test",
|
"testKey2": "test",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -185,7 +185,7 @@ var setValueAtPathTestCases = []tmplTestCase{
|
||||||
output: "testNewValue",
|
output: "testNewValue",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
data: map[string]interface{}{
|
data: map[string]any{
|
||||||
"root": "test",
|
"root": "test",
|
||||||
},
|
},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
|
|
@ -196,9 +196,9 @@ var setValueAtPathTestCases = []tmplTestCase{
|
||||||
|
|
||||||
var getTestCases = []tmplTestCase{
|
var getTestCases = []tmplTestCase{
|
||||||
{
|
{
|
||||||
data: map[string]interface{}{
|
data: map[string]any{
|
||||||
"root": map[string]interface{}{
|
"root": map[string]any{
|
||||||
"testGetKey": map[string]interface{}{
|
"testGetKey": map[string]any{
|
||||||
"testGetKey2": "test",
|
"testGetKey2": "test",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -208,9 +208,9 @@ var getTestCases = []tmplTestCase{
|
||||||
output: "test",
|
output: "test",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
data: map[string]interface{}{
|
data: map[string]any{
|
||||||
"root": map[string]interface{}{
|
"root": map[string]any{
|
||||||
"testGetKey": map[string]interface{}{
|
"testGetKey": map[string]any{
|
||||||
"testGetKey2": "test",
|
"testGetKey2": "test",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -223,7 +223,7 @@ var getTestCases = []tmplTestCase{
|
||||||
|
|
||||||
var tplTestCases = []tmplTestCase{
|
var tplTestCases = []tmplTestCase{
|
||||||
{
|
{
|
||||||
data: map[string]interface{}{
|
data: map[string]any{
|
||||||
"root": "tplvalue",
|
"root": "tplvalue",
|
||||||
},
|
},
|
||||||
name: "tpl",
|
name: "tpl",
|
||||||
|
|
@ -231,7 +231,7 @@ var tplTestCases = []tmplTestCase{
|
||||||
output: "tplvalue",
|
output: "tplvalue",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
data: map[string]interface{}{},
|
data: map[string]any{},
|
||||||
name: "tplInvalidTemplate",
|
name: "tplInvalidTemplate",
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
tmplString: `{{ . | tpl "{{ .root }}" }}`,
|
tmplString: `{{ . | tpl "{{ .root }}" }}`,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue