Skip to content

Commit

Permalink
K8s-8962 Only set replicas if it is outside of min/max boundaries (#83)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
phiphi282 authored Dec 18, 2023
1 parent a637231 commit def7f86
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions metakube/resource_node_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions metakube/resource_node_deployment_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion metakube/resource_node_deployment_structure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit def7f86

Please sign in to comment.