Skip to content

Commit

Permalink
Hotfix (typo): rename node_pools to node_pool (#407)
Browse files Browse the repository at this point in the history
* (typo) rename node_pools to node_pool

* make the acc tests and k8s example simpler

* reword node_pool description

* reword node_pool docs

* reformat k8s docs

* make node_pool required
  • Loading branch information
nvthongswansea authored Jan 3, 2025
1 parent 5c53faa commit 4e7ae82
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 95 deletions.
42 changes: 21 additions & 21 deletions gridscale/resource_gridscale_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ func (rgk8sm *ResourceGridscaleK8sModeler) buildInputSchema() map[string]*schema
Description: "PaaS service template identifier for this service.",
Computed: true,
},
"node_pools": {
"node_pool": {
Type: schema.TypeList,
Optional: true,
Description: `Define a list of pools and their attributes.`,
Required: true,
Description: `Define a node pool and its attributes.`,
Elem: &schema.Resource{
Schema: nodePoolSchema,
},
Expand Down Expand Up @@ -794,7 +794,7 @@ func resourceGridscaleK8sRead(d *schema.ResourceData, meta interface{}) error {
}
}
// Set node pools
if err = d.Set("node_pools", nodePools); err != nil {
if err = d.Set("node_pool", nodePools); err != nil {
return fmt.Errorf("%s error setting node_pool: %v", errorPrefix, err)
}
// Set cluster CIDR if it is set
Expand Down Expand Up @@ -872,21 +872,21 @@ func resourceGridscaleK8sCreate(d *schema.ResourceData, meta interface{}) error
parameters := make(map[string]interface{})

// Iterate over requested node pools to set them
if nodePoolsRequestedInterface, ok := d.GetOk("node_pools"); ok {
if nodePoolsRequestedInterface, ok := d.GetOk("node_pool"); ok {
nodePoolsRequested := nodePoolsRequestedInterface.([]interface{})
nodePools := make([]map[string]interface{}, 0)

for index, _ := range nodePoolsRequested {
nodePool := make(map[string]interface{}, 0)
nodePool["name"] = d.Get(fmt.Sprintf("node_pools.%d.name", index))
nodePool["count"] = d.Get(fmt.Sprintf("node_pools.%d.node_count", index))
nodePool["ram"] = d.Get(fmt.Sprintf("node_pools.%d.memory", index))
nodePool["cores"] = d.Get(fmt.Sprintf("node_pools.%d.cores", index))
nodePool["storage"] = d.Get(fmt.Sprintf("node_pools.%d.storage", index))
nodePool["storage_type"] = d.Get(fmt.Sprintf("node_pools.%d.storage_type", index))
nodePool["name"] = d.Get(fmt.Sprintf("node_pool.%d.name", index))
nodePool["count"] = d.Get(fmt.Sprintf("node_pool.%d.node_count", index))
nodePool["ram"] = d.Get(fmt.Sprintf("node_pool.%d.memory", index))
nodePool["cores"] = d.Get(fmt.Sprintf("node_pool.%d.cores", index))
nodePool["storage"] = d.Get(fmt.Sprintf("node_pool.%d.storage", index))
nodePool["storage_type"] = d.Get(fmt.Sprintf("node_pool.%d.storage_type", index))

// Set rocket storage if it is set
if rocketStorage, isRocketStorageSet := d.GetOk(fmt.Sprintf("node_pools.%d.rocket_storage", index)); isRocketStorageSet {
if rocketStorage, isRocketStorageSet := d.GetOk(fmt.Sprintf("node_pool.%d.rocket_storage", index)); isRocketStorageSet {
nodePool["rocket_storage"] = rocketStorage
}
nodePools = append(nodePools, nodePool)
Expand Down Expand Up @@ -1039,21 +1039,21 @@ func resourceGridscaleK8sUpdate(d *schema.ResourceData, meta interface{}) error
parameters := make(map[string]interface{})

// Iterate over requested node pools to set them
if nodePoolsRequestedInterface, ok := d.GetOk("node_pools"); ok {
if nodePoolsRequestedInterface, ok := d.GetOk("node_pool"); ok {
nodePoolsRequested := nodePoolsRequestedInterface.([]interface{})
nodePools := make([]map[string]interface{}, 0)

for index, _ := range nodePoolsRequested {
nodePool := make(map[string]interface{}, 0)
nodePool["name"] = d.Get(fmt.Sprintf("node_pools.%d.name", index))
nodePool["count"] = d.Get(fmt.Sprintf("node_pools.%d.node_count", index))
nodePool["ram"] = d.Get(fmt.Sprintf("node_pools.%d.memory", index))
nodePool["cores"] = d.Get(fmt.Sprintf("node_pools.%d.cores", index))
nodePool["storage"] = d.Get(fmt.Sprintf("node_pools.%d.storage", index))
nodePool["storage_type"] = d.Get(fmt.Sprintf("node_pools.%d.storage_type", index))
nodePool["name"] = d.Get(fmt.Sprintf("node_pool.%d.name", index))
nodePool["count"] = d.Get(fmt.Sprintf("node_pool.%d.node_count", index))
nodePool["ram"] = d.Get(fmt.Sprintf("node_pool.%d.memory", index))
nodePool["cores"] = d.Get(fmt.Sprintf("node_pool.%d.cores", index))
nodePool["storage"] = d.Get(fmt.Sprintf("node_pool.%d.storage", index))
nodePool["storage_type"] = d.Get(fmt.Sprintf("node_pool.%d.storage_type", index))

// Set rocket storage if it is set
if rocketStorage, isRocketStorageSet := d.GetOk(fmt.Sprintf("node_pools.%d.rocket_storage", index)); isRocketStorageSet {
if rocketStorage, isRocketStorageSet := d.GetOk(fmt.Sprintf("node_pool.%d.rocket_storage", index)); isRocketStorageSet {
nodePool["rocket_storage"] = rocketStorage
}
nodePools = append(nodePools, nodePool)
Expand Down Expand Up @@ -1206,7 +1206,7 @@ func validateK8sParameters(d *schema.ResourceDiff, template gsclient.PaaSTemplat
return err
}
templateParameterNodePools, templateParameterNodePoolsFound := template.Properties.ParametersSchema["pools"]
nodePoolsRequestedInterface, isNodePoolsRequested := d.GetOk("node_pools")
nodePoolsRequestedInterface, isNodePoolsRequested := d.GetOk("node_pool")

if templateParameterNodePoolsFound && isNodePoolsRequested {
nodePoolsRequested := nodePoolsRequestedInterface.([]interface{})
Expand Down
53 changes: 9 additions & 44 deletions gridscale/resource_gridscale_k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,19 @@ func TestAccResourceGridscaleK8sBasic(t *testing.T) {

func testAccCheckResourceGridscaleK8sConfigBasic(name string) string {
return fmt.Sprintf(`
variable "node_pools" {
description = "A list of node pools"
default = [
{
resource "gridscale_k8s" "foopaas" {
name = "%s"
release = "1.30"
node_pool {
name = "my-node-pool"
node_count = 2
cores = 1
memory = 2
storage = 30
storage_type = "storage_insane"
rocket_storage = 90
}
]
}
resource "gridscale_k8s" "foopaas" {
name = "%s"
release = "1.30"
dynamic "node_pools" {
for_each = var.node_pools
content {
name = node_pools.value.name
node_count = node_pools.value.node_count
cores = node_pools.value.cores
memory = node_pools.value.memory
storage = node_pools.value.storage
storage_type = node_pools.value.storage_type
rocket_storage = node_pools.value.rocket_storage
}
}
surge_node = false
oidc_enabled = true
oidc_issuer_url = "https://sts.windows.net/fe4ac456-23a7-4841-a404-01fcb695412c/"
Expand All @@ -87,35 +70,17 @@ resource "gridscale_k8s" "foopaas" {

func testAccCheckResourceGridscaleK8sConfigBasicUpdate() string {
return `
variable "node_pools" {
description = "A list of node pools"
default = [
{
resource "gridscale_k8s" "foopaas" {
name = "newname"
release = "1.30"
node_pool {
name = "my-node-pool"
node_count = 2
cores = 1
memory = 2
storage = 30
storage_type = "storage_insane"
rocket_storage = 90
}
]
}
resource "gridscale_k8s" "foopaas" {
name = "newname"
release = "1.30"
dynamic "node_pools" {
for_each = var.node_pools
content {
name = node_pools.value.name
node_count = node_pools.value.node_count
cores = node_pools.value.cores
memory = node_pools.value.memory
storage = node_pools.value.storage
storage_type = node_pools.value.storage_type
rocket_storage = node_pools.value.rocket_storage
}
}
surge_node = false
}
Expand Down
51 changes: 21 additions & 30 deletions website/docs/r/k8s.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,27 @@ Provides a k8s cluster resource. This can be used to create, modify, and delete
The following example shows how one might use this resource to add a k8s cluster to gridscale:

```terraform
variable "node_pools" {
description = "A list of node pools"
default = [
{
name = "test_node_pool"
node_count = 2
cores = 1
memory = 2
storage = 30
storage_type = "storage_insane"
rocket_storage = 90
}
]
resource "gridscale_k8s" "k8s-test" {
name = "test"
release = "1.30" # instead, gsk_version can be set.
node_pool {
name = "pool-0"
node_count = 2
cores = 2
memory = 4
storage = 30
storage_type = "storage_insane"
}
resource "gridscale_k8s" "k8s-test" {
name = "test"
release = "1.30" # instead, gsk_version can be set.
dynamic "node_pools" {
for_each = var.node_pools
content {
name = node_pools.value.name
node_count = node_pools.value.node_count
cores = node_pools.value.cores
memory = node_pools.value.memory
storage = node_pools.value.storage
storage_type = node_pools.value.storage_type
rocket_storage = node_pools.value.rocket_storage
}
}
node_pool {
name = "pool-1"
node_count = 3
cores = 1
memory = 3
storage = 30
storage_type = "storage_insane"
}
}
```

Expand All @@ -63,7 +54,7 @@ The following arguments are supported:

* `labels` - (Optional) List of labels in the format [ "label1", "label2" ].

* `node_pools` - (Optional) The collection of node pool specifications. **NOTE**: Any node pool specification is not yet mutable (except `node_count`).
* `node_pool` - (Required) The collection of node pool specifications. Mutiple node pools can be defined with multiple `node_pool` blocks. The node pool block supports the following arguments:
* `name` - Name of the node pool.
* `node_count` - Number of worker nodes.
* `cores` - Cores per worker node.
Expand Down Expand Up @@ -121,7 +112,7 @@ This resource exports the following attributes:
* `kubeconfig` - The kubeconfig file content of the k8s cluster.
* `network_uuid` - *DEPRECATED* Network UUID containing security zone, which is linked to the k8s cluster.
* `k8s_private_network_uuid` - Private network UUID which k8s nodes are attached to. It can be used to attach other PaaS/VMs.
* `node_pools` - See Argument Reference above.
* `node_pool` - See Argument Reference above.
* `name` - See Argument Reference above.
* `node_count` - See Argument Reference above.
* `cores` - See Argument Reference above.
Expand Down

0 comments on commit 4e7ae82

Please sign in to comment.