Skip to content

Commit 2043c23

Browse files
authored
Merge pull request #1104 from kahun/fix/autoscaling
Fix GKE autoscaling conditions in reconciliation process
2 parents 9831d45 + b3474c3 commit 2043c23

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

cloud/services/container/nodepools/reconcile.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ func (s *Service) checkDiffAndPrepareUpdateAutoscaling(existingNodePool *contain
420420
setNodePoolAutoscalingRequest := containerpb.SetNodePoolAutoscalingRequest{
421421
Name: s.scope.NodePoolFullName(),
422422
}
423-
if !cmp.Equal(desiredAutoscaling, existingNodePool.Autoscaling) {
423+
424+
if !cmp.Equal(desiredAutoscaling, existingNodePool.Autoscaling, cmpopts.IgnoreUnexported(containerpb.NodePoolAutoscaling{})) {
424425
needUpdate = true
425426
setNodePoolAutoscalingRequest.Autoscaling = desiredAutoscaling
426427
}

exp/api/v1beta1/types.go

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,30 @@ func convertToSdkLocationPolicy(locationPolicy ManagedNodePoolLocationPolicy) co
8181

8282
// ConvertToSdkAutoscaling converts node pool autoscaling config to a value that is used by GCP SDK.
8383
func ConvertToSdkAutoscaling(autoscaling *NodePoolAutoScaling) *containerpb.NodePoolAutoscaling {
84-
if autoscaling == nil {
85-
return nil
86-
}
8784
sdkAutoscaling := containerpb.NodePoolAutoscaling{
88-
Enabled: true, // enable autoscaling by default
89-
}
90-
// set fields
91-
if autoscaling.MinCount != nil {
92-
sdkAutoscaling.TotalMinNodeCount = *autoscaling.MinCount
93-
}
94-
if autoscaling.MaxCount != nil {
95-
sdkAutoscaling.TotalMaxNodeCount = *autoscaling.MaxCount
96-
}
97-
if autoscaling.EnableAutoscaling != nil {
98-
sdkAutoscaling.Enabled = *autoscaling.EnableAutoscaling
85+
Enabled: true, // enable autoscaling by default
86+
TotalMinNodeCount: 0,
87+
TotalMaxNodeCount: 1,
88+
LocationPolicy: convertToSdkLocationPolicy(ManagedNodePoolLocationPolicyBalanced),
9989
}
100-
if autoscaling.LocationPolicy != nil {
101-
sdkAutoscaling.LocationPolicy = convertToSdkLocationPolicy(*autoscaling.LocationPolicy)
102-
} else if sdkAutoscaling.Enabled {
103-
// if location policy is not specified and autoscaling is enabled, default location policy to "any"
104-
sdkAutoscaling.LocationPolicy = convertToSdkLocationPolicy(ManagedNodePoolLocationPolicyAny)
90+
if autoscaling != nil {
91+
// set fields
92+
if autoscaling.MinCount != nil {
93+
sdkAutoscaling.TotalMinNodeCount = *autoscaling.MinCount
94+
}
95+
if autoscaling.MaxCount != nil {
96+
sdkAutoscaling.TotalMaxNodeCount = *autoscaling.MaxCount
97+
}
98+
if autoscaling.LocationPolicy != nil {
99+
sdkAutoscaling.LocationPolicy = convertToSdkLocationPolicy(*autoscaling.LocationPolicy)
100+
}
101+
if autoscaling.EnableAutoscaling != nil {
102+
if !*autoscaling.EnableAutoscaling {
103+
sdkAutoscaling = containerpb.NodePoolAutoscaling{
104+
Enabled: false,
105+
}
106+
}
107+
}
105108
}
106109

107110
return &sdkAutoscaling

tilt-provider.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"go.sum",
99
"api",
1010
"cloud",
11-
"controllers"
11+
"controllers",
12+
"exp"
1213
],
1314
"label": "CAPG"
1415
}

0 commit comments

Comments
 (0)