From b3474c3b5e6cb17633f8cd663126be08c64c8421 Mon Sep 17 00:00:00 2001 From: Francisco Augusto Date: Tue, 19 Dec 2023 09:48:47 +0100 Subject: [PATCH] Fix autoscaling conditions --- .../services/container/nodepools/reconcile.go | 4 +- exp/api/v1beta1/types.go | 41 ++++++++++--------- tilt-provider.json | 3 +- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/cloud/services/container/nodepools/reconcile.go b/cloud/services/container/nodepools/reconcile.go index b02e1cbd9..a19b457b6 100644 --- a/cloud/services/container/nodepools/reconcile.go +++ b/cloud/services/container/nodepools/reconcile.go @@ -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" @@ -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 } diff --git a/exp/api/v1beta1/types.go b/exp/api/v1beta1/types.go index 6f4baf0a2..fd23cc3f7 100644 --- a/exp/api/v1beta1/types.go +++ b/exp/api/v1beta1/types.go @@ -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 diff --git a/tilt-provider.json b/tilt-provider.json index 94ba98dd5..bcbbb3fd4 100644 --- a/tilt-provider.json +++ b/tilt-provider.json @@ -8,7 +8,8 @@ "go.sum", "api", "cloud", - "controllers" + "controllers", + "exp" ], "label": "CAPG" }