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

Use instance pools for node groups #98

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions control_plane.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module "master" {
deploy_target_id = var.deploy_target_id

bootstrap_bucket = var.bootstrap_bucket

use_instancepool = var.use_instancepools
}

resource "exoscale_domain_record" "etcd" {
Expand Down
2 changes: 2 additions & 0 deletions infra.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ module "infra" {
deploy_target_id = var.deploy_target_id

bootstrap_bucket = var.bootstrap_bucket

use_instancepool = var.use_instancepools
}
32 changes: 28 additions & 4 deletions modules/node-group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ locals {
// having to work around merge() being a shallow merge in the compute
// instance resource.
user_data = [
for hostname in random_id.node_id[*].hex :
for hostname in(var.use_instancepool ? ["dummy"] : random_id.node_id[*].hex) :
{
"ignition" : {
"version" : "3.1.0",
Expand All @@ -42,7 +42,7 @@ locals {
"storage" : {
// concatenate the private network config (if requested) with the
// `/etc/hostname` override.
"files" : concat(
"files" : var.use_instancepool ? [] : concat(
var.use_privnet ? local.privnet_config_files : [],
// override /etc/hostname with short hostname, this works around the
// fact that we can't set a separate `name` and `display_name` for
Expand Down Expand Up @@ -158,7 +158,7 @@ locals {
}

resource "random_id" "node_id" {
count = var.node_count
count = var.use_instancepool ? 0 : var.node_count
prefix = "${var.role}-"
byte_length = 2
}
Expand All @@ -170,7 +170,7 @@ resource "exoscale_anti_affinity_group" "anti_affinity_group" {
}

resource "exoscale_compute_instance" "nodes" {
count = var.node_count
count = var.use_instancepool ? 0 : var.node_count
name = "${random_id.node_id[count.index].hex}.${var.cluster_domain}"
ssh_key = var.ssh_key_pair
zone = var.region
Expand Down Expand Up @@ -207,3 +207,27 @@ resource "exoscale_compute_instance" "nodes" {
]
}
}

resource "exoscale_instance_pool" "nodes" {
count = var.use_instancepool ? local.anti_affinity_group_count : 0
name = "${var.role}-${count.index}"
size = var.node_count
zone = var.region
key_pair = var.ssh_key_pair
template_id = var.template_id

instance_prefix = var.role
instance_type = var.instance_type

disk_size = local.disk_size
user_data = base64encode(jsonencode(local.user_data[0]))

deploy_target_id = var.deploy_target_id

security_group_ids = var.security_group_ids

anti_affinity_group_ids = concat(
[exoscale_anti_affinity_group.anti_affinity_group[count.index].id],
var.additional_affinity_group_ids
)
}
6 changes: 5 additions & 1 deletion modules/node-group/output.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
locals {
instance_pool_ips = var.use_instancepool ? exoscale_instance_pool.nodes[*].instances[*].public_ip_address : []
instance_ips = var.use_privnet ? exoscale_compute_instance.nodes[*].network_interface[0].ip_address : exoscale_compute_instance.nodes[*].public_ip_address
}
output "ip_address" {
value = var.use_privnet ? exoscale_compute_instance.nodes[*].network_interface[0].ip_address : exoscale_compute_instance.nodes[*].public_ip_address
value = var.use_instancepool ? local.instance_pool_ips : local.instance_ips
}
6 changes: 6 additions & 0 deletions modules/node-group/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,9 @@ variable "affinity_group_capacity" {
default = 0
description = "Capacity of the affinity group, e.g. when using dedicated hypervisors, default: 0 (unlimited)"
}

variable "use_instancepool" {
type = bool
description = "Use instancepool for this node group"
default = false
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,9 @@ variable "additional_lb_security_group_ids" {
default = []
description = "List of additional security group IDs to configure on the LBs"
}

variable "use_instancepools" {
type = bool
description = "Use instance pools for node groups"
default = true
}
6 changes: 5 additions & 1 deletion worker.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ module "worker" {
deploy_target_id = var.deploy_target_id

bootstrap_bucket = var.bootstrap_bucket

use_instancepool = var.use_instancepools
}

// Additional worker groups.
Expand Down Expand Up @@ -74,7 +76,7 @@ module "additional_worker" {
[exoscale_security_group.all_machines.id]
)

affinity_group_capacity = var.affinity_group_capacity
affinity_group_capacity = 1
additional_affinity_group_ids = concat(
each.value.affinity_group_ids != null ? each.value.affinity_group_ids : [],
var.additional_affinity_group_ids
Expand All @@ -83,4 +85,6 @@ module "additional_worker" {
deploy_target_id = var.deploy_target_id

bootstrap_bucket = var.bootstrap_bucket

use_instancepool = true
}
Loading