feat: Allow entrypoints other than main.jsonnet when searching for environments#1250
Open
sabeechen wants to merge 2 commits into
Open
feat: Allow entrypoints other than main.jsonnet when searching for environments#1250sabeechen wants to merge 2 commits into
sabeechen wants to merge 2 commits into
Conversation
Contributor
|
Thanks for giving this one a try 🙂 So far I also cannot really think of any negative side-effects for existing cases. The default entrypoint is also used for the |
zerok
reviewed
Feb 5, 2025
| var mainFiles []string | ||
| for _, file := range jsonnetFiles { | ||
| if filepath.Base(file) == jpath.DefaultEntrypoint { | ||
| if filepath.Base(file) == jpath.DefaultEntrypoint || file == path { |
Contributor
There was a problem hiding this comment.
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?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When using inline environments, some
tkcommands produce empty results when using an entrypoint whose filename is anything other thanmain.jsonnet.Example
You can reproduce the behavior by creating a simple project with an inline environments having two entrypoint files:
main.jsonnet
{ apiVersion: 'tanka.dev/v1alpha1', kind: 'Environment', metadata: { name: 'main', }, spec: { apiServer: 'https://localhost', namespace: 'default', }, data: { apiVersion: 'v1', kind: 'ConfigMap', metadata: { name: 'config' }, }, }other.jsonnet
With this setup running the commands:
tk env list main.jsonnet tk export export-dir main.jsonnet --recursiveWill produce the expected result, either listing the environment or exporting a
ConfigMapmanifest. However running:tk env list other.jsonnet tk export export-dir other.jsonnet --recursivewill not print any environments and exports nothing. Running
tk export export-dir other.jsonnet --name mainwill, however, export the manifests for the environment. This behavior feels inconsistent. I'm not sure if supporting this should be considered a feature or bug.Rationale
My organization's tanka-based stack makes heavy use of inline environments to generate its manifests. In the never-ending search for "the cleanest way to do things" we sometimes find it convenient to create two entrypoints for a project where one selectively uses manifests from the other. But only one can be named
main.jsonnet, which has made building automated tooling that depends on usingenv listor--recursiveto find environments troublesome. Admittedly, this may be a niche use case and it could be solved using external variables.Solution
I've modified
find.gosuch that if the requested search path for environments is exactly the name of the found file, then it is considered a mainfile. this seems to resolve the inconsistency in behavior for inline environments and I struggle to think of a way it could cause problems.