Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow entrypoints other than main.jsonnet when searching for environments #1250

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sabeechen
Copy link
Contributor

Description

When using inline environments, some tk commands produce empty results when using an entrypoint whose filename is anything other than main.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

import 'main.jsonnet'

With this setup running the commands:

tk env list main.jsonnet
tk export export-dir main.jsonnet --recursive

Will produce the expected result, either listing the environment or exporting a ConfigMap manifest. However running:

tk env list other.jsonnet
tk export export-dir other.jsonnet --recursive

will not print any environments and exports nothing. Running tk export export-dir other.jsonnet --name main will, 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 using env list or --recursive to find environments troublesome. Admittedly, this may be a niche use case and it could be solved using external variables.

Solution

I've modified find.go such 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.

@sabeechen sabeechen requested a review from a team as a code owner November 28, 2024 06:13
@zerok
Copy link
Contributor

zerok commented Dec 2, 2024

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 importers command. If I'm not mistaken then your change should probably also be somehow integrated there. But perhaps I'm also confusing the use-cases these two...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants