Skip to content

Commit

Permalink
tk tool importers: Follow through main files (grafana#888)
Browse files Browse the repository at this point in the history
If a main file imports another main file, we currently don't follow
This can lead to Tanka not diffing/applying all the environments it should, when the base environment changes
  • Loading branch information
julienduchesne committed Jul 12, 2023
1 parent e0bb1eb commit 0499ee0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pkg/jsonnet/find_importers.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,8 @@ func findImporters(root string, searchForFile string, chain map[string]struct{})
if isImporter {
if jsonnetFileContent.IsMainFile {
importers = append(importers, jsonnetFilePath)
} else {
intermediateImporters = append(intermediateImporters, jsonnetFilePath)
}
intermediateImporters = append(intermediateImporters, jsonnetFilePath)
break
}
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/jsonnet/find_importers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ func findImportersTestCases(t testing.TB) []findImportersTestCase {
absPath(t, "testdata/findImporters/environments/no-imports/main.jsonnet"),
},
},
{
name: "imports through a main file are followed",
files: []string{
"testdata/findImporters/environments/import-other-main-file/env2/file.libsonnet",
},
expectedImporters: []string{
absPath(t, "testdata/findImporters/environments/import-other-main-file/env1/main.jsonnet"),
absPath(t, "testdata/findImporters/environments/import-other-main-file/env2/main.jsonnet"),
},
},
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
otherMain: import '../env2/main.jsonnet',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
myfile: import 'file.libsonnet',
}

0 comments on commit 0499ee0

Please sign in to comment.