Skip to content

Commit

Permalink
K8s-11784 fix node deployment min/max replicas handling
Browse files Browse the repository at this point in the history
These fields were turned into pointers in the API so they can be set to
0, which wasn't previously possible.
  • Loading branch information
multi-io committed Dec 5, 2024
1 parent d7da245 commit d7572c5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0
github.com/mitchellh/go-homedir v1.1.0
github.com/syseleven/go-metakube v0.0.0-20241203225354-74465a218b83
github.com/syseleven/go-metakube v0.0.0-20241205132328-a44ad284c0ec
go.uber.org/zap v1.19.0
golang.org/x/mod v0.14.0
k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/syseleven/go-metakube v0.0.0-20241203225354-74465a218b83 h1:bp3I3hfrknpnJlZKVbG9APJfemhCFt7nBcMx1oAOoVE=
github.com/syseleven/go-metakube v0.0.0-20241203225354-74465a218b83/go.mod h1:KJB8m9a51Dcci9ee2pLwKetFm9MUrOAjDPAm5ZnOnHI=
github.com/syseleven/go-metakube v0.0.0-20241205132328-a44ad284c0ec h1:fu2xwlrSDyh9tIhW+CN7QJfTevFSI+zQfmSu8DlsgEM=
github.com/syseleven/go-metakube v0.0.0-20241205132328-a44ad284c0ec/go.mod h1:KJB8m9a51Dcci9ee2pLwKetFm9MUrOAjDPAm5ZnOnHI=
github.com/syseleven/terraform-plugin-sdk/v2 v2.31.0-sys11-2 h1:vywVVW9AnKcEiqgbZe16wwuaQaZ8VtMe+xmNBdvdMnU=
github.com/syseleven/terraform-plugin-sdk/v2 v2.31.0-sys11-2/go.mod h1:i2C41tszDjiWfziPQDL5R/f3Zp0gahXe5No/MIO9rCE=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
Expand Down
16 changes: 8 additions & 8 deletions metakube/resource_node_deployment_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ func metakubeNodeDeploymentFlattenSpec(in *models.NodeDeploymentSpec) []interfac
att["replicas"] = *in.Replicas
}

if in.MinReplicas >= 0 && in.MaxReplicas > 0 {
att["min_replicas"] = in.MinReplicas
if in.MinReplicas != nil {
att["min_replicas"] = *in.MinReplicas
}

if in.MaxReplicas > 0 {
att["max_replicas"] = in.MaxReplicas
if in.MaxReplicas != nil {
att["max_replicas"] = *in.MaxReplicas
}

if in.Template != nil {
Expand Down Expand Up @@ -304,20 +304,20 @@ func metakubeNodeDeploymentExpandSpec(p []interface{}, isCreate bool) *models.No

if v, ok := in["min_replicas"]; ok {
if vv, ok := v.(int); ok {
obj.MinReplicas = int32(vv)
obj.MinReplicas = ptr.To(int32(vv))
if isCreate {
obj.Replicas = int32ToPtr(obj.MinReplicas)
obj.Replicas = int32ToPtr(*obj.MinReplicas)
}
}
}

if v, ok := in["max_replicas"]; ok {
if vv, ok := v.(int); ok {
obj.MaxReplicas = int32(vv)
obj.MaxReplicas = ptr.To(int32(vv))
}
}

if v, ok := in["replicas"]; ok && obj.MinReplicas == 0 {
if v, ok := in["replicas"]; ok && *obj.MinReplicas == 0 {
if vv, ok := v.(int); ok {
obj.Replicas = int32ToPtr(int32(vv))
}
Expand Down

0 comments on commit d7572c5

Please sign in to comment.