From 8f1b28da34e5091d5383448ac163de148d1b96d4 Mon Sep 17 00:00:00 2001 From: Archana Shinde Date: Wed, 10 Oct 2018 17:28:21 -0700 Subject: [PATCH] network: Sort endpoints by name Sort endpoints by name to control the order in which they are passed to the VM as the interface name inside the VM depends on the order in which it is passed. Long term we should come up with a more robust approach. Fixes #785 Signed-off-by: Archana Shinde --- virtcontainers/network.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/virtcontainers/network.go b/virtcontainers/network.go index ab4389e488..d892b34d21 100644 --- a/virtcontainers/network.go +++ b/virtcontainers/network.go @@ -16,6 +16,7 @@ import ( "os" "path/filepath" "runtime" + "sort" "strings" "time" @@ -1670,6 +1671,12 @@ func createEndpointsFromScan(networkNSPath string, config NetworkConfig) ([]Endp idx++ } + sort.Slice(endpoints, func(i, j int) bool { + return endpoints[i].Name() < endpoints[j].Name() + }) + + networkLogger().WithField("endpoints", endpoints).Info("Endpoints found after scan") + return endpoints, nil }