From 92d0b85c14d0cf2f97882cc3b6d91ae6c98d815a Mon Sep 17 00:00:00 2001 From: Samuel Littley Date: Wed, 9 Aug 2023 17:25:22 +0100 Subject: [PATCH] Ignore node_count and initial_node_count when late initializing NodePools Having node_count late-initialized with autoscaling can cause the autoscaler and Crossplane to fight over how many nodes there should be (with Crossplane effectively reverting autoscaler changes). If autoscaling is used, node_count should remain unset. As documented in [0], initial_node_count may (or may not?) change if the node count is manually changed (via gcloud or the Cloud Console). This can cause resources to fail reconciliation because terraform wants to destroy and recreate the node pool. If the node count is changed manually, either Crossplane should correct it back to the value of an explicitly set node_count field, or it should be ignored because autoscaler is in use. [0]: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_node_pool#initial_node_count Signed-off-by: Samuel Littley --- apis/container/v1beta1/zz_generated_terraformed.go | 2 ++ config/container/config.go | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/apis/container/v1beta1/zz_generated_terraformed.go b/apis/container/v1beta1/zz_generated_terraformed.go index aab952077..3ceeacba6 100755 --- a/apis/container/v1beta1/zz_generated_terraformed.go +++ b/apis/container/v1beta1/zz_generated_terraformed.go @@ -198,6 +198,8 @@ func (tr *NodePool) LateInitialize(attrs []byte) (bool, error) { return false, errors.Wrap(err, "failed to unmarshal Terraform state parameters for late-initialization") } opts := []resource.GenericLateInitializerOption{resource.WithZeroValueJSONOmitEmptyFilter(resource.CNameWildcard)} + opts = append(opts, resource.WithNameFilter("InitialNodeCount")) + opts = append(opts, resource.WithNameFilter("NodeCount")) li := resource.NewGenericLateInitializer(opts...) return li.LateInitialize(&tr.Spec.ForProvider, params) diff --git a/config/container/config.go b/config/container/config.go index ef5282576..db830553a 100644 --- a/config/container/config.go +++ b/config/container/config.go @@ -127,5 +127,11 @@ func Configure(p *config.Provider) { //nolint:gocyclo Type: "Cluster", Extractor: common.ExtractResourceIDFuncPath, } + r.LateInitializer = config.LateInitializer{ + IgnoredFields: []string{ + "initial_node_count", + "node_count", + }, + } }) }