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

fix : set desired_nodes without max_nodes and min_nodes #538

Merged
merged 1 commit into from
Jan 18, 2024
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
4 changes: 2 additions & 2 deletions ovh/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ func GetNilStringPointerFromData(data interface{}, id string) *string {
// GetNilIntPointerFromDataAndNilIfNotPresent similar to GetNilIntPointerFromData but use terraform function schema.ResourceData.Get instead of schema.ResourceData.GetOk
func GetNilIntPointerFromDataAndNilIfNotPresent(data interface{}, id string) *int {
if resourceData, tok := data.(*schema.ResourceData); tok {
if val, ok := resourceData.GetOk(id); ok {
if val, ok := resourceData.GetOkExists(id); ok {
return GetNilIntPointer(val)
}
return GetNilIntPointer(resourceData.Get(id)) // read the 0 value
return nil //key doesn't exist
} else if mapData, tok := data.(map[string]interface{}); tok {
if val, ok := mapData[id]; ok {
return GetNilIntPointer(val)
Expand Down
72 changes: 70 additions & 2 deletions ovh/resource_cloud_project_kube_nodepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,46 @@ resource "ovh_cloud_project_kube_nodepool" "pool" {

`

func TestAccCloudProjectKubeNodePool(t *testing.T) {
var testAccCloudProjectKubeNodePoolConfigWithoutMaxMin = `
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 = 1
template {
metadata {
annotations = {
a1 = "av1"
}
finalizers = ["finalizer.extensions/v1beta1"]
labels = {
l1 = "lv1"
}
}
spec {
unschedulable = false
taints = [
{
effect = "PreferNoSchedule"
key = "t1"
value = "tv1"
}
]
}
}
}

`

func TestAccCloudProjectKubeNodePoolRessource(t *testing.T) {
name := acctest.RandomWithPrefix(test_prefix)
region := os.Getenv("OVH_CLOUD_PROJECT_KUBE_REGION_TEST")
version := os.Getenv("OVH_CLOUD_PROJECT_KUBE_VERSION_TEST")
Expand All @@ -316,7 +355,13 @@ func TestAccCloudProjectKubeNodePool(t *testing.T) {
region,
version,
)

configWithoutMaxMinNodes := fmt.Sprintf(
testAccCloudProjectKubeNodePoolConfigWithoutMaxMin,
os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST"),
name,
region,
version,
)
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheckCloud(t)
Expand All @@ -325,6 +370,29 @@ func TestAccCloudProjectKubeNodePool(t *testing.T) {
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: configWithoutMaxMinNodes,
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", "1"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "min_nodes", "0"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "max_nodes", "100"),

resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.annotations.a1", "av1"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.finalizers.0", "finalizer.extensions/v1beta1"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.metadata.0.labels.l1", "lv1"),

resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.taints.0.effect", "PreferNoSchedule"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.taints.0.key", "t1"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.taints.0.value", "tv1"),
resource.TestCheckResourceAttr("ovh_cloud_project_kube_nodepool.pool", "template.0.spec.0.unschedulable", "false"),
),
},
{
Config: config,
Check: resource.ComposeTestCheckFunc(
Expand Down