Skip to content

Commit

Permalink
Merge pull request #1100 from kahun/fix/gke_node_pools_per_region
Browse files Browse the repository at this point in the history
Fix GKE MachinePool replicas per region
  • Loading branch information
k8s-ci-robot authored Dec 15, 2023
2 parents cadb9b9 + 29b28ef commit 818b985
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion cloud/scope/managedmachinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ func NodePoolResourceLabels(additionalLabels infrav1.Labels, clusterName string)
func ConvertToSdkNodePool(nodePool infrav1exp.GCPManagedMachinePool, machinePool clusterv1exp.MachinePool, regional bool, clusterName string) *containerpb.NodePool {
replicas := *machinePool.Spec.Replicas
if regional {
replicas /= cloud.DefaultNumRegionsPerZone
if len(nodePool.Spec.NodeLocations) != 0 {
replicas /= int32(len(nodePool.Spec.NodeLocations))
} else {
replicas /= cloud.DefaultNumRegionsPerZone
}
}
nodePoolName := nodePool.Spec.NodePoolName
if len(nodePoolName) == 0 {
Expand Down
3 changes: 1 addition & 2 deletions cloud/services/container/nodepools/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"strings"

"sigs.k8s.io/cluster-api-provider-gcp/cloud"
"sigs.k8s.io/cluster-api-provider-gcp/util/resourceurl"

"google.golang.org/api/iterator"
Expand Down Expand Up @@ -433,7 +432,7 @@ func (s *Service) checkDiffAndPrepareUpdateSize(existingNodePool *containerpb.No

replicas := *s.scope.MachinePool.Spec.Replicas
if shared.IsRegional(s.scope.Region()) {
replicas /= cloud.DefaultNumRegionsPerZone
replicas /= int32(len(existingNodePool.Locations))
}

if replicas != existingNodePool.InitialNodeCount {
Expand Down
10 changes: 8 additions & 2 deletions cloud/services/shared/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ func ManagedMachinePoolPreflightCheck(managedPool *infrav1exp.GCPManagedMachineP
}

if IsRegional(location) {
if *machinePool.Spec.Replicas%cloud.DefaultNumRegionsPerZone != 0 {
return fmt.Errorf("a machine pool (%s) in a regional cluster must have replicas with a multiple of %d", machinePool.Name, cloud.DefaultNumRegionsPerZone)
var numRegionsPerZone int32
if len(managedPool.Spec.NodeLocations) != 0 {
numRegionsPerZone = int32(len(managedPool.Spec.NodeLocations))
} else {
numRegionsPerZone = cloud.DefaultNumRegionsPerZone
}
if *machinePool.Spec.Replicas%numRegionsPerZone != 0 {
return fmt.Errorf("a machine pool (%s) in a regional cluster with %d regions, must have replicas with a multiple of %d", machinePool.Name, numRegionsPerZone, numRegionsPerZone)
}
}

Expand Down

0 comments on commit 818b985

Please sign in to comment.