Skip to content

Commit

Permalink
improve logic for the cluster autoscaler extension
Browse files Browse the repository at this point in the history
  • Loading branch information
robo-cap authored and devoncrouse committed Oct 12, 2023
1 parent 4d9ab74 commit 31e995e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions module-extensions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module "extensions" {
cluster_autoscaler_helm_version = var.cluster_autoscaler_helm_version
cluster_autoscaler_helm_values = var.cluster_autoscaler_helm_values
cluster_autoscaler_helm_values_files = var.cluster_autoscaler_helm_values_files
expected_autoscale_worker_pools = coalesce(one(module.workers[*].worker_pool_autoscale_expected), 0)

# Gatekeeper
gatekeeper_install = var.gatekeeper_install
Expand Down
2 changes: 1 addition & 1 deletion modules/extensions/autoscaler.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ locals {
cluster_autoscaler_enabled = alltrue([
var.cluster_autoscaler_install,
var.expected_node_count > 0,
length(local.worker_pools_autoscaling) > 0,
var.expected_autoscale_worker_pools > 0,
])

# Templated Helm manifest values
Expand Down
1 change: 1 addition & 0 deletions modules/extensions/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ variable "cluster_autoscaler_namespace" { type = string }
variable "cluster_autoscaler_helm_version" { type = string }
variable "cluster_autoscaler_helm_values" { type = map(string) }
variable "cluster_autoscaler_helm_values_files" { type = list(string) }
variable "expected_autoscale_worker_pools" { type = number }

# Prometheus
variable "prometheus_install" { type = bool }
Expand Down
5 changes: 5 additions & 0 deletions modules/workers/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ locals {
for k, v in local.enabled_worker_pools : tobool(v.drain) ? lookup(v, "size", var.worker_pool_size) : 0
])

# Number of work pools in the worker pools with autoscale enabled
expected_autoscale_worker_pools = length(local.enabled_worker_pools) == 0 ? 0 : sum([
for k, v in local.enabled_worker_pools : tobool(v.autoscale) ? 1 : 0
])

# Enabled worker_pool map entries for node pools
enabled_node_pools = {
for k, v in local.enabled_worker_pools : k => v
Expand Down
5 changes: 5 additions & 0 deletions modules/workers/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ output "worker_drain_expected" {
description = "# of nodes expected to be draining in worker pools"
value = local.expected_drain_count
}

output "worker_pool_autoscale_expected" {
description = "# of worker pools expected with autoscale enabled from created worker pools"
value = local.expected_autoscale_worker_pools
}

0 comments on commit 31e995e

Please sign in to comment.