Skip to content
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
4 changes: 3 additions & 1 deletion cloud/services/container/nodepools/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"cloud.google.com/go/container/apiv1/containerpb"
"github.com/go-logr/logr"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/googleapis/gax-go/v2/apierror"
"github.com/pkg/errors"
"sigs.k8s.io/cluster-api-provider-gcp/cloud/providerid"
Expand Down Expand Up @@ -410,7 +411,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