diff --git a/pkg/tanka/find.go b/pkg/tanka/find.go index 4dad7b3ae..e0bf2b974 100644 --- a/pkg/tanka/find.go +++ b/pkg/tanka/find.go @@ -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 { mainFiles = append(mainFiles, file) } } diff --git a/pkg/tanka/find_test.go b/pkg/tanka/find_test.go index 5f2f20a03..749f6ae26 100644 --- a/pkg/tanka/find_test.go +++ b/pkg/tanka/find_test.go @@ -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) +}