Skip to content

Commit 46ec5f4

Browse files
robo-capdevoncrouse
authored andcommitted
Add option to ignore size for nodepools and instance pools
1 parent c8e8410 commit 46ec5f4

File tree

8 files changed

+318
-29
lines changed

8 files changed

+318
-29
lines changed

docs/src/guide/extensions_cluster_autoscaler.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Extensions: Cluster Autoscaler
1+
# Extensions: Standalone Cluster Autoscaler
22

33
Deployed using the [cluster-autoscaler Helm chart](https://github.com/kubernetes/autoscaler/tree/master/charts/cluster-autoscaler) with configuration from the `worker_pools` variable.
44

@@ -13,6 +13,66 @@ The following parameters may be added on each pool definition to enable manageme
1313
* `min_size`: Define the minimum scale of a pool managed by the cluster autoscaler. Defaults to `size` when not provided.
1414
* `max_size`: Define the maximum scale of a pool managed by the cluster autoscaler. Defaults to `size` when not provided.
1515

16+
The cluster-autoscaler will manage the size of the nodepools with the attribute `autoscale = true`. To avoid the conflict between the actual `size` of a nodepool and the `size` defined in the terraform configuration files, you can add the `ignore_initial_pool_size = true` attribute to the nodepool definition in the `worker_pools` variable. This parameter will allow terraform to ignore the [drift](https://developer.hashicorp.com/terraform/tutorials/state/resource-drift) of the size parameter for the specific nodepool.
17+
18+
This setting is strongly recommended for nodepools configured with `autoscale = true`.
19+
20+
Example:
21+
22+
```
23+
worker_pools = {
24+
np-autoscaled = {
25+
description = "Node pool managed by cluster autoscaler",
26+
size = 2,
27+
min_size = 1,
28+
max_size = 3,
29+
autoscale = true,
30+
ignore_initial_pool_size = true # allows nodepool size drift
31+
},
32+
np-autoscaler = {
33+
description = "Node pool with cluster autoscaler scheduling allowed",
34+
size = 1,
35+
allow_autoscaler = true,
36+
},
37+
}
38+
39+
```
40+
41+
42+
For existing deployments is necessary to use the [terraform state mv](https://developer.hashicorp.com/terraform/cli/commands/state/mv) command.
43+
44+
Example for `nodepool` resource:
45+
```
46+
47+
$ terraform plan
48+
...
49+
Terraform will perform the following actions:
50+
51+
# module.oke.module.workers[0].oci_containerengine_node_pool.tfscaled_workers["np-autoscaled"] will be destroyed
52+
...
53+
54+
# module.oke.module.workers[0].oci_containerengine_node_pool.autoscaled_workers["np-autoscaled"] will be created
55+
56+
57+
$ terraform state mv module.oke.module.workers[0].oci_containerengine_node_pool.tfscaled_workers[\"np-autoscaled\"] module.oke.module.workers[0].oci_containerengine_node_pool.autoscaled_workers[\"np-autoscaled\"]
58+
59+
Successfully moved 1 object(s).
60+
61+
$ terraform plan
62+
...
63+
No changes. Your infrastructure matches the configuration.
64+
65+
```
66+
67+
Example for `instance_pool` resource:
68+
69+
```
70+
$ terraform state mv module.oke.module.workers[0].oci_core_instance_pool.tfscaled_workers[\"np-autoscaled\"] module.oke.module.workers[0].oci_core_instance_pool.autoscaled_workers[\"np-autoscaled\"]
71+
72+
Successfully moved 1 object(s).
73+
74+
```
75+
1676
### Notes
1777

1878
Don't set `allow_autoscaler` and `autoscale` to `true` on the same pool. This will cause the cluster autoscaler pod to be unschedulable as the `oke.oraclecloud.com/cluster_autoscaler: managed` node label will override the `oke.oraclecloud.com/cluster_autoscaler: allowed` node label specified by the cluster autoscaler `nodeSelector` pod attribute.

docs/src/resources.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
## Workers
5454
<!-- BEGIN_TF_WORKERS -->
5555

56-
* [oci_containerengine_node_pool.workers](https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/containerengine_node_pool)
56+
* [oci_containerengine_node_pool.tfscaled_workers](https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/containerengine_node_pool)
5757
* [oci_containerengine_virtual_node_pool.workers](https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/containerengine_virtual_node_pool)
5858
* [oci_core_cluster_network.workers](https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_cluster_network)
5959
* [oci_core_instance.workers](https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_instance)

examples/workers/vars-workers-advanced.auto.tfvars

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,26 @@ worker_pools = {
2525
create = false
2626
},
2727
wg_np-vm-ol7 = {
28-
description = "OKE-managed Node Pool with OKE Oracle Linux 7 image",
29-
create = false,
30-
mode = "node-pool",
31-
size = 1,
32-
size_max = 2,
33-
os = "Oracle Linux",
34-
os_version = "7",
35-
autoscale = true,
28+
description = "OKE-managed Node Pool with OKE Oracle Linux 7 image",
29+
create = false,
30+
mode = "node-pool",
31+
size = 1,
32+
size_max = 2,
33+
os = "Oracle Linux",
34+
os_version = "7",
35+
autoscale = true,
36+
ignore_initial_pool_size = true
3637
},
3738
wg_np-vm-ol8 = {
38-
description = "OKE-managed Node Pool with OKE Oracle Linux 8 image",
39-
create = false,
40-
mode = "node-pool",
41-
size = 1,
42-
size_max = 3,
43-
os = "Oracle Linux",
44-
os_version = "8",
45-
autoscale = true,
39+
description = "OKE-managed Node Pool with OKE Oracle Linux 8 image",
40+
create = false,
41+
mode = "node-pool",
42+
size = 1,
43+
size_max = 3,
44+
os = "Oracle Linux",
45+
os_version = "8",
46+
autoscale = true,
47+
ignore_initial_pool_size = true
4648
},
4749
wg_np-vm-custom = {
4850
description = "OKE-managed Node Pool with custom image",

examples/workers/vars-workers-autoscaling.auto.tfvars

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
worker_pools = {
77
np-autoscaled = {
8-
description = "Node pool managed by cluster autoscaler",
9-
size = 2,
10-
min_size = 1,
11-
max_size = 3,
12-
autoscale = true,
8+
description = "Node pool managed by cluster autoscaler",
9+
size = 2,
10+
min_size = 1,
11+
max_size = 3,
12+
autoscale = true,
13+
ignore_initial_pool_size = true
1314
},
1415
np-autoscaler = {
1516
description = "Node pool with cluster autoscaler scheduling allowed",

migration.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,13 @@ moved {
4949
from = module.oke.oci_containerengine_node_pool.nodepools
5050
to = module.workers[0].oci_containerengine_node_pool.workers
5151
}
52+
53+
moved {
54+
from = module.workers[0].oci_containerengine_node_pool.workers
55+
to = module.workers[0].oci_containerengine_node_pool.tfscaled_workers
56+
}
57+
58+
moved {
59+
from = module.workers[0].oci_core_instance_pool.workers
60+
to = module.workers[0].oci_core_instance_pool.tfscaled_workers
61+
}

modules/workers/instancepools.tf

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
33

44
# Dynamic resource block for Instance Pool groups defined in worker_pools
5-
resource "oci_core_instance_pool" "workers" {
5+
resource "oci_core_instance_pool" "tfscaled_workers" {
66
# Create an OCI Instance Pool resource for each enabled entry of the worker_pools map with that mode.
7-
for_each = local.enabled_instance_pools
7+
for_each = { for key, value in local.enabled_instance_pools: key => value if tobool(lookup(value, "ignore_initial_pool_size", false)) == false }
88
compartment_id = each.value.compartment_id
99
display_name = each.key
1010
size = each.value.size
@@ -61,3 +61,63 @@ resource "oci_core_instance_pool" "workers" {
6161
}
6262
}
6363
}
64+
65+
resource "oci_core_instance_pool" "autoscaled_workers" {
66+
# Create an OCI Instance Pool resource for each enabled entry of the worker_pools map with that mode.
67+
for_each = { for key, value in local.enabled_instance_pools: key => value if tobool(lookup(value, "ignore_initial_pool_size", false)) == true }
68+
compartment_id = each.value.compartment_id
69+
display_name = each.key
70+
size = each.value.size
71+
instance_configuration_id = oci_core_instance_configuration.workers[each.key].id
72+
defined_tags = each.value.defined_tags
73+
freeform_tags = each.value.freeform_tags
74+
75+
dynamic "placement_configurations" {
76+
for_each = each.value.availability_domains
77+
iterator = ad
78+
79+
content {
80+
availability_domain = ad.value
81+
primary_subnet_id = each.value.subnet_id
82+
83+
# Value(s) specified on pool, or null to select automatically
84+
fault_domains = try(each.value.placement_fds, null)
85+
86+
dynamic "secondary_vnic_subnets" {
87+
for_each = lookup(each.value, "secondary_vnics", {})
88+
iterator = vnic
89+
content {
90+
display_name = vnic.key
91+
subnet_id = lookup(vnic.value, "subnet_id", each.value.subnet_id)
92+
}
93+
}
94+
}
95+
}
96+
97+
lifecycle {
98+
ignore_changes = [
99+
display_name, defined_tags, freeform_tags,
100+
placement_configurations, size
101+
]
102+
103+
precondition {
104+
condition = coalesce(each.value.image_id, "none") != "none"
105+
error_message = <<-EOT
106+
Missing image_id; check provided value if image_type is 'custom', or image_os/image_os_version if image_type is 'oke' or 'platform'.
107+
pool: ${each.key}
108+
image_type: ${coalesce(each.value.image_type, "none")}
109+
image_id: ${coalesce(each.value.image_id, "none")}
110+
EOT
111+
}
112+
113+
precondition {
114+
condition = var.cni_type == "flannel"
115+
error_message = "Instance Pools require a cluster with `cni_type = flannel`."
116+
}
117+
118+
precondition {
119+
condition = each.value.autoscale == false
120+
error_message = "Instance Pools do not support cluster autoscaler management."
121+
}
122+
}
123+
}

modules/workers/locals.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ locals {
3636
eviction_grace_duration = 300
3737
force_node_delete = true
3838
extended_metadata = {} # empty pool-specific default
39+
ignore_initial_pool_size = false
3940
image_id = var.image_id
4041
image_type = var.image_type
4142
kubernetes_version = var.kubernetes_version
@@ -231,9 +232,9 @@ locals {
231232
}
232233

233234
# Maps of worker pool OCI resources by pool name enriched with desired/custom parameters for various modes
234-
worker_node_pools = { for k, v in oci_containerengine_node_pool.workers : k => merge(v, lookup(local.worker_pools_final, k, {})) }
235+
worker_node_pools = { for k, v in merge(oci_containerengine_node_pool.tfscaled_workers, oci_containerengine_node_pool.autoscaled_workers) : k => merge(v, lookup(local.worker_pools_final, k, {})) }
235236
worker_virtual_node_pools = { for k, v in oci_containerengine_virtual_node_pool.workers : k => merge(v, lookup(local.worker_pools_final, k, {})) }
236-
worker_instance_pools = { for k, v in oci_core_instance_pool.workers : k => merge(v, lookup(local.worker_pools_final, k, {})) }
237+
worker_instance_pools = { for k, v in merge(oci_core_instance_pool.tfscaled_workers, oci_core_instance_pool.autoscaled_workers) : k => merge(v, lookup(local.worker_pools_final, k, {})) }
237238
worker_cluster_networks = { for k, v in oci_core_cluster_network.workers : k => merge(v, lookup(local.worker_pools_final, k, {})) }
238239
worker_instances = { for k, v in oci_core_instance.workers : k => merge(v, lookup(local.worker_pools_final, k, {})) }
239240

0 commit comments

Comments
 (0)