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

Allow resizing kubernetes service worker-pools to 0 #5460

Merged
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
123 changes: 121 additions & 2 deletions ibm/service/kubernetes/resource_ibm_container_worker_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,59 @@ func TestAccIBMContainerWorkerPoolBasic(t *testing.T) {
})
}

func TestAccIBMContainerWorkerPoolZeroSize(t *testing.T) {

workerPoolName := fmt.Sprintf("tf-cluster-worker-%d", acctest.RandIntRange(10, 100))
clusterName := fmt.Sprintf("tf-cluster-worker-%d", acctest.RandIntRange(10, 100))

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMContainerWorkerPoolDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMContainerWorkerPoolZeroSize(clusterName, workerPoolName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"ibm_container_worker_pool.test_pool", "worker_pool_name", workerPoolName),
resource.TestCheckResourceAttr(
"ibm_container_worker_pool.test_pool", "size_per_zone", "1"),
resource.TestCheckResourceAttr(
"ibm_container_worker_pool.test_pool", "labels.%", "2"),
resource.TestCheckResourceAttr(
"ibm_container_worker_pool.test_pool", "state", "active"),
resource.TestCheckResourceAttr(
"ibm_container_worker_pool.test_pool", "disk_encryption", "true"),
resource.TestCheckResourceAttr(
"ibm_container_worker_pool.test_pool", "hardware", "shared"),
),
},
{
Config: testAccCheckIBMContainerWorkerPoolZeroSizeUpdate(clusterName, workerPoolName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"ibm_container_worker_pool.test_pool", "worker_pool_name", workerPoolName),
resource.TestCheckResourceAttr(
"ibm_container_worker_pool.test_pool", "size_per_zone", "0"),
resource.TestCheckResourceAttr(
"ibm_container_worker_pool.test_pool", "labels.%", "2"),
resource.TestCheckResourceAttr(
"ibm_container_worker_pool.test_pool", "state", "active"),
resource.TestCheckResourceAttr(
"ibm_container_worker_pool.test_pool", "disk_encryption", "true"),
resource.TestCheckResourceAttr(
"ibm_container_worker_pool.test_pool", "hardware", "shared"),
),
},
{
ResourceName: "ibm_container_worker_pool.test_pool",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccIBMContainerWorkerPoolInvalidSizePerZone(t *testing.T) {
workerPoolName := fmt.Sprintf("tf-cluster-worker-%d", acctest.RandIntRange(10, 100))
clusterName := fmt.Sprintf("tf-cluster-worker-%d", acctest.RandIntRange(10, 100))
Expand All @@ -82,7 +135,7 @@ func TestAccIBMContainerWorkerPoolInvalidSizePerZone(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccCheckIBMContainerWorkerPoolInvalidSizePerZone(clusterName, workerPoolName),
ExpectError: regexp.MustCompile("must be greater than 0"),
ExpectError: regexp.MustCompile("must be non-negative"),
},
},
})
Expand Down Expand Up @@ -190,13 +243,79 @@ resource "ibm_container_worker_pool" "test_pool" {
}`, clusterName, acc.Datacenter, acc.MachineType, acc.PublicVlanID, acc.PrivateVlanID, acc.KubeVersion, workerPoolName, acc.MachineType)
}

func testAccCheckIBMContainerWorkerPoolZeroSize(clusterName, workerPoolName string) string {
return fmt.Sprintf(`

resource "ibm_container_cluster" "testacc_cluster" {
name = "%s"
datacenter = "%s"
machine_type = "%s"
hardware = "shared"
public_vlan_id = "%s"
private_vlan_id = "%s"
kube_version = "%s"
wait_till = "OneWorkerNodeReady"
taints {
key = "key1"
value = "value1"
effect = "NoSchedule"
}
}

resource "ibm_container_worker_pool" "test_pool" {
worker_pool_name = "%s"
machine_type = "%s"
cluster = ibm_container_cluster.testacc_cluster.id
size_per_zone = 1
hardware = "shared"
disk_encryption = true
labels = {
"test" = "test-pool"
"test1" = "test-pool1"
}
taints {
key = "key1"
value = "value1"
effect = "NoSchedule"
}
}`, clusterName, acc.Datacenter, acc.MachineType, acc.PublicVlanID, acc.PrivateVlanID, acc.KubeVersion, workerPoolName, acc.MachineType)
}

func testAccCheckIBMContainerWorkerPoolZeroSizeUpdate(clusterName, workerPoolName string) string {
return fmt.Sprintf(`

resource "ibm_container_cluster" "testacc_cluster" {
name = "%s"
datacenter = "%s"
machine_type = "%s"
hardware = "shared"
public_vlan_id = "%s"
private_vlan_id = "%s"
kube_version = "%s"
wait_till = "OneWorkerNodeReady"
}

resource "ibm_container_worker_pool" "test_pool" {
worker_pool_name = "%s"
machine_type = "%s"
cluster = ibm_container_cluster.testacc_cluster.id
size_per_zone = 0
hardware = "shared"
disk_encryption = true
labels = {
"test" = "test-pool"
"test1" = "test-pool1"
}
}`, clusterName, acc.Datacenter, acc.MachineType, acc.PublicVlanID, acc.PrivateVlanID, acc.KubeVersion, workerPoolName, acc.MachineType)
}

func testAccCheckIBMContainerWorkerPoolInvalidSizePerZone(clusterName, workerPoolName string) string {
return fmt.Sprintf(`
resource "ibm_container_worker_pool" "test_pool" {
worker_pool_name = "%s"
machine_type = "%s"
cluster = "%s"
size_per_zone = 0
size_per_zone = -1
hardware = "shared"
disk_encryption = true

Expand Down
6 changes: 3 additions & 3 deletions ibm/validate/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
homedir "github.com/mitchellh/go-homedir"
"github.com/mitchellh/go-homedir"

"github.com/IBM-Cloud/bluemix-go/helpers"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
Expand Down Expand Up @@ -304,9 +304,9 @@ func ValidateWeight(v interface{}, k string) (ws []string, errors []error) {

func ValidateSizePerZone(v interface{}, k string) (ws []string, errors []error) {
sizePerZone := v.(int)
if sizePerZone <= 0 {
if sizePerZone < 0 {
errors = append(errors, fmt.Errorf(
"%q must be greater than 0",
"%q must be non-negative",
k))
}
return
Expand Down
Loading