From cf54c73dac232299aca39524f3b28fbca23100e0 Mon Sep 17 00:00:00 2001 From: Christophe de Carvalho Date: Mon, 6 Apr 2020 09:50:07 +0200 Subject: [PATCH] provisiond: sort the workloads from a reservation before sending it to provisiond engine fixes #683 --- pkg/provision/source.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/provision/source.go b/pkg/provision/source.go index c5c5c4d5b..1c9e005f5 100644 --- a/pkg/provision/source.go +++ b/pkg/provision/source.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "sort" "sync" "time" @@ -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 { @@ -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 }