Skip to content

Commit d7bdcdf

Browse files
Merge pull request openshift#8176 from barbacbd/OCPBUGS-30882
OCPBUGS-30882: GCP capg distribute instances across zones
2 parents fb92a96 + af35299 commit d7bdcdf

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
@@ -304,6 +304,13 @@ func (c *ClusterAPI) Generate(dependencies asset.Parents) error {
304304
mpool := defaultGCPMachinePoolPlatform(pool.Architecture)
305305
mpool.Set(ic.Platform.GCP.DefaultMachinePlatform)
306306
mpool.Set(pool.Platform.GCP)
307+
if len(mpool.Zones) == 0 {
308+
azs, err := gcp.ZonesForInstanceType(ic.Platform.GCP.ProjectID, ic.Platform.GCP.Region, mpool.InstanceType)
309+
if err != nil {
310+
return errors.Wrap(err, "failed to fetch availability zones")
311+
}
312+
mpool.Zones = azs
313+
}
307314
pool.Platform.GCP = &mpool
308315

309316
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)