Skip to content

Commit

Permalink
fix(jsonnet): TLA in export panic (#519)
Browse files Browse the repository at this point in the history
Assigning to an improperly initialized map type caused a panic. Fixed by properly initializing
  • Loading branch information
morlay committed Feb 26, 2021
1 parent f88c104 commit 97ed7fc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion pkg/jsonnet/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ type Opts struct {

// Clone returns a deep copy of Opts
func (o Opts) Clone() Opts {
var extCode, tlaCode InjectedCode
extCode, tlaCode := InjectedCode{}, InjectedCode{}

for k, v := range o.ExtCode {
extCode[k] = v
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/tanka/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

// FindOpts are optional arguments for FindEnvs
type FindOpts struct {
JsonnetOpts
Selector labels.Selector
}

Expand All @@ -20,7 +21,7 @@ type FindOpts struct {
// are not checked.
func FindEnvs(path string, opts FindOpts) ([]*v1alpha1.Environment, error) {
// find all environments at dir
envs, err := find(path)
envs, err := find(path, Opts{JsonnetOpts: opts.JsonnetOpts})
if err != nil {
return nil, err
}
Expand All @@ -42,9 +43,9 @@ func FindEnvs(path string, opts FindOpts) ([]*v1alpha1.Environment, error) {
}

// find implements the actual functionality described at 'FindEnvs'
func find(path string) ([]*v1alpha1.Environment, error) {
func find(path string, opts Opts) ([]*v1alpha1.Environment, error) {
// try if this has envs
list, err := List(path, Opts{})
list, err := List(path, opts)
if len(list) != 0 && err == nil {
// it has. don't search deeper
return list, nil
Expand Down Expand Up @@ -77,7 +78,7 @@ func find(path string) ([]*v1alpha1.Environment, error) {
}

routines++
go findShim(filepath.Join(path, fi.Name()), ch)
go findShim(filepath.Join(path, fi.Name()), opts, ch)
}

// collect parallel results
Expand Down Expand Up @@ -105,7 +106,7 @@ type findOut struct {
err error
}

func findShim(dir string, ch chan findOut) {
envs, err := find(dir)
func findShim(dir string, opts Opts, ch chan findOut) {
envs, err := find(dir, opts)
ch <- findOut{envs: envs, err: err}
}
2 changes: 1 addition & 1 deletion pkg/tanka/parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func parallelLoadEnvironments(paths []string, opts parallelOpts) ([]*v1alpha1.En
jobsCh := make(chan parallelJob)
list := make(map[string]string)
for _, path := range paths {
envs, err := FindEnvs(path, FindOpts{opts.Selector})
envs, err := FindEnvs(path, FindOpts{Selector: opts.Selector, JsonnetOpts: opts.JsonnetOpts})
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 97ed7fc

Please sign in to comment.