Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

desired_nodes to 0 was not taken into account into ovh_cloud_project_kube_nodepool resource #389

Merged
merged 2 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ovh/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func GetNilIntPointerFromDataAndNilIfNotPresent(data interface{}, id string) *in
if val, ok := resourceData.GetOk(id); ok {
return GetNilIntPointer(val)
}
return GetNilIntPointer(resourceData.Get(id)) // read the 0 value
} else if mapData, tok := data.(map[string]interface{}); tok {
if val, ok := mapData[id]; ok {
return GetNilIntPointer(val)
Expand Down
54 changes: 54 additions & 0 deletions ovh/resource_cloud_project_kube_nodepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,35 @@ resource "ovh_cloud_project_kube_nodepool" "pool" {
}
`

var testAccCloudProjectKubeNodePoolConfigUpdatedScaleToZero = `
resource "ovh_cloud_project_kube" "cluster" {
service_name = "%s"
name = "%s"
region = "%s"
version = "%s"
}

resource "ovh_cloud_project_kube_nodepool" "pool" {
service_name = ovh_cloud_project_kube.cluster.service_name
kube_id = ovh_cloud_project_kube.cluster.id
name = ovh_cloud_project_kube.cluster.name
flavor_name = "b2-7"
desired_nodes = 0
min_nodes = 0
max_nodes = 2
template {
metadata {
annotations = {
a2 = "av2"
}
labels = {
l2 = "lv2"
}
}
}
}
`

func TestAccCloudProjectKubeNodePool(t *testing.T) {
name := acctest.RandomWithPrefix(test_prefix)
region := os.Getenv("OVH_CLOUD_PROJECT_KUBE_REGION_TEST")
Expand All @@ -161,6 +190,13 @@ func TestAccCloudProjectKubeNodePool(t *testing.T) {
region,
version,
)
configUpdatedScaleToZero := fmt.Sprintf(
testAccCloudProjectKubeNodePoolConfigUpdatedScaleToZero,
os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST"),
name,
region,
version,
)

resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand Down Expand Up @@ -209,6 +245,24 @@ func TestAccCloudProjectKubeNodePool(t *testing.T) {
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.taints.#", "0"),
),
},
{
Config: configUpdatedScaleToZero,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("ovh_cloud_project_kube.cluster", "region", region),
resource.TestCheckResourceAttrSet("ovh_cloud_project_kube.cluster", "kubeconfig"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube.cluster", "name", name),
resource.TestCheckResourceAttr("ovh_cloud_project_kube.cluster", "version", version),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "name", name),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "flavor_name", "b2-7"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "desired_nodes", "0"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "min_nodes", "0"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "max_nodes", "2"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.annotations.a2", "av2"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.finalizers.#", "0"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.labels.l2", "lv2"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.taints.#", "0"),
),
},
{
ResourceName: resourceName,
ImportState: true,
Expand Down