Skip to content

Commit 647292d

Browse files
committed
moved cluster autoscaler to a module
Signed-off-by: junior <junior@users.noreply.github.com>
1 parent c3a3214 commit 647292d

File tree

1 file changed

+54
-33
lines changed

1 file changed

+54
-33
lines changed

module-oke.tf

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ module "oke" {
3232
## Cluster API Endpoint visibility
3333
cluster_endpoint_visibility = var.cluster_endpoint_visibility
3434

35+
## Control Plane Kubernetes Version
36+
k8s_version = var.k8s_version
37+
3538
## Create Dynamic group and Policies for Autoscaler and OCI Metrics and Logging
3639
create_dynamic_group_for_nodes_in_compartment = var.create_dynamic_group_for_nodes_in_compartment
3740
create_compartment_policies = var.create_compartment_policies
@@ -42,27 +45,41 @@ module "oke" {
4245
existent_encryption_key_id = var.existent_encryption_key_id
4346

4447
## Enable Cluster Autoscaler
45-
cluster_autoscaler_enabled = var.cluster_autoscaler_enabled
46-
cluster_autoscaler_min_nodes = var.cluster_autoscaler_min_nodes
47-
cluster_autoscaler_max_nodes = var.cluster_autoscaler_max_nodes
48-
existent_oke_nodepool_id_for_autoscaler = var.existent_oke_nodepool_id_for_autoscaler
48+
cluster_autoscaler_enabled = var.cluster_autoscaler_enabled
49+
# cluster_autoscaler_min_nodes = var.cluster_autoscaler_min_nodes
50+
# cluster_autoscaler_max_nodes = var.cluster_autoscaler_max_nodes
51+
# existent_oke_nodepool_id_for_autoscaler = var.existent_oke_nodepool_id_for_autoscaler
4952

5053
## OKE Worker Nodes (Compute)
51-
num_pool_workers = var.num_pool_workers
54+
num_pool_workers = var.cluster_autoscaler_enabled ? var.cluster_autoscaler_min_nodes : var.num_pool_workers
5255
node_pool_shape = var.node_pool_instance_shape.instanceShape
5356
node_pool_node_shape_config_ocpus = var.node_pool_instance_shape.ocpus
5457
node_pool_node_shape_config_memory_in_gbs = var.node_pool_instance_shape.memory
5558
generate_public_ssh_key = var.generate_public_ssh_key
5659
public_ssh_key = var.public_ssh_key
60+
}
61+
62+
module "oke-cluster-autoscaler" {
63+
source = "./modules/oke-cluster-autoscaler"
5764

58-
# count = var.oke_provision ? 1 : 0
65+
# Oracle Cloud Infrastructure Tenancy and Compartment OCID
66+
# tenancy_ocid = var.tenancy_ocid
67+
# compartment_ocid = var.compartment_ocid
68+
region = var.region
69+
70+
## Enable Cluster Autoscaler
71+
cluster_autoscaler_enabled = var.cluster_autoscaler_enabled
72+
# cluster_autoscaler_min_nodes = var.cluster_autoscaler_min_nodes
73+
# cluster_autoscaler_max_nodes = var.cluster_autoscaler_max_nodes
74+
# existent_oke_nodepool_id_for_autoscaler = var.existent_oke_nodepool_id_for_autoscaler
75+
oke_node_pools = var.oke_node_pools
76+
77+
## Nodes Kubernetes Version
78+
k8s_version = var.k8s_version
79+
80+
depends_on = [module.oke]
5981
}
6082

61-
# OKE Variables
62-
# variable "oke_provision" {
63-
# default = false
64-
# description = "Provision OCI Container Engine - OKE"
65-
# }
6683
## OKE Cluster Details
6784
variable "app_name" {
6885
default = "K8s App"
@@ -142,18 +159,30 @@ variable "cluster_autoscaler_enabled" {
142159
default = true
143160
description = "Enables OKE cluster autoscaler. Node pools will auto scale based on the resources usage"
144161
}
145-
variable "cluster_autoscaler_min_nodes" {
146-
default = 3
147-
description = "Minimum number of nodes on the node pool to be scheduled by the Kubernetes"
148-
}
149-
variable "cluster_autoscaler_max_nodes" {
150-
default = 10
151-
description = "Maximum number of nodes on the node pool to be scheduled by the Kubernetes"
152-
}
153-
variable "existent_oke_nodepool_id_for_autoscaler" {
154-
default = ""
155-
description = "Nodepool Id of the existent OKE to use with Cluster Autoscaler"
156-
}
162+
variable "oke_node_pools" {
163+
type = list(any)
164+
165+
default = [
166+
{
167+
node_pool_id = "" # TODO: node pool Id from module
168+
node_pool_min_nodes = 3
169+
node_pool__max_nodes = 10
170+
}
171+
]
172+
description = "Node pools (id, min_nodes, max_nodes) to use with Cluster Autoscaler"
173+
}
174+
# variable "cluster_autoscaler_min_nodes" {
175+
# default = 3
176+
# description = "Minimum number of nodes on the node pool to be scheduled by the Kubernetes"
177+
# }
178+
# variable "cluster_autoscaler_max_nodes" {
179+
# default = 10
180+
# description = "Maximum number of nodes on the node pool to be scheduled by the Kubernetes"
181+
# }
182+
# variable "existent_oke_nodepool_id_for_autoscaler" {
183+
# default = ""
184+
# description = "Nodepool Id of the existent OKE to use with Cluster Autoscaler"
185+
# }
157186

158187
## OKE Node Pool Details
159188
variable "node_pool_name" {
@@ -179,14 +208,6 @@ variable "node_pool_instance_shape" {
179208
}
180209
description = "A shape is a template that determines the number of OCPUs, amount of memory, and other resources allocated to a newly created instance for the Worker Node. Select at least 2 OCPUs and 16GB of memory if using Flex shapes"
181210
}
182-
# variable "node_pool_node_shape_config_ocpus" {
183-
# default = "1" # Only used if flex shape is selected
184-
# description = "You can customize the number of OCPUs to a flexible shape"
185-
# }
186-
# variable "node_pool_node_shape_config_memory_in_gbs" {
187-
# default = "16" # Only used if flex shape is selected
188-
# description = "You can customize the amount of memory allocated to a flexible shape"
189-
# }
190211
variable "node_pool_boot_volume_size_in_gbs" {
191212
default = "60"
192213
description = "Specify a custom boot volume size (in GB)"
@@ -209,15 +230,15 @@ variable "public_ssh_key" {
209230

210231
# Create Dynamic Group and Policies
211232
variable "create_dynamic_group_for_nodes_in_compartment" {
212-
default = false # TODO: true
233+
default = true
213234
description = "Creates dynamic group of Nodes in the compartment. Note: You need to have proper rights on the Tenancy. If you only have rights in a compartment, uncheck and ask you administrator to create the Dynamic Group for you"
214235
}
215236
variable "existent_dynamic_group_for_nodes_in_compartment" {
216237
default = ""
217238
description = "Enter previous created Dynamic Group for the policies"
218239
}
219240
variable "create_compartment_policies" {
220-
default = false # TODO: true
241+
default = true
221242
description = "Creates policies that will reside on the compartment. e.g.: Policies to support Cluster Autoscaler, OCI Logging datasource on Grafana"
222243
}
223244

0 commit comments

Comments
 (0)