From 28038bdf4797f4f625442aed1484f19ee8be96e4 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Mon, 5 Apr 2021 09:45:55 -0600 Subject: [PATCH] consul: minor CR cleanup --- CHANGELOG.md | 2 +- command/agent/consul/check_watcher.go | 2 +- command/agent/consul/service_client.go | 6 +++++- command/job_init.bindata_assetfs.go | 8 ++++---- nomad/consul_test.go | 16 +++++----------- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bb341fcb..b81974292 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## 1.1.0 (Unreleased) FEATURES: - * **Consul Namespaces**: Adds support for Consul Namespaces [[GH-10235](https://github.com/hashicorp/nomad/pull/10235)] + * **Consul Namespaces (Enterprise)**: Adds support for Consul Namespaces [[GH-10235](https://github.com/hashicorp/nomad/pull/10235)] * **Licensing (Enterprise)**: Support loading Enterprise license from disk or environment. [[GH-10216](https://github.com/hashicorp/nomad/issues/10216)] * **Readiness Checks**: Adds `service` and `check` `on_update` configuration to support liveness and readiness checks. [[GH-9955](https://github.com/hashicorp/nomad/issues/9955)] diff --git a/command/agent/consul/check_watcher.go b/command/agent/consul/check_watcher.go index 295a7f4fc..ee2e18a28 100644 --- a/command/agent/consul/check_watcher.go +++ b/command/agent/consul/check_watcher.go @@ -282,7 +282,7 @@ WATCHER: if !ok { // Only warn if outside grace period to avoid races with check registration if now.After(check.graceUntil) { - // w.logger.Warn("watched check not found in Consul", "check", check.checkName, "check_id", cid) // add back + w.logger.Warn("watched check not found in Consul", "check", check.checkName, "check_id", cid) } continue } diff --git a/command/agent/consul/service_client.go b/command/agent/consul/service_client.go index 9c451754b..6da8097ac 100644 --- a/command/agent/consul/service_client.go +++ b/command/agent/consul/service_client.go @@ -807,6 +807,10 @@ func (c *ServiceClient) sync(reason syncReason) error { // asynchronous. // // Agents will be deregistered when Shutdown is called. +// +// Note: no need to manually plumb Consul namespace into the agent service registration +// or its check registrations, because the Nomad Client's Consul Client will already +// have the Nomad Client's Consul Namespace set on startup. func (c *ServiceClient) RegisterAgent(role string, services []*structs.Service) error { ops := operations{} @@ -855,7 +859,7 @@ func (c *ServiceClient) RegisterAgent(role string, services []*structs.Service) } checkHost, checkPort = host, port } - checkReg, err := createCheckReg(id, checkID, check, checkHost, checkPort, "") // todo ... whats up with agent namespace and its checks? + checkReg, err := createCheckReg(id, checkID, check, checkHost, checkPort, "") if err != nil { return fmt.Errorf("failed to add check %q: %v", check.Name, err) } diff --git a/command/job_init.bindata_assetfs.go b/command/job_init.bindata_assetfs.go index 9677c0860..8b0c01d37 100644 --- a/command/job_init.bindata_assetfs.go +++ b/command/job_init.bindata_assetfs.go @@ -87,7 +87,7 @@ func commandAssetsConnectShortNomad() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "command/assets/connect-short.nomad", size: 997, mode: os.FileMode(436), modTime: time.Unix(1616684356, 0)} + info := bindataFileInfo{name: "command/assets/connect-short.nomad", size: 997, mode: os.FileMode(436), modTime: time.Unix(1612560436, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -107,7 +107,7 @@ func commandAssetsConnectNomad() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "command/assets/connect.nomad", size: 17842, mode: os.FileMode(436), modTime: time.Unix(1616684356, 0)} + info := bindataFileInfo{name: "command/assets/connect.nomad", size: 17842, mode: os.FileMode(436), modTime: time.Unix(1612560436, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -127,7 +127,7 @@ func commandAssetsExampleShortNomad() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "command/assets/example-short.nomad", size: 324, mode: os.FileMode(436), modTime: time.Unix(1616684356, 0)} + info := bindataFileInfo{name: "command/assets/example-short.nomad", size: 324, mode: os.FileMode(436), modTime: time.Unix(1612560436, 0)} a := &asset{bytes: bytes, info: info} return a, nil } @@ -147,7 +147,7 @@ func commandAssetsExampleNomad() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "command/assets/example.nomad", size: 16057, mode: os.FileMode(436), modTime: time.Unix(1616684356, 0)} + info := bindataFileInfo{name: "command/assets/example.nomad", size: 16057, mode: os.FileMode(436), modTime: time.Unix(1612560436, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/nomad/consul_test.go b/nomad/consul_test.go index 1dde65b92..cbc0bf431 100644 --- a/nomad/consul_test.go +++ b/nomad/consul_test.go @@ -341,26 +341,20 @@ func TestConsulACLsAPI_Stop(t *testing.T) { require.Error(t, err) } -// CheckPermissions(ctx context.Context, namespace string, usage *structs.ConsulUsage) error - func TestConsulACLsAPI_CheckPermissions(t *testing.T) { t.Parallel() - equalError := func(t *testing.T, exp, err error) { - if exp == nil { - require.NoError(t, err) - } else { - require.Equal(t, exp.Error(), err.Error()) - } - } - try := func(t *testing.T, namespace string, usage *structs.ConsulUsage, secretID string, exp error) { logger := testlog.HCLogger(t) aclAPI := consul.NewMockACLsAPI(logger) cAPI := NewConsulACLsAPI(aclAPI, logger, nil) err := cAPI.CheckPermissions(context.Background(), namespace, usage, secretID) - equalError(t, exp, err) + if exp == nil { + require.NoError(t, err) + } else { + require.Equal(t, exp.Error(), err.Error()) + } } t.Run("check-permissions kv read", func(t *testing.T) {