client: fix multiple imports (#10537)

This commit is contained in:
Lars Lehtonen
2021-05-13 11:30:31 -07:00
committed by GitHub
parent 02e585a611
commit cded17cbaf
3 changed files with 14 additions and 16 deletions

View File

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

View File

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

View File

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