Skip to content

Commit

Permalink
FEATURE: add new variables to override asg and warm pool max capacity (
Browse files Browse the repository at this point in the history
…#147)

* feat: add max_count variable for asg max size

* feat: add warm pool max_group_prepared_capacity variable

* test: support new arguments

Co-authored-by: Relk Li <[email protected]>
  • Loading branch information
Downager and Downager authored May 24, 2022
1 parent 0223a21 commit 1d2d867
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
21 changes: 12 additions & 9 deletions examples/aws-eks-distro/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ module "worker_on_demand" {
subnet_ids = module.network.private_subnet_ids

instance_config = {
name = "on-demand"
count = 1
image_id = module.os_ami.image_id
name = "on-demand"
count = 1
max_count = null
image_id = module.os_ami.image_id
ec2_type = [
"t3.medium",
"t2.medium"
Expand All @@ -175,9 +176,10 @@ module "worker_on_demand" {
}

asg_warm_pool = {
enabled = true
min_size = 1
reuse_on_scale_in = false
enabled = true
min_size = 1
reuse_on_scale_in = false
max_group_prepared_capacity = 1
}

s3_bucket = module.master.ignition_s3_bucket
Expand All @@ -203,9 +205,10 @@ module "worker_spot" {
subnet_ids = module.network.private_subnet_ids

instance_config = {
name = "spot"
image_id = module.os_ami.image_id
count = 2
name = "spot"
image_id = module.os_ami.image_id
count = 2
max_count = 10
ec2_type = [
"m5.large",
"m4.large"
Expand Down
21 changes: 12 additions & 9 deletions examples/kubernetes-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ module "worker_on_demand" {
subnet_ids = module.network.private_subnet_ids

instance_config = {
name = "on-demand"
count = 1
image_id = module.os_ami.image_id
name = "on-demand"
count = 1
max_count = null
image_id = module.os_ami.image_id
ec2_type = [
"t3.medium",
"t2.medium"
Expand All @@ -140,9 +141,10 @@ module "worker_on_demand" {
}

asg_warm_pool = {
enabled = true
min_size = 1
reuse_on_scale_in = false
enabled = true
min_size = 1
reuse_on_scale_in = false
max_group_prepared_capacity = 1
}

kubelet_config = {
Expand Down Expand Up @@ -179,9 +181,10 @@ module "worker_spot" {
subnet_ids = module.network.private_subnet_ids

instance_config = {
name = "spot"
image_id = module.os_ami.image_id
count = 2
name = "spot"
image_id = module.os_ami.image_id
count = 2
max_count = 10
ec2_type = [
"m5.large",
"m4.large"
Expand Down
4 changes: 2 additions & 2 deletions modules/aws/kube-worker/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ locals {
}
}
vpc_security_group_ids = var.enable_extra_sg ? concat([aws_security_group.worker_group[0].id], var.security_group_ids) : var.security_group_ids
asg_max_size = var.instance_config["count"] == 0 ? 3 : (var.instance_config["count"] * 3)
asg_max_size = var.instance_config["max_count"] != null ? var.instance_config["max_count"] : (var.instance_config["count"] == 0 ? 3 : (var.instance_config["count"] * 3))
}

data "aws_subnet" "subnet" {
Expand Down Expand Up @@ -56,7 +56,7 @@ resource "aws_autoscaling_group" "worker" {
content {
pool_state = "Stopped"
min_size = var.asg_warm_pool["min_size"]
max_group_prepared_capacity = local.asg_max_size
max_group_prepared_capacity = var.asg_warm_pool["max_group_prepared_capacity"]

instance_reuse_policy {
reuse_on_scale_in = var.asg_warm_pool["reuse_on_scale_in"]
Expand Down
15 changes: 9 additions & 6 deletions modules/aws/kube-worker/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ variable "instance_config" {
description = "Desired worker nodes configuration."
type = object({
count = number
max_count = number
name = string
image_id = string
ec2_type = list(string)
Expand All @@ -159,14 +160,16 @@ variable "instance_config" {
variable "asg_warm_pool" {
description = "Warm pool arguments of Auto Scaling group."
type = object({
enabled = bool
min_size = number
reuse_on_scale_in = bool
enabled = bool
min_size = number
reuse_on_scale_in = bool
max_group_prepared_capacity = number
})
default = {
enabled = false
min_size = 1
reuse_on_scale_in = false
enabled = false
min_size = 1
reuse_on_scale_in = false
max_group_prepared_capacity = 1
}
}

Expand Down

0 comments on commit 1d2d867

Please sign in to comment.