From def7f86fbe1cdfcd63a2b710ba342d3bf64195bf Mon Sep 17 00:00:00 2001 From: Phillip Date: Mon, 18 Dec 2023 14:47:55 +0100 Subject: [PATCH] K8s-8962 Only set replicas if it is outside of min/max boundaries (#83) * Only set replicas if it is outside of min/max boundaries If no boundaries are set then replicas is set to the input. If the replicas are inside the boundaries it is also set to the input. * Handle replica variables in big if/else --- metakube/resource_node_deployment.go | 4 ++-- metakube/resource_node_deployment_structure.go | 6 ++++-- metakube/resource_node_deployment_structure_test.go | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/metakube/resource_node_deployment.go b/metakube/resource_node_deployment.go index 0a43f9a..4f4f9e4 100644 --- a/metakube/resource_node_deployment.go +++ b/metakube/resource_node_deployment.go @@ -116,7 +116,7 @@ func metakubeResourceNodeDeploymentCreate(ctx context.Context, d *schema.Resourc nodeDeployment := &models.NodeDeployment{ Name: d.Get("name").(string), - Spec: metakubeNodeDeploymentExpandSpec(d.Get("spec").([]interface{})), + Spec: metakubeNodeDeploymentExpandSpec(d.Get("spec").([]interface{}), true), } if err := metakubeResourceNodeDeploymentVersionCompatibleWithCluster(ctx, k, projectID, clusterID, nodeDeployment); err != nil { @@ -223,7 +223,7 @@ func metakubeResourceNodeDeploymentUpdate(ctx context.Context, d *schema.Resourc clusterID := d.Get("cluster_id").(string) nodeDeployment := &models.NodeDeployment{ - Spec: metakubeNodeDeploymentExpandSpec(d.Get("spec").([]interface{})), + Spec: metakubeNodeDeploymentExpandSpec(d.Get("spec").([]interface{}), false), } if err := metakubeResourceNodeDeploymentVersionCompatibleWithCluster(ctx, k, projectID, clusterID, nodeDeployment); err != nil { diff --git a/metakube/resource_node_deployment_structure.go b/metakube/resource_node_deployment_structure.go index 4c5fa99..9f2791b 100644 --- a/metakube/resource_node_deployment_structure.go +++ b/metakube/resource_node_deployment_structure.go @@ -285,7 +285,7 @@ func metakubeNodeDeploymentFlattenAzureSpec(in *models.AzureNodeSpec) []interfac // expanders -func metakubeNodeDeploymentExpandSpec(p []interface{}) *models.NodeDeploymentSpec { +func metakubeNodeDeploymentExpandSpec(p []interface{}, isCreate bool) *models.NodeDeploymentSpec { if len(p) < 1 { return nil } @@ -302,7 +302,9 @@ func metakubeNodeDeploymentExpandSpec(p []interface{}) *models.NodeDeploymentSpe if v, ok := in["min_replicas"]; ok { if vv, ok := v.(int); ok { obj.MinReplicas = int32(vv) - obj.Replicas = int32ToPtr(obj.MinReplicas) + if isCreate { + obj.Replicas = int32ToPtr(obj.MinReplicas) + } } } diff --git a/metakube/resource_node_deployment_structure_test.go b/metakube/resource_node_deployment_structure_test.go index 43527f8..f1b4b24 100644 --- a/metakube/resource_node_deployment_structure_test.go +++ b/metakube/resource_node_deployment_structure_test.go @@ -404,7 +404,7 @@ func TestExpandNodeDeploymentSpec(t *testing.T) { } for _, tc := range cases { - output := metakubeNodeDeploymentExpandSpec(tc.Input) + output := metakubeNodeDeploymentExpandSpec(tc.Input, false) if diff := cmp.Diff(tc.ExpectedOutput, output); diff != "" { t.Fatalf("Unexpected output from expander: mismatch (-want +got):\n%s", diff) }