Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/tanka/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func findJsonnetFilesFromPaths(paths []string, opts FindOpts) ([]string, error)
jsonnetFiles, err := jsonnet.FindFiles(path, nil)
var mainFiles []string
for _, file := range jsonnetFiles {
if filepath.Base(file) == jpath.DefaultEntrypoint {
if filepath.Base(file) == jpath.DefaultEntrypoint || file == path {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it perhaps make sense here to restrict that to only files with the suffix .jsonnet? For me, *.libsonnet files would not look like entrypoints to me. WDYT?

mainFiles = append(mainFiles, file)
}
}
Expand Down
26 changes: 26 additions & 0 deletions pkg/tanka/find_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,29 @@ func buildLargeEnvironmentDirForFindTest(t testing.TB) (string, []string) {

return tempDir, envPaths
}

func TestFindInlineEnvWithNonStandardEntrypoint(t *testing.T) {
tempDir := t.TempDir()

// Create an inline environment with an entrypoint named something other than main.jsonnet
entrypoint := filepath.Join(tempDir, "entrypoint.libsonnet")
require.NoError(t, os.WriteFile(filepath.Join(tempDir, "jsonnetfile.json"), []byte(`{}`), 0644))
require.NoError(t, os.WriteFile(entrypoint, []byte(`{
"apiVersion": "tanka.dev/v1alpha1",
"kind": "Environment",
"metadata": {
"name": "test-name",
"labels": {}
},
"spec": {
"apiServer": "https://192.168.0.1",
"namespace": "test-namespace",
"cluster": "test-cluster"
}
}`), 0644))

// Verify the environment is found if the entrypoint's file name is explicitly specified
envs, err := findJsonnetFilesFromPaths([]string{entrypoint}, FindOpts{Parallelism: 1})
require.NoError(t, err)
require.Len(t, envs, 1)
}
Loading