From cded17cbaf33116440ea9c54194da3731eb41259 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Thu, 13 May 2021 11:30:31 -0700 Subject: [PATCH] client: fix multiple imports (#10537) --- client/alloc_endpoint.go | 17 ++++++++--------- client/alloc_endpoint_test.go | 10 +++++----- client/client_test.go | 3 +-- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/client/alloc_endpoint.go b/client/alloc_endpoint.go index 986986386..6b1ff7604 100644 --- a/client/alloc_endpoint.go +++ b/client/alloc_endpoint.go @@ -15,7 +15,6 @@ import ( cstructs "github.com/hashicorp/nomad/client/structs" "github.com/hashicorp/nomad/helper" "github.com/hashicorp/nomad/helper/uuid" - "github.com/hashicorp/nomad/nomad/structs" nstructs "github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/plugins/drivers" ) @@ -144,8 +143,8 @@ func (a *Allocations) exec(conn io.ReadWriteCloser) { defer conn.Close() execID := uuid.Generate() - decoder := codec.NewDecoder(conn, structs.MsgpackHandle) - encoder := codec.NewEncoder(conn, structs.MsgpackHandle) + decoder := codec.NewDecoder(conn, nstructs.MsgpackHandle) + encoder := codec.NewEncoder(conn, nstructs.MsgpackHandle) code, err := a.execImpl(encoder, decoder, execID) if err != nil { @@ -166,7 +165,7 @@ func (a *Allocations) execImpl(encoder *codec.Encoder, decoder *codec.Decoder, e } if a.c.GetConfig().DisableRemoteExec { - return nil, structs.ErrPermissionDenied + return nil, nstructs.ErrPermissionDenied } if req.AllocID == "" { @@ -175,7 +174,7 @@ func (a *Allocations) execImpl(encoder *codec.Encoder, decoder *codec.Decoder, e ar, err := a.c.getAllocRunner(req.AllocID) if err != nil { code := helper.Int64ToPtr(500) - if structs.IsErrUnknownAllocation(err) { + if nstructs.IsErrUnknownAllocation(err) { code = helper.Int64ToPtr(404) } @@ -206,7 +205,7 @@ func (a *Allocations) execImpl(encoder *codec.Encoder, decoder *codec.Decoder, e if err != nil { return nil, err } else if aclObj != nil && !aclObj.AllowNsOp(alloc.Namespace, acl.NamespaceCapabilityAllocExec) { - return nil, structs.ErrPermissionDenied + return nil, nstructs.ErrPermissionDenied } // Validate the arguments @@ -220,7 +219,7 @@ func (a *Allocations) execImpl(encoder *codec.Encoder, decoder *codec.Decoder, e capabilities, err := ar.GetTaskDriverCapabilities(req.Task) if err != nil { code := helper.Int64ToPtr(500) - if structs.IsErrUnknownAllocation(err) { + if nstructs.IsErrUnknownAllocation(err) { code = helper.Int64ToPtr(404) } @@ -231,14 +230,14 @@ func (a *Allocations) execImpl(encoder *codec.Encoder, decoder *codec.Decoder, e if aclObj != nil && capabilities.FSIsolation == drivers.FSIsolationNone { exec := aclObj.AllowNsOp(alloc.Namespace, acl.NamespaceCapabilityAllocNodeExec) if !exec { - return nil, structs.ErrPermissionDenied + return nil, nstructs.ErrPermissionDenied } } allocState, err := a.c.GetAllocState(req.AllocID) if err != nil { code := helper.Int64ToPtr(500) - if structs.IsErrUnknownAllocation(err) { + if nstructs.IsErrUnknownAllocation(err) { code = helper.Int64ToPtr(404) } diff --git a/client/alloc_endpoint_test.go b/client/alloc_endpoint_test.go index dfdda310c..bc7205159 100644 --- a/client/alloc_endpoint_test.go +++ b/client/alloc_endpoint_test.go @@ -779,7 +779,7 @@ func TestAlloc_ExecStreaming_ACL_Basic(t *testing.T) { { Name: "bad token", Token: tokenBad.SecretID, - ExpectedError: structs.ErrPermissionDenied.Error(), + ExpectedError: nstructs.ErrPermissionDenied.Error(), }, { Name: "good token", @@ -912,7 +912,7 @@ func TestAlloc_ExecStreaming_ACL_WithIsolation_Image(t *testing.T) { { Name: "bad token", Token: tokenBad.SecretID, - ExpectedError: structs.ErrPermissionDenied.Error(), + ExpectedError: nstructs.ErrPermissionDenied.Error(), }, { Name: "alloc-exec token", @@ -1061,7 +1061,7 @@ func TestAlloc_ExecStreaming_ACL_WithIsolation_Chroot(t *testing.T) { { Name: "bad token", Token: tokenBad.SecretID, - ExpectedError: structs.ErrPermissionDenied.Error(), + ExpectedError: nstructs.ErrPermissionDenied.Error(), }, { Name: "alloc-exec token", @@ -1205,12 +1205,12 @@ func TestAlloc_ExecStreaming_ACL_WithIsolation_None(t *testing.T) { { Name: "bad token", Token: tokenBad.SecretID, - ExpectedError: structs.ErrPermissionDenied.Error(), + ExpectedError: nstructs.ErrPermissionDenied.Error(), }, { Name: "alloc-exec token", Token: tokenAllocExec.SecretID, - ExpectedError: structs.ErrPermissionDenied.Error(), + ExpectedError: nstructs.ErrPermissionDenied.Error(), }, { Name: "alloc-node-exec token", diff --git a/client/client_test.go b/client/client_test.go index 59d57dae1..4c7c56889 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -16,7 +16,6 @@ import ( "github.com/hashicorp/nomad/client/config" consulApi "github.com/hashicorp/nomad/client/consul" "github.com/hashicorp/nomad/client/fingerprint" - "github.com/hashicorp/nomad/client/state" "github.com/hashicorp/nomad/command/agent/consul" "github.com/hashicorp/nomad/helper/pluginutils/catalog" "github.com/hashicorp/nomad/helper/pluginutils/singleton" @@ -1600,7 +1599,7 @@ func TestClient_hasLocalState(t *testing.T) { c, cleanup := TestClient(t, nil) defer cleanup() - c.stateDB = state.NewMemDB(c.logger) + c.stateDB = cstate.NewMemDB(c.logger) t.Run("plain alloc", func(t *testing.T) { alloc := mock.BatchAlloc()