diff --git a/api/allocations.go b/api/allocations.go index be4058977..0c1a01b1a 100644 --- a/api/allocations.go +++ b/api/allocations.go @@ -511,7 +511,8 @@ type AllocatedCpuResources struct { } type AllocatedMemoryResources struct { - MemoryMB int64 + MemoryMB int64 + MemoryMaxMB int64 } type AllocatedDeviceResource struct { diff --git a/api/resources.go b/api/resources.go index ae420b22f..d9bd49476 100644 --- a/api/resources.go +++ b/api/resources.go @@ -7,12 +7,13 @@ import ( // Resources encapsulates the required resources of // a given task or task group. type Resources struct { - CPU *int `hcl:"cpu,optional"` - Cores *int `hcl:"cores,optional"` - MemoryMB *int `mapstructure:"memory" hcl:"memory,optional"` - DiskMB *int `mapstructure:"disk" hcl:"disk,optional"` - Networks []*NetworkResource `hcl:"network,block"` - Devices []*RequestedDevice `hcl:"device,block"` + CPU *int `hcl:"cpu,optional"` + Cores *int `hcl:"cores,optional"` + MemoryMB *int `mapstructure:"memory" hcl:"memory,optional"` + MemoryMaxMB *int `mapstructure:"memory_max" hcl:"memory_max,optional"` + DiskMB *int `mapstructure:"disk" hcl:"disk,optional"` + Networks []*NetworkResource `hcl:"network,block"` + Devices []*RequestedDevice `hcl:"device,block"` // COMPAT(0.10) // XXX Deprecated. Please do not use. The field will be removed in Nomad diff --git a/command/agent/job_endpoint.go b/command/agent/job_endpoint.go index 79e44bba9..3b358c447 100644 --- a/command/agent/job_endpoint.go +++ b/command/agent/job_endpoint.go @@ -1193,6 +1193,10 @@ func ApiResourcesToStructs(in *api.Resources) *structs.Resources { out.Cores = *in.Cores } + if in.MemoryMaxMB != nil { + out.MemoryMaxMB = *in.MemoryMaxMB + } + // COMPAT(0.10): Only being used to issue warnings if in.IOPS != nil { out.IOPS = *in.IOPS diff --git a/command/agent/job_endpoint_test.go b/command/agent/job_endpoint_test.go index 9a4870e81..099eb2a60 100644 --- a/command/agent/job_endpoint_test.go +++ b/command/agent/job_endpoint_test.go @@ -2930,6 +2930,53 @@ func TestConversion_apiLogConfigToStructs(t *testing.T) { })) } +func TestConversion_apiResourcesToStructs(t *testing.T) { + t.Parallel() + + cases := []struct { + name string + input *api.Resources + expected *structs.Resources + }{ + { + "nil", + nil, + nil, + }, + { + "plain", + &api.Resources{ + CPU: helper.IntToPtr(100), + MemoryMB: helper.IntToPtr(200), + }, + &structs.Resources{ + CPU: 100, + MemoryMB: 200, + }, + }, + { + "with memory max", + &api.Resources{ + CPU: helper.IntToPtr(100), + MemoryMB: helper.IntToPtr(200), + MemoryMaxMB: helper.IntToPtr(300), + }, + &structs.Resources{ + CPU: 100, + MemoryMB: 200, + MemoryMaxMB: 300, + }, + }, + } + + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + found := ApiResourcesToStructs(c.input) + require.Equal(t, c.expected, found) + }) + } +} + func TestConversion_apiConnectSidecarTaskToStructs(t *testing.T) { t.Parallel() require.Nil(t, apiConnectSidecarTaskToStructs(nil)) diff --git a/command/alloc_status.go b/command/alloc_status.go index aabcaaf43..4e21d18ad 100644 --- a/command/alloc_status.go +++ b/command/alloc_status.go @@ -563,13 +563,21 @@ func (c *AllocStatusCommand) outputTaskResources(alloc *api.Allocation, task str var resourcesOutput []string resourcesOutput = append(resourcesOutput, "CPU|Memory|Disk|Addresses") firstAddr := "" + secondAddr := "" if len(addr) > 0 { firstAddr = addr[0] } + if len(addr) > 1 { + secondAddr = addr[1] + } // Display the rolled up stats. If possible prefer the live statistics cpuUsage := strconv.Itoa(*resource.CPU) memUsage := humanize.IBytes(uint64(*resource.MemoryMB * bytesPerMegabyte)) + memMax := "" + if max := resource.MemoryMaxMB; max != nil && *max != 0 && *max != *resource.MemoryMB { + memMax = "Max: " + humanize.IBytes(uint64(*resource.MemoryMaxMB*bytesPerMegabyte)) + } var deviceStats []*api.DeviceGroupStats if stats != nil { @@ -588,7 +596,10 @@ func (c *AllocStatusCommand) outputTaskResources(alloc *api.Allocation, task str memUsage, humanize.IBytes(uint64(*alloc.Resources.DiskMB*bytesPerMegabyte)), firstAddr)) - for i := 1; i < len(addr); i++ { + if memMax != "" || secondAddr != "" { + resourcesOutput = append(resourcesOutput, fmt.Sprintf("|%v||%v", memMax, secondAddr)) + } + for i := 2; i < len(addr); i++ { resourcesOutput = append(resourcesOutput, fmt.Sprintf("|||%v", addr[i])) } c.Ui.Output(formatListWithSpaces(resourcesOutput)) diff --git a/vendor/github.com/hashicorp/nomad/api/allocations.go b/vendor/github.com/hashicorp/nomad/api/allocations.go index be4058977..0c1a01b1a 100644 --- a/vendor/github.com/hashicorp/nomad/api/allocations.go +++ b/vendor/github.com/hashicorp/nomad/api/allocations.go @@ -511,7 +511,8 @@ type AllocatedCpuResources struct { } type AllocatedMemoryResources struct { - MemoryMB int64 + MemoryMB int64 + MemoryMaxMB int64 } type AllocatedDeviceResource struct { diff --git a/vendor/github.com/hashicorp/nomad/api/resources.go b/vendor/github.com/hashicorp/nomad/api/resources.go index ae420b22f..d9bd49476 100644 --- a/vendor/github.com/hashicorp/nomad/api/resources.go +++ b/vendor/github.com/hashicorp/nomad/api/resources.go @@ -7,12 +7,13 @@ import ( // Resources encapsulates the required resources of // a given task or task group. type Resources struct { - CPU *int `hcl:"cpu,optional"` - Cores *int `hcl:"cores,optional"` - MemoryMB *int `mapstructure:"memory" hcl:"memory,optional"` - DiskMB *int `mapstructure:"disk" hcl:"disk,optional"` - Networks []*NetworkResource `hcl:"network,block"` - Devices []*RequestedDevice `hcl:"device,block"` + CPU *int `hcl:"cpu,optional"` + Cores *int `hcl:"cores,optional"` + MemoryMB *int `mapstructure:"memory" hcl:"memory,optional"` + MemoryMaxMB *int `mapstructure:"memory_max" hcl:"memory_max,optional"` + DiskMB *int `mapstructure:"disk" hcl:"disk,optional"` + Networks []*NetworkResource `hcl:"network,block"` + Devices []*RequestedDevice `hcl:"device,block"` // COMPAT(0.10) // XXX Deprecated. Please do not use. The field will be removed in Nomad