Skip to content

Commit 1bd1751

Browse files
committed
use same NodeMaxAllocs struct for client and node config
1 parent 68f0eb7 commit 1bd1751

File tree

6 files changed

+15
-19
lines changed

6 files changed

+15
-19
lines changed

client/client.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,12 +1629,8 @@ func (c *Client) setupNode() error {
16291629
node.Meta[envoy.DefaultTransparentProxyOutboundPortParam] = envoy.DefaultTransparentProxyOutboundPort
16301630
}
16311631
// Set NodeMaxAllocs before dynamic configuration is set
1632-
if node.NodeAllocationTracker == nil {
1633-
if newConfig.NodeMaxAllocs >= 1 {
1634-
node.NodeAllocationTracker = &structs.NodeAllocationTracker{
1635-
NodeMaxAllocs: newConfig.NodeMaxAllocs,
1636-
}
1637-
}
1632+
if node.NodeMaxAllocs == nil && newConfig.NodeMaxAllocs != nil {
1633+
node.NodeMaxAllocs = newConfig.NodeMaxAllocs
16381634
}
16391635
// Since node.Meta will get dynamic metadata merged in, save static metadata
16401636
// here.

client/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ type Config struct {
378378

379379
// NodeMaxAllocs is an optional field that sets the maximum number of
380380
// allocations a node can be assigned. Defaults to 0 and ignored if unset.
381-
NodeMaxAllocs int
381+
NodeMaxAllocs *structs.NodeMaxAllocs
382382
}
383383

384384
type APIListenerRegistrar interface {

nomad/structs/funcs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ func (a TerminalByNodeByName) Get(nodeID, name string) (*Allocation, bool) {
141141
func AllocsFit(node *Node, allocs []*Allocation, netIdx *NetworkIndex, checkDevices bool) (bool, string, *ComparableResources, error) {
142142
// Compute the allocs' utilization from zero
143143
used := new(ComparableResources)
144-
if node.NodeAllocationTracker != nil {
145-
if node.NodeAllocationTracker.NodeMaxAllocs < len(allocs) {
144+
if node.NodeMaxAllocs != nil {
145+
if node.NodeMaxAllocs.MaxAllocs < len(allocs) {
146146
return false, "max allocation exceeded", used, fmt.Errorf("plan exceeds max allocation")
147147
}
148148
}

nomad/structs/funcs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ func TestAllocsFit_MaxNodeAllocs(t *testing.T) {
774774
for _, tc := range testCases {
775775
t.Run(tc.name, func(t *testing.T) {
776776
n := node2k()
777-
n.NodeAllocationTracker = &NodeAllocationTracker{false, tc.maxAllocs}
777+
n.NodeMaxAllocs = &NodeMaxAllocs{tc.maxAllocs}
778778
fit, dim, used, err := AllocsFit(n, tc.allocations, nil, false)
779779
if !tc.expectErr {
780780
must.NoError(t, err)

nomad/structs/structs.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,10 +2175,10 @@ type Node struct {
21752175
CreateIndex uint64
21762176
ModifyIndex uint64
21772177

2178-
// NodeAllocationTracker holds NodeMaxAllocs value, if configured,
2178+
// NodeMaxAllocs holds NodeMaxAllocs value, if configured,
21792179
// and CurrentNodeAllocations to help the scheduler to block excess
21802180
// allocations.
2181-
NodeAllocationTracker *NodeAllocationTracker
2181+
NodeMaxAllocs *NodeMaxAllocs
21822182
}
21832183

21842184
// GetID is a helper for getting the ID when the object may be nil and is
@@ -2399,10 +2399,10 @@ type NodeStubFields struct {
23992399
OS bool
24002400
}
24012401

2402-
// NodeAllocationTracker holds the NodeMaxAlloc value
2402+
// NodeMaxAllocs holds the NodeMaxAlloc value
24032403
// if set in *client.Config.
2404-
type NodeAllocationTracker struct {
2405-
NodeMaxAllocs int
2404+
type NodeMaxAllocs struct {
2405+
MaxAllocs int
24062406
}
24072407

24082408
// Resources is used to define the resources available

scheduler/rank_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,14 +2160,14 @@ func TestBinPackIterator_MaxAlloc(t *testing.T) {
21602160
if tc.noNodes {
21612161
// Note: test case order matters here
21622162
for _, v := range nodes {
2163-
v.Node.NodeAllocationTracker = &structs.NodeAllocationTracker{
2164-
NodeMaxAllocs: tc.maxAlloc,
2163+
v.Node.NodeMaxAllocs = &structs.NodeMaxAllocs{
2164+
MaxAllocs: tc.maxAlloc,
21652165
}
21662166
}
21672167
} else {
21682168
// only add allocation limit to first node if !noNodes
2169-
nodes[0].Node.NodeAllocationTracker = &structs.NodeAllocationTracker{
2170-
NodeMaxAllocs: tc.maxAlloc,
2169+
nodes[0].Node.NodeMaxAllocs = &structs.NodeMaxAllocs{
2170+
MaxAllocs: tc.maxAlloc,
21712171
}
21722172
}
21732173
static := NewStaticRankIterator(ctx, nodes)

0 commit comments

Comments
 (0)