Skip to content

Commit

Permalink
add label controls
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin-DynamicD committed Sep 7, 2023
1 parent 31f344b commit 441f9a5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
6 changes: 3 additions & 3 deletions aks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ resource "azurerm_kubernetes_cluster_node_pool" "user" {
mode = local.node_user_pool.mode
name = local.node_user_pool.name
node_count = local.node_user_pool.node_count
node_labels = local.node_user_pool_defaults[local.node_user_pool.priority].labels
node_taints = local.node_user_pool_defaults[local.node_user_pool.priority].taints
node_labels = local.node_user_pool_merged.node_labels
node_taints = local.node_user_pool_merged.node_taints
os_disk_size_gb = local.node_user_pool.os_disk_size_gb
os_disk_type = local.node_user_pool.os_disk_type
priority = local.node_user_pool.priority
Expand All @@ -81,4 +81,4 @@ resource "azurerm_kubernetes_cluster_node_pool" "user" {
vm_size = local.node_user_pool.vm_size
vnet_subnet_id = local.subnet_id # must be defined or terraform will redeploy despite documentation stating optional
zones = local.zones != [] ? local.zones : null
}
}
25 changes: 18 additions & 7 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,32 @@ locals {
# details: https://docs.microsoft.com/en-us/azure/aks/spot-node-pool
node_user_pool_defaults = {
Regular = {
labels = {}
taints = []
node_labels = {}
node_taints = []
}
Spot = {
labels = {
node_labels = {
"kubernetes.azure.com/scalesetpriority" = "spot"
}
taints = [
node_taints = [
"kubernetes.azure.com/scalesetpriority=spot:NoSchedule"
]
}
}

# merges the node_pool_defaults into the node_user_pool per priority
# type (see above) Allows user to override values.
node_user_pool = var.node_user_pool
# merges the node_user_pool_defaults with the node_user_pool via
# priority type (see above). Allows user to add values.
# node_user_pool = var.node_user_pool
node_user_pool_merged = {
node_labels = merge(
var.node_user_pool.node_labels,
local.node_user_pool_defaults[var.node_user_pool.priority].node_labels
)
node_taints = concat(
var.node_user_pool.node_taints,
local.node_user_pool_defaults[var.node_user_pool.priority].node_taints
)
}

# these are unmodified, just dropped into locals for consistency
acr_list = var.acr_list
Expand All @@ -45,6 +55,7 @@ locals {
docker_bridge_cidr = var.docker_bridge_cidr
location = var.location
node_default_pool = var.node_default_pool
node_user_pool = var.node_user_pool
oms = var.oms
resource_group_name = var.resource_group_name
sku_tier = var.sku_tier
Expand Down
2 changes: 2 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ variable "node_user_pool" {
mode = optional(string, "User")
name = optional(string, "user")
node_count = optional(number, 2)
node_labels = optional(map(any), {}) # needs defaults as we merge it later
node_taints = optional(list(string), []) # needs defaults as we concat it later
os_disk_size_gb = optional(number, 120)
os_disk_type = optional(string, "Ephemeral")
priority = optional(string, "Regular")
Expand Down

0 comments on commit 441f9a5

Please sign in to comment.