From 734b7c4d839263e73fcc99d8ddb490aba824b0e2 Mon Sep 17 00:00:00 2001 From: justinsb Date: Fri, 5 Apr 2024 19:12:01 -0400 Subject: [PATCH] openstack: try to consistently return addresses from the first network This avoids a test flake, and makes production more predictable also. --- etcd-manager/pkg/volumes/openstack/util.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/etcd-manager/pkg/volumes/openstack/util.go b/etcd-manager/pkg/volumes/openstack/util.go index c79171a9a..be0d49b86 100644 --- a/etcd-manager/pkg/volumes/openstack/util.go +++ b/etcd-manager/pkg/volumes/openstack/util.go @@ -19,6 +19,7 @@ package openstack import ( "fmt" "net" + "sort" ) const ( @@ -28,7 +29,15 @@ const ( ) func GetServerFixedIP(addrs map[string]interface{}, name string, networkCIDR *net.IPNet) (poolAddress string, err error) { - for _, address := range addrs { + // Introduce some determinism, even though map ordering is random + var addressKeys []string + for addressKey := range addrs { + addressKeys = append(addressKeys, addressKey) + } + sort.Strings(addressKeys) + + for _, addressKey := range addressKeys { + address := addrs[addressKey] if addresses, ok := address.([]interface{}); ok { for _, addr := range addresses { addrMap := addr.(map[string]interface{})