Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GKE MachinePool replicas per region #1100

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cloud/scope/managedmachinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ func (s *ManagedMachinePoolScope) NodePoolVersion() *string {
func ConvertToSdkNodePool(nodePool infrav1exp.GCPManagedMachinePool, machinePool clusterv1exp.MachinePool, regional bool) *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"
"reflect"

"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 @@ -411,7 +410,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
Loading