Skip to content

Commit af35299

Browse files
committed
OCPBUGS-30882: GCP capg distribute instances across zones
** CAPG machines were only being created in a single zone. The instances should be spread across multiple zones based on the availability zones.
1 parent 0eafdbb commit af35299

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pkg/asset/machines/clusterapi.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,13 @@ func (c *ClusterAPI) Generate(dependencies asset.Parents) error {
305305
mpool := defaultGCPMachinePoolPlatform(pool.Architecture)
306306
mpool.Set(ic.Platform.GCP.DefaultMachinePlatform)
307307
mpool.Set(pool.Platform.GCP)
308+
if len(mpool.Zones) == 0 {
309+
azs, err := gcp.ZonesForInstanceType(ic.Platform.GCP.ProjectID, ic.Platform.GCP.Region, mpool.InstanceType)
310+
if err != nil {
311+
return errors.Wrap(err, "failed to fetch availability zones")
312+
}
313+
mpool.Zones = azs
314+
}
308315
pool.Platform.GCP = &mpool
309316

310317
gcpMachines, err := gcp.GenerateMachines(

pkg/asset/machines/gcp/gcpmachines.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ func GenerateMachines(installConfig *installconfig.InstallConfig, infraID string
4545
dataSecret := fmt.Sprintf("%s-%s", infraID, masterRole)
4646
capiMachine := createCAPIMachine(gcpMachine.Name, dataSecret, infraID)
4747

48+
if len(mpool.Zones) > 0 {
49+
// When there are fewer zones than the number of control plane instances,
50+
// cycle through the zones where the instances will reside.
51+
zone := mpool.Zones[int(idx)%len(mpool.Zones)]
52+
capiMachine.Spec.FailureDomain = ptr.To(zone)
53+
}
54+
4855
result = append(result, &asset.RuntimeFile{
4956
File: asset.File{Filename: fmt.Sprintf("10_machine_%s.yaml", capiMachine.Name)},
5057
Object: capiMachine,

0 commit comments

Comments
 (0)