Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions client/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/hashicorp/nomad/acl"
"github.com/hashicorp/nomad/ci"
"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/helper/pointer"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
Expand Down Expand Up @@ -261,7 +260,7 @@ func TestClient_ACL_ResolveToken_Expired(t *testing.T) {

// Create and upsert a token which has just expired.
mockExpiredToken := mock.ACLToken()
mockExpiredToken.ExpirationTime = pointer.Of(time.Now().Add(-5 * time.Minute))
mockExpiredToken.ExpirationTime = new(time.Now().Add(-5 * time.Minute))

err := s1.State().UpsertACLTokens(structs.MsgTypeTestSetup, 120, []*structs.ACLToken{mockExpiredToken})
must.NoError(t, err)
Expand Down
23 changes: 11 additions & 12 deletions client/agent_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/hashicorp/nomad/command/agent/host"
"github.com/hashicorp/nomad/command/agent/monitor"
"github.com/hashicorp/nomad/command/agent/pprof"
"github.com/hashicorp/nomad/helper/pointer"
"github.com/hashicorp/nomad/nomad/structs"
)

Expand Down Expand Up @@ -88,16 +87,16 @@ func (a *Agent) monitor(conn io.ReadWriteCloser) {
encoder := codec.NewEncoder(conn, structs.MsgpackHandle)

if err := decoder.Decode(&args); err != nil {
handleStreamResultError(err, pointer.Of(int64(500)), encoder)
handleStreamResultError(err, new(int64(500)), encoder)
return
}

// Check acl
if aclObj, err := a.c.ResolveToken(args.AuthToken); err != nil {
handleStreamResultError(err, pointer.Of(int64(403)), encoder)
handleStreamResultError(err, new(int64(403)), encoder)
return
} else if !aclObj.AllowAgentRead() {
handleStreamResultError(structs.ErrPermissionDenied, pointer.Of(int64(403)), encoder)
handleStreamResultError(structs.ErrPermissionDenied, new(int64(403)), encoder)
return
}

Expand All @@ -107,7 +106,7 @@ func (a *Agent) monitor(conn io.ReadWriteCloser) {
}

if logLevel == log.NoLevel {
handleStreamResultError(errors.New("Unknown log level"), pointer.Of(int64(400)), encoder)
handleStreamResultError(errors.New("Unknown log level"), new(int64(400)), encoder)
return
}

Expand Down Expand Up @@ -168,7 +167,7 @@ func (a *Agent) monitor(conn io.ReadWriteCloser) {
streamErr := streamEncoder.EncodeStream(frames, errCh, ctx, framer, false)

if streamErr != nil {
handleStreamResultError(streamErr, pointer.Of(int64(500)), encoder)
handleStreamResultError(streamErr, new(int64(500)), encoder)
return
}
}
Expand Down Expand Up @@ -203,22 +202,22 @@ func (a *Agent) monitorExport(conn io.ReadWriteCloser) {
encoder := codec.NewEncoder(conn, structs.MsgpackHandle)

if err := decoder.Decode(&args); err != nil {
handleStreamResultError(err, pointer.Of(int64(500)), encoder)
handleStreamResultError(err, new(int64(500)), encoder)
return
}

// Check acl
if aclObj, err := a.c.ResolveToken(args.AuthToken); err != nil {
handleStreamResultError(err, pointer.Of(int64(403)), encoder)
handleStreamResultError(err, new(int64(403)), encoder)
return
} else if !aclObj.AllowAgentRead() {
handleStreamResultError(structs.ErrPermissionDenied, pointer.Of(int64(403)), encoder)
handleStreamResultError(structs.ErrPermissionDenied, new(int64(403)), encoder)
return
}

nomadLogPath := a.c.GetConfig().LogFile
if args.OnDisk && nomadLogPath == "" {
handleStreamResultError(errors.New("No nomad log file defined"), pointer.Of(int64(400)), encoder)
handleStreamResultError(errors.New("No nomad log file defined"), new(int64(400)), encoder)
}

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -255,7 +254,7 @@ func (a *Agent) monitorExport(conn io.ReadWriteCloser) {

m, err := monitor.NewExportMonitor(opts)
if err != nil {
handleStreamResultError(err, pointer.Of(int64(500)), encoder)
handleStreamResultError(err, new(int64(500)), encoder)
return
}
var eofCancelCh chan error
Expand All @@ -279,7 +278,7 @@ func (a *Agent) monitorExport(conn io.ReadWriteCloser) {
streamErr := streamEncoder.EncodeStream(frames, errCh, ctx, framer, true)

if streamErr != nil {
handleStreamResultError(streamErr, pointer.Of(int64(500)), encoder)
handleStreamResultError(streamErr, new(int64(500)), encoder)
return
}
}
37 changes: 18 additions & 19 deletions client/alloc_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/hashicorp/go-msgpack/v2/codec"
"github.com/hashicorp/nomad/acl"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/helper/pointer"
"github.com/hashicorp/nomad/helper/uuid"
nstructs "github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/plugins/drivers"
Expand Down Expand Up @@ -233,21 +232,21 @@ func (a *Allocations) execImpl(encoder *codec.Encoder, decoder *codec.Decoder, e
// Decode the arguments
var req cstructs.AllocExecRequest
if err := decoder.Decode(&req); err != nil {
return pointer.Of(int64(500)), err
return new(int64(500)), err
}

if a.c.GetConfig().DisableRemoteExec {
return nil, nstructs.ErrPermissionDenied
}

if req.AllocID == "" {
return pointer.Of(int64(400)), allocIDNotPresentErr
return new(int64(400)), allocIDNotPresentErr
}
ar, err := a.c.getAllocRunner(req.AllocID)
if err != nil {
code := pointer.Of(int64(500))
code := new(int64(500))
if nstructs.IsErrUnknownAllocation(err) {
code = pointer.Of(int64(404))
code = new(int64(404))
}

return code, err
Expand Down Expand Up @@ -286,31 +285,31 @@ func (a *Allocations) execImpl(encoder *codec.Encoder, decoder *codec.Decoder, e

// Check alloc-exec permission.
if err != nil {
return pointer.Of(int64(400)), err
return new(int64(400)), err
} else if !aclObj.AllowNsOp(alloc.Namespace, acl.NamespaceCapabilityAllocExec) {
return nil, nstructs.ErrPermissionDenied
}

// Validate the arguments
if req.Task == "" {
return pointer.Of(int64(400)), taskNotPresentErr
return new(int64(400)), taskNotPresentErr
}

if req.JobID != "" && req.JobID != alloc.JobID {
return pointer.Of(int64(http.StatusBadRequest)),
return new(int64(http.StatusBadRequest)),
fmt.Errorf("job %s does not have allocation %s", req.JobID, req.AllocID)
}

// If an action is present, go find the command and args
if req.Action != "" {
task := alloc.LookupTask(req.Task)
if task == nil {
return pointer.Of(int64(http.StatusBadRequest)),
return new(int64(http.StatusBadRequest)),
fmt.Errorf("task %s not found in allocation %s", req.Task, alloc.ID)
}
jobAction := task.GetAction(req.Action)
if jobAction == nil {
return pointer.Of(int64(http.StatusBadRequest)),
return new(int64(http.StatusBadRequest)),
fmt.Errorf("action %s not found in task %s", req.Action, req.Task)
}

Expand All @@ -319,14 +318,14 @@ func (a *Allocations) execImpl(encoder *codec.Encoder, decoder *codec.Decoder, e
}

if len(req.Cmd) == 0 {
return pointer.Of(int64(400)), errors.New("command is not present")
return new(int64(400)), errors.New("command is not present")
}

capabilities, err := ar.GetTaskDriverCapabilities(req.Task)
if err != nil {
code := pointer.Of(int64(500))
code := new(int64(500))
if nstructs.IsErrUnknownAllocation(err) {
code = pointer.Of(int64(404))
code = new(int64(404))
}

return code, err
Expand All @@ -342,9 +341,9 @@ func (a *Allocations) execImpl(encoder *codec.Encoder, decoder *codec.Decoder, e

allocState, err := a.c.GetAllocState(req.AllocID)
if err != nil {
code := pointer.Of(int64(500))
code := new(int64(500))
if nstructs.IsErrUnknownAllocation(err) {
code = pointer.Of(int64(404))
code = new(int64(404))
}

return code, err
Expand All @@ -353,24 +352,24 @@ func (a *Allocations) execImpl(encoder *codec.Encoder, decoder *codec.Decoder, e
// Check that the task is there
taskState := allocState.TaskStates[req.Task]
if taskState == nil {
return pointer.Of(int64(400)), fmt.Errorf("unknown task name %q", req.Task)
return new(int64(400)), fmt.Errorf("unknown task name %q", req.Task)
}

if taskState.StartedAt.IsZero() {
return pointer.Of(int64(404)), fmt.Errorf("task %q not started yet.", req.Task)
return new(int64(404)), fmt.Errorf("task %q not started yet.", req.Task)
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

h := ar.GetTaskExecHandler(req.Task)
if h == nil {
return pointer.Of(int64(404)), fmt.Errorf("task %q is not running.", req.Task)
return new(int64(404)), fmt.Errorf("task %q is not running.", req.Task)
}

err = h(ctx, req.Cmd, req.Tty, newExecStream(decoder, encoder))
if err != nil {
code := pointer.Of(int64(500))
code := new(int64(500))
return code, err
}

Expand Down
3 changes: 1 addition & 2 deletions client/allocrunner/alloc_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/hashicorp/nomad/client/taskenv"
"github.com/hashicorp/nomad/client/vaultclient"
"github.com/hashicorp/nomad/client/widmgr"
"github.com/hashicorp/nomad/helper/pointer"
"github.com/hashicorp/nomad/helper/users/dynamic"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/plugins/device"
Expand Down Expand Up @@ -863,7 +862,7 @@ func (ar *allocRunner) clientAlloc(taskStates map[string]*structs.TaskState) *st
if a.ClientStatus == structs.AllocClientStatusFailed &&
alloc.DeploymentID != "" && !a.DeploymentStatus.HasHealth() {
a.DeploymentStatus = &structs.AllocDeploymentStatus{
Healthy: pointer.Of(false),
Healthy: new(false),
}
}

Expand Down
9 changes: 4 additions & 5 deletions client/allocrunner/csi_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/hashicorp/nomad/client/allocrunner/state"
"github.com/hashicorp/nomad/client/pluginmanager/csimanager"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/helper/pointer"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
Expand Down Expand Up @@ -317,8 +316,8 @@ func TestCSIHook(t *testing.T) {
alloc: alloc,
ns: tc.rpcNS,
callCounts: callCounts,
hasExistingClaim: pointer.Of(tc.startsWithClaims),
schedulable: pointer.Of(!tc.startsUnschedulable),
hasExistingClaim: new(tc.startsWithClaims),
schedulable: new(!tc.startsUnschedulable),
}
ar := mockAllocRunner{
res: &cstructs.AllocHookResources{},
Expand Down Expand Up @@ -460,8 +459,8 @@ func TestCSIHook_Prerun_Validation(t *testing.T) {
rpcer := mockRPCer{
alloc: alloc,
callCounts: testutil.NewCallCounter(),
hasExistingClaim: pointer.Of(false),
schedulable: pointer.Of(true),
hasExistingClaim: new(false),
schedulable: new(true),
}

ar := mockAllocRunner{
Expand Down
5 changes: 2 additions & 3 deletions client/allocrunner/group_service_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/client/taskenv"
agentconsul "github.com/hashicorp/nomad/command/agent/consul"
"github.com/hashicorp/nomad/helper/pointer"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
Expand Down Expand Up @@ -73,7 +72,7 @@ func TestGroupServiceHook_ShutdownDelayUpdate(t *testing.T) {
ci.Parallel(t)

alloc := mock.Alloc()
alloc.Job.TaskGroups[0].ShutdownDelay = pointer.Of(10 * time.Second)
alloc.Job.TaskGroups[0].ShutdownDelay = new(10 * time.Second)

logger := testlog.HCLogger(t)
consulMockClient := regMock.NewServiceRegistrationHandler(logger)
Expand All @@ -95,7 +94,7 @@ func TestGroupServiceHook_ShutdownDelayUpdate(t *testing.T) {
must.NoError(t, h.Prerun(env))

// Incease shutdown Delay
alloc.Job.TaskGroups[0].ShutdownDelay = pointer.Of(15 * time.Second)
alloc.Job.TaskGroups[0].ShutdownDelay = new(15 * time.Second)
req := &interfaces.RunnerUpdateRequest{Alloc: alloc, AllocEnv: env}
must.NoError(t, h.Update(req))

Expand Down
13 changes: 6 additions & 7 deletions client/allocrunner/taskrunner/connect_native_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/hashicorp/nomad/client/taskenv"
"github.com/hashicorp/nomad/client/testutil"
agentconsul "github.com/hashicorp/nomad/command/agent/consul"
"github.com/hashicorp/nomad/helper/pointer"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/mock"
Expand Down Expand Up @@ -475,8 +474,8 @@ func TestTaskRunner_ConnectNativeHook_shareTLS(t *testing.T) {

// TLS config consumed by native application
ShareSSL: shareSSL,
EnableSSL: pointer.Of(true),
VerifySSL: pointer.Of(true),
EnableSSL: new(true),
VerifySSL: new(true),
CAFile: fakeCert,
CertFile: fakeCert,
KeyFile: fakeCert,
Expand Down Expand Up @@ -522,7 +521,7 @@ func TestTaskRunner_ConnectNativeHook_shareTLS(t *testing.T) {
// so make sure an unset value turns the feature on.

t.Run("share_ssl is true", func(t *testing.T) {
try(t, pointer.Of(true))
try(t, new(true))
})

t.Run("share_ssl is nil", func(t *testing.T) {
Expand Down Expand Up @@ -590,9 +589,9 @@ func TestTaskRunner_ConnectNativeHook_shareTLS_override(t *testing.T) {
Addr: consulConfig.Address,

// TLS config consumed by native application
ShareSSL: pointer.Of(true),
EnableSSL: pointer.Of(true),
VerifySSL: pointer.Of(true),
ShareSSL: new(true),
EnableSSL: new(true),
VerifySSL: new(true),
CAFile: fakeCert,
CertFile: fakeCert,
KeyFile: fakeCert,
Expand Down
5 changes: 2 additions & 3 deletions client/allocrunner/taskrunner/envoy_bootstrap_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/hashicorp/nomad/client/testutil"
agentconsul "github.com/hashicorp/nomad/command/agent/consul"
"github.com/hashicorp/nomad/helper/args"
"github.com/hashicorp/nomad/helper/pointer"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/mock"
Expand Down Expand Up @@ -104,8 +103,8 @@ func TestEnvoyBootstrapHook_decodeTriState(t *testing.T) {
ci.Parallel(t)

require.Equal(t, "", decodeTriState(nil))
require.Equal(t, "true", decodeTriState(pointer.Of(true)))
require.Equal(t, "false", decodeTriState(pointer.Of(false)))
require.Equal(t, "true", decodeTriState(new(true)))
require.Equal(t, "false", decodeTriState(new(false)))
}

var (
Expand Down
5 changes: 2 additions & 3 deletions client/allocrunner/taskrunner/getter/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"testing"

cconfig "github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/helper/pointer"
"github.com/hashicorp/nomad/helper/testlog"
sconfig "github.com/hashicorp/nomad/nomad/structs/config"
"github.com/shoenig/test/must"
Expand All @@ -19,8 +18,8 @@ import (
// artifact config. It is good enough for tests so no mock implementation exists.
func TestSandbox(t *testing.T) *Sandbox {
defaultConfig := sconfig.DefaultArtifactConfig()
defaultConfig.DecompressionSizeLimit = pointer.Of("1MB")
defaultConfig.DecompressionFileCountLimit = pointer.Of(10)
defaultConfig.DecompressionSizeLimit = new("1MB")
defaultConfig.DecompressionFileCountLimit = new(10)
ac, err := cconfig.ArtifactConfigFromAgent(defaultConfig)
must.NoError(t, err)
return New(ac, testlog.HCLogger(t))
Expand Down
Loading
Loading