Merge branch 'f-ns-meta' of ssh://github.com/jorgemarey/nomad into f-ns-meta

This commit is contained in:
Jorge Marey
2022-03-07 10:57:41 +01:00
12 changed files with 70 additions and 52 deletions

View File

@@ -1,6 +1,3 @@
//go:build ent
// +build ent
package agent
import (

View File

@@ -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 {

View File

@@ -1,6 +1,3 @@
//go:build ent
// +build ent
package command
import (

View File

@@ -1,6 +1,3 @@
//go:build ent
// +build ent
package command
import (

View File

@@ -1,6 +1,3 @@
//go:build ent
// +build ent
package command
import (

View File

@@ -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()

View File

@@ -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 != "" {

View File

@@ -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")
}

View File

@@ -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}}

View File

@@ -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

View File

@@ -18,7 +18,7 @@ when introduced in Nomad 0.7.
nomad namespace apply [options] <input>
```
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
```

View File

@@ -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