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

cli: detect directory when applying namespace spec file #12738

Merged
merged 1 commit into from
Apr 21, 2022

Conversation

tgross
Copy link
Member

@tgross tgross commented Apr 21, 2022

The new namespace apply feature that allows for passing a namespace
specification file detects the difference between an empty namespace
and a namespace specification by checking if the file exists. For most
cases, the file will have an extension like .hcl and so there's
little danger that a user will apply a file spec when they intended to
apply a file name.

But because directory names typically don't include an extension,
you're much more likely to collide when trying to namespace apply by
name only, and then you get a confusing error message of the form:

Failed to read file: read $namespace: is a directory

Detect the case where the namespace name collides with a directory in
the current working directory, and skip trying to load the directory.


No changelog entry, as this feature shipped for the first time in Nomad 1.3.0-beta.1 (ref #11813)

Before:

$ nomad namespace apply prod
Successfully applied namespace "prod"!

$ nomad namespace apply ./namespace.hcl
Successfully applied namespace "staging"!

$ nomad namespace apply dev
Failed to read file: read dev: is a directory

After:

$ nomad namespace apply prod
Successfully applied namespace "prod"!

$ nomad namespace apply ./namespace.hcl
Successfully applied namespace "staging"!

$ nomad namespace apply dev
Successfully applied namespace "dev"!

The new `namespace apply` feature that allows for passing a namespace
specification file detects the difference between an empty namespace
and a namespace specification by checking if the file exists. For most
cases, the file will have an extension like `.hcl` and so there's
little danger that a user will apply a file spec when they intended to
apply a file name.

But because directory names typically don't include an extension,
you're much more likely to collide when trying to `namespace apply` by
name only, and then you get a confusing error message of the form:

   Failed to read file: read $namespace: is a directory

Detect the case where the namespace name collides with a directory in
the current working directory, and skip trying to load the directory.
Copy link
Contributor

@DerekStrickland DerekStrickland left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@shoenig shoenig left a comment

Choose a reason for hiding this comment

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

LGTM!

@tgross tgross merged commit 42bcb74 into main Apr 21, 2022
@tgross tgross deleted the cli-namespace-apply-directory branch April 21, 2022 18:53
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants