Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#1104 from kahun/fix/autoscaling
Browse files Browse the repository at this point in the history
Fix GKE autoscaling conditions in reconciliation process
  • Loading branch information
k8s-ci-robot committed Feb 4, 2024
2 parents 9831d45 + b3474c3 commit 2043c23
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
3 changes: 2 additions & 1 deletion cloud/services/container/nodepools/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ func (s *Service) checkDiffAndPrepareUpdateAutoscaling(existingNodePool *contain
setNodePoolAutoscalingRequest := containerpb.SetNodePoolAutoscalingRequest{
Name: s.scope.NodePoolFullName(),
}
if !cmp.Equal(desiredAutoscaling, existingNodePool.Autoscaling) {

if !cmp.Equal(desiredAutoscaling, existingNodePool.Autoscaling, cmpopts.IgnoreUnexported(containerpb.NodePoolAutoscaling{})) {
needUpdate = true
setNodePoolAutoscalingRequest.Autoscaling = desiredAutoscaling
}
Expand Down
41 changes: 22 additions & 19 deletions exp/api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,30 @@ func convertToSdkLocationPolicy(locationPolicy ManagedNodePoolLocationPolicy) co

// ConvertToSdkAutoscaling converts node pool autoscaling config to a value that is used by GCP SDK.
func ConvertToSdkAutoscaling(autoscaling *NodePoolAutoScaling) *containerpb.NodePoolAutoscaling {
if autoscaling == nil {
return nil
}
sdkAutoscaling := containerpb.NodePoolAutoscaling{
Enabled: true, // enable autoscaling by default
}
// set fields
if autoscaling.MinCount != nil {
sdkAutoscaling.TotalMinNodeCount = *autoscaling.MinCount
}
if autoscaling.MaxCount != nil {
sdkAutoscaling.TotalMaxNodeCount = *autoscaling.MaxCount
}
if autoscaling.EnableAutoscaling != nil {
sdkAutoscaling.Enabled = *autoscaling.EnableAutoscaling
Enabled: true, // enable autoscaling by default
TotalMinNodeCount: 0,
TotalMaxNodeCount: 1,
LocationPolicy: convertToSdkLocationPolicy(ManagedNodePoolLocationPolicyBalanced),
}
if autoscaling.LocationPolicy != nil {
sdkAutoscaling.LocationPolicy = convertToSdkLocationPolicy(*autoscaling.LocationPolicy)
} else if sdkAutoscaling.Enabled {
// if location policy is not specified and autoscaling is enabled, default location policy to "any"
sdkAutoscaling.LocationPolicy = convertToSdkLocationPolicy(ManagedNodePoolLocationPolicyAny)
if autoscaling != nil {
// set fields
if autoscaling.MinCount != nil {
sdkAutoscaling.TotalMinNodeCount = *autoscaling.MinCount
}
if autoscaling.MaxCount != nil {
sdkAutoscaling.TotalMaxNodeCount = *autoscaling.MaxCount
}
if autoscaling.LocationPolicy != nil {
sdkAutoscaling.LocationPolicy = convertToSdkLocationPolicy(*autoscaling.LocationPolicy)
}
if autoscaling.EnableAutoscaling != nil {
if !*autoscaling.EnableAutoscaling {
sdkAutoscaling = containerpb.NodePoolAutoscaling{
Enabled: false,
}
}
}
}

return &sdkAutoscaling
Expand Down
3 changes: 2 additions & 1 deletion tilt-provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"go.sum",
"api",
"cloud",
"controllers"
"controllers",
"exp"
],
"label": "CAPG"
}
Expand Down

0 comments on commit 2043c23

Please sign in to comment.