Skip to content

Commit 7f17512

Browse files
committed
OCPBUGS-54979: sort zone slices extracted from map of byo subnets
Previously, since zones are extracted from map keys, order is not guaranteed. This can lead to an issue where master CAPI machine manifest is configured with a different subnet ID than MAPI machine manifest as they are handled separately. This commit ensures the zones are sorted by lexical order before processing CAPI/MAP machine manifests so that zones are distributed in the same order.
1 parent 0b51991 commit 7f17512

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pkg/asset/machines/clusterapi.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"net"
77
"path/filepath"
8+
"slices"
89
"strings"
910
"time"
1011

@@ -125,6 +126,10 @@ func (c *ClusterAPI) Generate(ctx context.Context, dependencies asset.Parents) e
125126
for zone := range subnets {
126127
mpool.Zones = append(mpool.Zones, zone)
127128
}
129+
// Since zones are extracted from map keys, order is not guaranteed.
130+
// Thus, sort the zones by lexical order to ensure CAPI and MAPI machines
131+
// are distributed to zones in the same order.
132+
slices.Sort(mpool.Zones)
128133
} else {
129134
mpool.Zones, err = installConfig.AWS.AvailabilityZones(ctx)
130135
if err != nil {

pkg/asset/machines/master.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"slices"
89
"strings"
910

1011
baremetalhost "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1"
@@ -196,6 +197,10 @@ func (m *Master) Generate(ctx context.Context, dependencies asset.Parents) error
196197
for zone := range subnets {
197198
mpool.Zones = append(mpool.Zones, zone)
198199
}
200+
// Since zones are extracted from map keys, order is not guaranteed.
201+
// Thus, sort the zones by lexical order to ensure CAPI and MAPI machines
202+
// are distributed to zones in the same order.
203+
slices.Sort(mpool.Zones)
199204
} else {
200205
mpool.Zones, err = installConfig.AWS.AvailabilityZones(ctx)
201206
if err != nil {

0 commit comments

Comments
 (0)