From b72e85e2dca8ebb8f501b96a5cdff42d3b2cab53 Mon Sep 17 00:00:00 2001 From: Ivan Stankov Date: Tue, 28 Nov 2023 15:14:55 +0200 Subject: [PATCH 1/3] bug: node template custom taints value should be optional --- castai/resource_node_template.go | 7 +++---- castai/resource_node_template_test.go | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/castai/resource_node_template.go b/castai/resource_node_template.go index cde251b7..f5d23630 100644 --- a/castai/resource_node_template.go +++ b/castai/resource_node_template.go @@ -336,10 +336,9 @@ func resourceNodeTemplate() *schema.Resource { Description: "Key of a taint to be added to nodes created from this template.", }, FieldValue: { - Required: true, - Type: schema.TypeString, - ValidateDiagFunc: validation.ToDiagFunc(validation.StringIsNotWhiteSpace), - Description: "Value of a taint to be added to nodes created from this template.", + Optional: true, + Type: schema.TypeString, + Description: "Value of a taint to be added to nodes created from this template.", }, FieldEffect: { Optional: true, diff --git a/castai/resource_node_template_test.go b/castai/resource_node_template_test.go index 89426068..e069705b 100644 --- a/castai/resource_node_template_test.go +++ b/castai/resource_node_template_test.go @@ -359,7 +359,7 @@ func TestAccResourceNodeTemplate_basic(t *testing.T) { resourceName := "castai_node_template.test" clusterName := "cost-terraform" - resource.ParallelTest(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProviderFactories: providerFactories, CheckDestroy: testAccCheckNodeTemplateDestroy, @@ -374,7 +374,7 @@ func TestAccResourceNodeTemplate_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "custom_labels.%", "2"), resource.TestCheckResourceAttr(resourceName, "custom_labels."+rName+"-label-key-1", rName+"-label-value-1"), resource.TestCheckResourceAttr(resourceName, "custom_labels."+rName+"-label-key-2", rName+"-label-value-2"), - resource.TestCheckResourceAttr(resourceName, "custom_taints.#", "3"), + resource.TestCheckResourceAttr(resourceName, "custom_taints.#", "4"), resource.TestCheckResourceAttr(resourceName, "custom_taints.0.key", rName+"-taint-key-1"), resource.TestCheckResourceAttr(resourceName, "custom_taints.0.value", rName+"-taint-value-1"), resource.TestCheckResourceAttr(resourceName, "custom_taints.0.effect", "NoSchedule"), @@ -384,6 +384,9 @@ func TestAccResourceNodeTemplate_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "custom_taints.2.key", rName+"-taint-key-3"), resource.TestCheckResourceAttr(resourceName, "custom_taints.2.value", rName+"-taint-value-3"), resource.TestCheckResourceAttr(resourceName, "custom_taints.2.effect", "NoSchedule"), + resource.TestCheckResourceAttr(resourceName, "custom_taints.3.key", rName+"-taint-key-4"), + resource.TestCheckResourceAttr(resourceName, "custom_taints.3.value", ""), + resource.TestCheckResourceAttr(resourceName, "custom_taints.3.effect", "NoSchedule"), resource.TestCheckResourceAttr(resourceName, "constraints.0.instance_families.0.exclude.0", "m5"), resource.TestCheckResourceAttr(resourceName, "constraints.0.gpu.0.manufacturers.0", "NVIDIA"), resource.TestCheckResourceAttr(resourceName, "constraints.0.gpu.0.include_names.#", "0"), @@ -423,9 +426,11 @@ func TestAccResourceNodeTemplate_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "custom_labels.%", "2"), resource.TestCheckResourceAttr(resourceName, "custom_labels."+rName+"-label-key-1", rName+"-label-value-1"), resource.TestCheckResourceAttr(resourceName, "custom_labels."+rName+"-label-key-2", rName+"-label-value-2"), - resource.TestCheckResourceAttr(resourceName, "custom_taints.#", "1"), + resource.TestCheckResourceAttr(resourceName, "custom_taints.#", "2"), resource.TestCheckResourceAttr(resourceName, "custom_taints.0.key", rName+"-taint-key-1"), resource.TestCheckResourceAttr(resourceName, "custom_taints.0.value", rName+"-taint-value-1"), + resource.TestCheckResourceAttr(resourceName, "custom_taints.1.key", rName+"-taint-key-2"), + resource.TestCheckResourceAttr(resourceName, "custom_taints.1.value", ""), resource.TestCheckResourceAttr(resourceName, "constraints.0.use_spot_fallbacks", "true"), resource.TestCheckResourceAttr(resourceName, "constraints.0.spot", "true"), resource.TestCheckResourceAttr(resourceName, "constraints.0.on_demand", "true"), @@ -487,6 +492,10 @@ func testAccNodeTemplateConfig(rName, clusterName string) string { value = "%[1]s-taint-value-3" } + custom_taints { + key = "%[1]s-taint-key-4" + } + constraints { fallback_restore_rate_seconds = 1800 spot = true @@ -531,6 +540,11 @@ func testNodeTemplateUpdated(rName, clusterName string) string { effect = "NoSchedule" } + custom_taints { + key = "%[1]s-taint-key-2" + effect = "NoSchedule" + } + constraints { use_spot_fallbacks = true spot = true From 56e36be22aee45aa96b71933fe242f926e7c92cb Mon Sep 17 00:00:00 2001 From: Ivan Stankov Date: Tue, 28 Nov 2023 15:17:47 +0200 Subject: [PATCH 2/3] update documentation --- docs/resources/node_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/resources/node_template.md b/docs/resources/node_template.md index 60a863a6..30dbf73a 100644 --- a/docs/resources/node_template.md +++ b/docs/resources/node_template.md @@ -90,11 +90,11 @@ Optional: Required: - `key` (String) Key of a taint to be added to nodes created from this template. -- `value` (String) Value of a taint to be added to nodes created from this template. Optional: - `effect` (String) Effect of a taint to be added to nodes created from this template, the default is NoSchedule. Allowed values: NoSchedule, NoExecute. +- `value` (String) Value of a taint to be added to nodes created from this template. From 6e6ca2f2f97a17df2bb6387b97da7a0bef7f582c Mon Sep 17 00:00:00 2001 From: Ivan Stankov Date: Tue, 28 Nov 2023 15:18:44 +0200 Subject: [PATCH 3/3] fix ParallelTest --- castai/resource_node_template_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/castai/resource_node_template_test.go b/castai/resource_node_template_test.go index e069705b..550f7c63 100644 --- a/castai/resource_node_template_test.go +++ b/castai/resource_node_template_test.go @@ -359,7 +359,7 @@ func TestAccResourceNodeTemplate_basic(t *testing.T) { resourceName := "castai_node_template.test" clusterName := "cost-terraform" - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProviderFactories: providerFactories, CheckDestroy: testAccCheckNodeTemplateDestroy,