Skip to content

Commit

Permalink
fix(inventory): readjust inventory on startup for existing leases
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Mar 27, 2024
1 parent 7a06ee4 commit f54ad37
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
20 changes: 19 additions & 1 deletion cluster/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ func (is *inventoryService) run(ctx context.Context, reservationsArg []*reservat
}

var runch <-chan runner.Result
var currinv ctypes.Inventory

invupch := make(chan ctypes.Inventory, 1)

invch := is.clients.inventory.ResultChan()
var reserveChLocal <-chan inventoryRequest

Expand Down Expand Up @@ -543,6 +547,13 @@ loop:
"order", res.OrderID(),
"resource-group", res.Resources().GetName(),
"allocated", res.allocated)

if currinv != nil {
select {
case invupch <- currinv:
default:
}
}
}

break
Expand Down Expand Up @@ -606,12 +617,19 @@ loop:
res: resp,
err: err,
}
inventoryRequestsCounter.WithLabelValues("status", "success").Inc()
if err == nil {
inventoryRequestsCounter.WithLabelValues("status", "success").Inc()
} else {
inventoryRequestsCounter.WithLabelValues("status", "error").Inc()
}
case inv, open := <-invch:
if !open {
continue
}

invupch <- inv
case inv := <-invupch:
currinv = inv.Dup()
state.inventory = inv
updateIPs()

Expand Down
6 changes: 6 additions & 0 deletions cluster/kube/operators/clients/inventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func (inv *inventory) dup() inventory {
return dup
}

func (inv *inventory) Dup() ctypes.Inventory {
dup := inv.dup()

return &dup
}

// tryAdjust cluster inventory
// It returns two boolean values. First indicates if node-wide resources satisfy (true) requirements
// Seconds indicates if cluster-wide resources satisfy (true) requirements
Expand Down
7 changes: 6 additions & 1 deletion cluster/types/v1beta3/clients/inventory/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ func (inv *inventory) Snapshot() inventoryV1.Cluster {
Storage: make(inventoryV1.ClusterStorage, 0, len(inv.storage)),
}

for _, nd := range inv.nodes {
for i := range inv.nodes {
nd := inv.nodes[i]
res.Nodes = append(res.Nodes, inventoryV1.Node{
Name: nd.id,
Resources: inventoryV1.NodeResources{
Expand Down Expand Up @@ -406,3 +407,7 @@ func (inv *inventory) dup() *inventory {

return res
}

func (inv *inventory) Dup() ctypes.Inventory {
return inv.dup()
}
1 change: 1 addition & 0 deletions cluster/types/v1beta3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Inventory interface {
Adjust(ReservationGroup, ...InventoryOption) error
Metrics() inventoryV1.Metrics
Snapshot() inventoryV1.Cluster
Dup() Inventory
}

type EventsWatcher interface {
Expand Down

0 comments on commit f54ad37

Please sign in to comment.