Skip to content

Commit

Permalink
fix: introduce concatenate function to avoid reusing arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Zebradil committed Sep 13, 2023
1 parent 083b251 commit c07a30c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/myks/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (a *Application) Init() error {

a.collectDataFiles()

dataYaml, err := a.renderDataYaml(append(a.e.g.extraYttPaths, a.yttDataFiles...))
dataYaml, err := a.renderDataYaml(concatenate(a.e.g.extraYttPaths, a.yttDataFiles))
if err != nil {
return err
}
Expand Down Expand Up @@ -179,7 +179,7 @@ func (a *Application) ytt(step, purpose string, paths []string, args ...string)
}

func (a *Application) yttS(step string, purpose string, paths []string, stdin io.Reader, args ...string) (CmdResult, error) {
paths = append(a.e.g.extraYttPaths, paths...)
paths = concatenate(a.e.g.extraYttPaths, paths)
return runYttWithFilesAndStdin(paths, stdin, func(name string, args []string) {
log.Debug().Msg(a.Msg(step, msgRunCmd(purpose, name, args)))
}, args...)
Expand Down
2 changes: 1 addition & 1 deletion internal/myks/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (e *Environment) ytt(purpose string, paths []string, args ...string) (CmdRe
}

func (e *Environment) yttS(purpose string, paths []string, stdin io.Reader, args ...string) (CmdResult, error) {
paths = append(e.g.extraYttPaths, paths...)
paths = concatenate(e.g.extraYttPaths, paths)
return runYttWithFilesAndStdin(paths, stdin, func(name string, args []string) {
log.Debug().Msg(e.Msg(msgRunCmd(purpose, name, args)))
}, args...)
Expand Down
2 changes: 1 addition & 1 deletion internal/myks/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (a *Application) prepareValuesFile(dirName string, resourceName string) (st
return "", nil
}

resourceValuesYaml, err := a.ytt(renderStepName, "collect data values file", append(a.yttDataFiles, valuesFiles...))
resourceValuesYaml, err := a.ytt(renderStepName, "collect data values file", concatenate(a.yttDataFiles, valuesFiles))
if err != nil {
log.Warn().Err(err).Msg(a.Msg(renderStepName, "Unable to render resource values templates"))
return "", err
Expand Down
9 changes: 9 additions & 0 deletions internal/myks/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,12 @@ func extract[T any](items []T, filterFunc func(cf T) bool) []T {
}
return result
}

// Concatenates multiple slices of the same type together creating a new underlying array
func concatenate[T any](slices ...[]T) []T {
result := []T{}
for _, slice := range slices {
result = append(result, slice...)
}
return result
}

0 comments on commit c07a30c

Please sign in to comment.