Skip to content

Commit 4dce39a

Browse files
committed
wip_1
1 parent bee2400 commit 4dce39a

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

client/client.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,17 @@ func (c *Client) setupNode() error {
16281628
if _, ok := node.Meta[envoy.DefaultTransparentProxyOutboundPortParam]; !ok {
16291629
node.Meta[envoy.DefaultTransparentProxyOutboundPortParam] = envoy.DefaultTransparentProxyOutboundPort
16301630
}
1631-
1631+
// Set NodeMaxAllocs before dynamic configuration is set
1632+
if node.NodeAllocationTracker == nil {
1633+
if newConfig.NodeMaxAllocs >= 1 {
1634+
node.NodeAllocationTracker = &structs.NodeAllocationTracker{
1635+
HasMaxAlloc: true,
1636+
NodeAvailable: true,
1637+
NodeMaxAllocs: newConfig.NodeMaxAllocs,
1638+
NodeCurrentAllocs: 0,
1639+
}
1640+
}
1641+
}
16321642
// Since node.Meta will get dynamic metadata merged in, save static metadata
16331643
// here.
16341644
c.metaStatic = maps.Clone(node.Meta)

client/config/config.go

+4
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,10 @@ type Config struct {
375375

376376
// ExtraAllocHooks are run with other allocation hooks, mainly for testing.
377377
ExtraAllocHooks []interfaces.RunnerHook
378+
379+
// NodeMaxAllocs is an optional field that sets the maximum number of
380+
// allocations a node can be assigned. Defaults to 0 and ignored if unset.
381+
NodeMaxAllocs int
378382
}
379383

380384
type APIListenerRegistrar interface {

nomad/structs/structs.go

+17
Original file line numberDiff line numberDiff line change
@@ -2174,6 +2174,11 @@ type Node struct {
21742174
// Raft Indexes
21752175
CreateIndex uint64
21762176
ModifyIndex uint64
2177+
2178+
// NodeAllocationTracker holds NodeMaxAllocs value, if configured,
2179+
// and CurrentNodeAllocations to help the scheduler to block excess
2180+
// allocations.
2181+
NodeAllocationTracker *NodeAllocationTracker
21772182
}
21782183

21792184
// GetID is a helper for getting the ID when the object may be nil and is
@@ -2394,6 +2399,18 @@ type NodeStubFields struct {
23942399
OS bool
23952400
}
23962401

2402+
// NodeAllocationTracker retains awareness of a client's NodeMaxAllocs
2403+
// value, the current number of Allocations and whether the node can
2404+
// accept new Allocations
2405+
type NodeAllocationTracker struct {
2406+
HasMaxAlloc bool
2407+
NodeAvailable bool
2408+
// TODO: review node concurrency, think allocations are either locked by
2409+
// default or "single threaded" by virtue of single scheduler.
2410+
NodeCurrentAllocs int // NOTE: Keeping track of this here might be too ambitious and unneeded
2411+
NodeMaxAllocs int
2412+
}
2413+
23972414
// Resources is used to define the resources available
23982415
// on a client
23992416
type Resources struct {

scheduler/generic_sched.go

+4
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ func (s *GenericScheduler) computeJobAllocs() error {
381381
// nodes to lost, but only if the scheduler has already marked them
382382
updateNonTerminalAllocsToLost(s.plan, tainted, allocs)
383383

384+
////TODO refactor into helper func
385+
//for _, alloc := range allocs {
386+
387+
//}
384388
reconciler := NewAllocReconciler(s.logger,
385389
genericAllocUpdateFn(s.ctx, s.stack, s.eval.ID),
386390
s.batch, s.eval.JobID, s.job, s.deployment, allocs, tainted, s.eval.ID,

0 commit comments

Comments
 (0)