diff --git a/command/agent/namespace_endpoint_test.go b/command/agent/namespace_endpoint_test.go index 7cbf2301b..3c5b1bf2f 100644 --- a/command/agent/namespace_endpoint_test.go +++ b/command/agent/namespace_endpoint_test.go @@ -1,6 +1,3 @@ -//go:build ent -// +build ent - package agent import ( diff --git a/command/namespace_apply.go b/command/namespace_apply.go index edab6bff2..a6acd0da7 100644 --- a/command/namespace_apply.go +++ b/command/namespace_apply.go @@ -61,7 +61,11 @@ func (c *NamespaceApplyCommand) AutocompleteFlags() complete.Flags { } func (c *NamespaceApplyCommand) AutocompleteArgs() complete.Predictor { - return NamespacePredictor(c.Meta.Client, nil) + return complete.PredictOr( + NamespacePredictor(c.Meta.Client, nil), + complete.PredictFiles("*.hcl"), + complete.PredictFiles("*.json"), + ) } func (c *NamespaceApplyCommand) Synopsis() string { diff --git a/command/namespace_apply_test.go b/command/namespace_apply_test.go index a5611e2ad..95164b2ba 100644 --- a/command/namespace_apply_test.go +++ b/command/namespace_apply_test.go @@ -1,6 +1,3 @@ -//go:build ent -// +build ent - package command import ( diff --git a/command/namespace_delete_test.go b/command/namespace_delete_test.go index 155f2cff7..95fe7c8ba 100644 --- a/command/namespace_delete_test.go +++ b/command/namespace_delete_test.go @@ -1,6 +1,3 @@ -//go:build ent -// +build ent - package command import ( diff --git a/command/namespace_inspect_test.go b/command/namespace_inspect_test.go index 296b0fa5d..35bfef085 100644 --- a/command/namespace_inspect_test.go +++ b/command/namespace_inspect_test.go @@ -1,6 +1,3 @@ -//go:build ent -// +build ent - package command import ( diff --git a/command/namespace_list_test.go b/command/namespace_list_test.go index 822199c62..b8e662bdd 100644 --- a/command/namespace_list_test.go +++ b/command/namespace_list_test.go @@ -1,6 +1,3 @@ -//go:build ent -// +build ent - package command import ( @@ -10,10 +7,7 @@ import ( "github.com/mitchellh/cli" ) -func TestNamespaceListCommand_Implements(t *testing.T) { - t.Parallel() - var _ cli.Command = &NamespaceListCommand{} -} +var _ cli.Command = (*NamespaceListCommand)(nil) func TestNamespaceListCommand_Fails(t *testing.T) { t.Parallel() diff --git a/command/namespace_status.go b/command/namespace_status.go index 654d1883d..d9d59d76d 100644 --- a/command/namespace_status.go +++ b/command/namespace_status.go @@ -84,14 +84,12 @@ func (c *NamespaceStatusCommand) Run(args []string) int { if len(ns.Meta) > 0 { c.Ui.Output(c.Colorize().Color("\n[bold]Metadata[reset]")) - var keys []string + var meta []string for k := range ns.Meta { - keys = append(keys, k) - } - sort.Strings(keys) - for _, k := range keys { - c.Ui.Output(fmt.Sprintf("%s:\x1f%s", k, ns.Meta[k])) + meta = append(meta, fmt.Sprintf("%s|%s", k, ns.Meta[k])) } + sort.Strings(meta) + c.Ui.Output(formatKV(meta)) } if ns.Quota != "" { diff --git a/command/namespace_status_oss_test.go b/command/namespace_status_oss_test.go new file mode 100644 index 000000000..7bc4d2e56 --- /dev/null +++ b/command/namespace_status_oss_test.go @@ -0,0 +1,10 @@ +//go:build !ent +// +build !ent + +package command + +import "github.com/hashicorp/nomad/api" + +func testQuotaSpec() *api.QuotaSpec { + panic("not implemented - enterprise only") +} diff --git a/command/namespace_status_test.go b/command/namespace_status_test.go index 74073b8f2..fa70ed218 100644 --- a/command/namespace_status_test.go +++ b/command/namespace_status_test.go @@ -1,6 +1,3 @@ -//go:build ent -// +build ent - package command import ( @@ -77,6 +74,10 @@ func TestNamespaceStatusCommand_Good_Quota(t *testing.T) { srv, client, url := testServer(t, true, nil) defer srv.Shutdown() + if !srv.Enterprise { + t.Skip("Skipping enterprise-only quota test") + } + ui := cli.NewMockUi() cmd := &NamespaceStatusCommand{Meta: Meta{Ui: ui}} diff --git a/website/content/api-docs/namespaces.mdx b/website/content/api-docs/namespaces.mdx index 882a279a4..33c6363a8 100644 --- a/website/content/api-docs/namespaces.mdx +++ b/website/content/api-docs/namespaces.mdx @@ -48,17 +48,24 @@ $ curl \ ```json [ { - "CreateIndex": 31, - "Description": "Production API Servers", - "ModifyIndex": 31, - "Name": "api-prod", + "Capabilities": null, + "CreateIndex": 1, + "Description": "Default shared namespace", + "Meta": null, + "ModifyIndex": 1, + "Name": "default", "Quota": "" }, { - "CreateIndex": 5, - "Description": "Default shared namespace", - "ModifyIndex": 5, - "Name": "default", + "Capabilities": null, + "CreateIndex": 17, + "Description": "Development Staging Namespace", + "Meta": { + "type": "dev", + "contact": "helpdesk@example.com" + }, + "ModifyIndex": 17, + "Name": "staging", "Quota": "" } ] @@ -88,19 +95,23 @@ The table below shows this endpoint's support for ```shell-session $ curl \ - https://localhost:4646/v1/namespace/api-prod + https://localhost:4646/v1/namespace/staging ``` ### Sample Response ```json { - "CreateIndex": 31, - "Description": "Production API Servers", - "Quota": "", - "Hash": "N8WvePwqkp6J354eLJMKyhvsFdPELAos0VuBfMoVKoU=", - "ModifyIndex": 31, - "Name": "api-prod" + "Capabilities": null, + "CreateIndex": 17, + "Description": "Development Staging Namespace", + "Meta": { + "type": "dev", + "contact": "helpdesk@example.com" + }, + "ModifyIndex": 17, + "Name": "staging", + "Quota": "" } ``` @@ -128,6 +139,10 @@ The table below shows this endpoint's support for - `Description` `(string: "")` - Specifies an optional human-readable description of the namespace. +- `Meta` `(object: null)` - Optional object with string keys and values of + metadata to attach to the namespace. Namespace metadata is not used by Nomad + and is intended for use by operators and third party tools. + - `Quota` `(string: "")` - Specifies an quota to attach to the namespace. ### Sample Payload @@ -136,10 +151,15 @@ The table below shows this endpoint's support for { "Name": "api-prod", "Description": "Production API Servers", + "Meta": { + "contact": "platform-eng@example.com" + }, "Quota": "prod-quota" } ``` +Note that the `Quota` key is Enterprise-only. + ### Sample Request ```shell-session diff --git a/website/content/docs/commands/namespace/apply.mdx b/website/content/docs/commands/namespace/apply.mdx index fa54517c2..3f42e8e8b 100644 --- a/website/content/docs/commands/namespace/apply.mdx +++ b/website/content/docs/commands/namespace/apply.mdx @@ -18,7 +18,7 @@ when introduced in Nomad 0.7. nomad namespace apply [options] ``` -Apply is used to create or update a namespace. The specification file +Apply is used to create or update a namespace. The HCL specification file will be read from stdin by specifying "-", otherwise a path to the file is expected. @@ -37,7 +37,7 @@ If ACLs are enabled, this command requires a management ACL token. - `-description` : An optional human readable description for the namespace. -- `json` : Parse the input as a JSON namespace specification. +- `-json` : Parse the input as a JSON namespace specification. ## Examples @@ -56,7 +56,7 @@ $ nomad namespace apply -quota= api-prod Create a namespace from a file: ```shell-session -$ cat namespace.json +$ cat namespace.hcl name = "dev" description = "Namespace for developers" @@ -66,8 +66,8 @@ capabilities { } meta { - owner = "John Doe" + owner = "John Doe" contact_mail = "john@mycompany.com } -$ nomad namespace apply namespace.json +$ nomad namespace apply namespace.hcl ``` diff --git a/website/content/docs/commands/namespace/status.mdx b/website/content/docs/commands/namespace/status.mdx index 570b065e6..5a51e3ac6 100644 --- a/website/content/docs/commands/namespace/status.mdx +++ b/website/content/docs/commands/namespace/status.mdx @@ -33,11 +33,14 @@ View the status of a namespace: ```shell-session $ nomad namespace status default -Name = default -Description = Default shared namespace -Quota = shared-default-quota +Name = api-prod +Description = Prod API servers +Quota = prod EnabledDrivers = docker,exec DisabledDrivers = raw_exec + +Metadata +contact = platform-eng@example.com Quota Limits Region CPU Usage Memory Usage