Skip to content

Commit

Permalink
provisiond: sort the workloads from a reservation before sending it to
Browse files Browse the repository at this point in the history
provisiond engine

fixes #683
  • Loading branch information
zaibon committed Apr 6, 2020
1 parent 6f768f2 commit cf54c73
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/provision/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"sort"
"sync"
"time"

Expand Down Expand Up @@ -39,6 +40,17 @@ type reservationPoller struct {
wl client.Workloads
}

// provisionOrder is used to sort the workload type
// in the right order for provisiond
var provisionOrder = map[ReservationType]int{
DebugReservation: 0,
NetworkReservation: 1,
ZDBReservation: 2,
VolumeReservation: 3,
ContainerReservation: 4,
KubernetesReservation: 5,
}

func (r *reservationPoller) Poll(nodeID pkg.Identifier, from uint64) ([]*Reservation, error) {
list, err := r.wl.Workloads(nodeID.Identity(), from)
if err != nil {
Expand All @@ -55,6 +67,11 @@ func (r *reservationPoller) Poll(nodeID pkg.Identifier, from uint64) ([]*Reserva
result = append(result, r)
}

// sorts the workloads in the oder they need to be processed by provisiond
sort.Slice(result, func(i int, j int) bool {
return provisionOrder[result[i].Type] < provisionOrder[result[j].Type]
})

return result, nil
}

Expand Down

0 comments on commit cf54c73

Please sign in to comment.