Skip to content

Commit

Permalink
cli: detect directory when applying namespace spec file (#12738)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tgross authored Apr 21, 2022
1 parent a977577 commit 42bcb74
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions command/namespace_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Usage: nomad namespace apply [options] <input>
Apply is used to create or update a namespace. The specification file
will be read from stdin by specifying "-", otherwise a path to the file is
expected.
Instead of a file, you may instead pass the namespace name to create
or update as the only argument.
Expand Down Expand Up @@ -114,7 +114,7 @@ func (c *NamespaceApplyCommand) Run(args []string) int {
return 1
}

if _, err = os.Stat(file); file == "-" || err == nil {
if fi, err := os.Stat(file); (file == "-" || err == nil) && !fi.IsDir() {
if quota != nil || description != nil {
c.Ui.Warn("Flags are ignored when a file is specified!")
}
Expand Down
2 changes: 1 addition & 1 deletion website/content/docs/commands/namespace/apply.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ capabilities {
meta {
owner = "John Doe"
contact_mail = "john@mycompany.com
contact_mail = "john@mycompany.com"
}
$ nomad namespace apply namespace.hcl
```

0 comments on commit 42bcb74

Please sign in to comment.