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

Dtspo 22631 - custom settings per aks cluster on SDS #658

Merged
merged 54 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
4f19202
add custom settings per aks cluster
NickAzureDevops Dec 4, 2024
4d7bb3d
edit test and stg tfvars
NickAzureDevops Dec 4, 2024
b9ee45b
edit test and stg tfvars
NickAzureDevops Dec 4, 2024
147da33
uncomment backend block
NickAzureDevops Dec 4, 2024
532d505
fix issues with system node pool and csi driver and tfvars
NickAzureDevops Dec 5, 2024
e14324b
comment out backend remote
NickAzureDevops Dec 5, 2024
557796e
edit aks.tf
NickAzureDevops Dec 5, 2024
d69c7a4
edit tfvars
NickAzureDevops Dec 5, 2024
cefa3bd
remove loop and add foreach
NickAzureDevops Dec 5, 2024
3ca912a
format code
NickAzureDevops Dec 5, 2024
55ca263
edit sbox tfvars
NickAzureDevops Dec 5, 2024
31f7fed
refactor code
NickAzureDevops Dec 5, 2024
7bc8566
revert demo,prod,ptl,stg and edit test.tfvars
NickAzureDevops Dec 5, 2024
e46bc25
comment out prod env on pipeline
NickAzureDevops Dec 5, 2024
cda33ff
comment out 00 on dev
NickAzureDevops Dec 6, 2024
f963a00
edit tfvars
NickAzureDevops Dec 6, 2024
c225086
edit tfvars
NickAzureDevops Dec 6, 2024
dd78bed
comment out prod stages
NickAzureDevops Dec 6, 2024
5a05413
format code
NickAzureDevops Dec 6, 2024
0bd5da6
edit tfvars version name
NickAzureDevops Dec 6, 2024
f2899dc
edit system node pool size
NickAzureDevops Dec 6, 2024
9e1523a
edit tfvars
NickAzureDevops Dec 6, 2024
7ed0d71
format code
NickAzureDevops Dec 6, 2024
fa5db31
edit logic in aks components
NickAzureDevops Dec 6, 2024
aedf409
format code
NickAzureDevops Dec 6, 2024
dfe6e81
edit logic in local
NickAzureDevops Dec 6, 2024
736c94f
format code
NickAzureDevops Dec 6, 2024
9a347f1
edit logic in local
NickAzureDevops Dec 6, 2024
3124063
edit logic in local
NickAzureDevops Dec 6, 2024
5349582
add min node to system node pool in cluster vars
NickAzureDevops Dec 6, 2024
1d3ca64
add min node to system node pool in cluster vars
NickAzureDevops Dec 6, 2024
35c9200
format code
NickAzureDevops Dec 6, 2024
7b9d14c
edit aks.tf
NickAzureDevops Dec 6, 2024
8764fa9
comment out backend block
NickAzureDevops Dec 6, 2024
22dea71
edit system sku
NickAzureDevops Dec 6, 2024
f40b833
edit max node for system node pool
NickAzureDevops Dec 6, 2024
ba36d0d
edit sbox max pods for linux
NickAzureDevops Dec 6, 2024
4417391
edit sbox max pods for linux
NickAzureDevops Dec 6, 2024
ff1a57c
uncommented out unwanted cluster
NickAzureDevops Dec 9, 2024
09c5fe5
edit additional node pool logic
NickAzureDevops Dec 9, 2024
17397e3
fix logic in additional nodep pool
NickAzureDevops Dec 9, 2024
16cdbc7
fix logic in additional nodep pool
NickAzureDevops Dec 9, 2024
54acbc2
revert changes from additional node pool
NickAzureDevops Dec 9, 2024
c090761
edit loop in additional node pool
NickAzureDevops Dec 9, 2024
8a36bb6
re-add msising data source
NickAzureDevops Dec 9, 2024
bdaeca6
edit tfvars values
NickAzureDevops Dec 10, 2024
fc1f9da
edit tfvars values
NickAzureDevops Dec 10, 2024
68d9afc
fix demo, dev and prod values
NickAzureDevops Dec 10, 2024
ac6a0a2
edit stg value
NickAzureDevops Dec 10, 2024
ed5d477
edit maangedcluster loop
NickAzureDevops Dec 10, 2024
0a49115
format code
NickAzureDevops Dec 10, 2024
dd8977c
edit ssh key on sbox
NickAzureDevops Dec 10, 2024
71753b5
format code
NickAzureDevops Dec 10, 2024
ce276e1
comment out other env in pipeline
NickAzureDevops Dec 10, 2024
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
130 changes: 73 additions & 57 deletions components/aks/aks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resource "azurerm_resource_group" "kubernetes_resource_group" {
name = format("%s-%s-%s-rg",
var.project,
var.env,
each.value
each.key
)
tags = module.ctags.common_tags
}
Expand All @@ -15,46 +15,6 @@ module "loganalytics" {
environment = var.env
}

locals {
linux_node_pool = {
name = "linux"
vm_size = lookup(var.linux_node_pool, "vm_size", "Standard_D4ds_v5")
min_count = lookup(var.linux_node_pool, "min_nodes", 2)
max_count = lookup(var.linux_node_pool, "max_nodes", 10)
max_pods = lookup(var.linux_node_pool, "max_pods", 30)
os_type = "Linux"
node_taints = []
enable_auto_scaling = true
mode = "User"
availability_zones = var.availability_zones
}

system_node_pool = {
name = "msnode"
vm_size = lookup(var.windows_node_pool, "vm_size", "Standard_D4ds_v5")
min_count = lookup(var.windows_node_pool, "min_nodes", 2)
max_count = lookup(var.windows_node_pool, "max_nodes", 4)
max_pods = lookup(var.windows_node_pool, "max_pods", 30)
os_type = "Windows"
node_taints = ["kubernetes.io/os=windows:NoSchedule"]
enable_auto_scaling = true
mode = "User"
availability_zones = var.availability_zones
}
cron_job_node_pool = {
name = "cronjob"
vm_size = "Standard_D4ds_v5"
min_count = 0
max_count = 10
max_pods = 30
os_type = "Linux"
node_taints = ["dedicated=jobs:NoSchedule"]
enable_auto_scaling = true
mode = "User"
availability_zones = var.availability_zones
}
}

data "azuread_service_principal" "version_checker" {
display_name = "DTS SDS AKS version checker"
}
Expand All @@ -64,14 +24,14 @@ data "azuread_service_principal" "aks_auto_shutdown" {
}

module "kubernetes" {
for_each = toset((var.env == "sbox" && var.cluster_automatic) ? [for k, v in var.clusters : k if k == "00"] : [for k, v in var.clusters : k])
for_each = var.env == "sbox" && var.cluster_automatic ? { for k, v in var.clusters : k => v if k == "00" } : var.clusters
source = "git::https://github.com/hmcts/aks-module-kubernetes.git?ref=4.x"
environment = var.env
location = var.location

kubelet_uami_enabled = true
oms_agent_enabled = var.oms_agent_enabled
csi_driver_enabled = tobool(lookup(var.clusters[each.value], "csi_driver_enabled", true))
csi_driver_enabled = var.csi_driver_enabled

providers = {
azurerm = azurerm
Expand All @@ -80,13 +40,13 @@ module "kubernetes" {
azurerm.global_acr = azurerm.global_acr
}

resource_group_name = azurerm_resource_group.kubernetes_resource_group[each.value].name
resource_group_name = azurerm_resource_group.kubernetes_resource_group[each.key].name

network_name = local.network_name
network_shortname = local.network_shortname
network_resource_group_name = local.network_resource_group_name

cluster_number = each.value
cluster_number = each.key
service_shortname = var.service_shortname
project = var.project

Expand All @@ -99,35 +59,92 @@ module "kubernetes" {

control_vault = var.control_vault

kubernetes_cluster_ssh_key = var.kubernetes_cluster_ssh_key
kubernetes_cluster_ssh_key = each.value.kubernetes_cluster_ssh_key

kubernetes_cluster_agent_min_count = lookup(var.system_node_pool, "min_nodes", 2)
kubernetes_cluster_agent_max_count = lookup(var.system_node_pool, "max_nodes", 4)
kubernetes_cluster_agent_vm_size = lookup(var.system_node_pool, "vm_size", "Standard_D4ds_v5")
kubernetes_cluster_agent_min_count = lookup(each.value.system_node_pool, "min_nodes", 2)
kubernetes_cluster_agent_max_count = lookup(each.value.system_node_pool, "max_nodes", 4)
kubernetes_cluster_agent_vm_size = lookup(each.value.system_node_pool, "vm_size", "Standard_D4ds_v5")

kubernetes_cluster_version = var.clusters[each.value]["kubernetes_version"]
kubernetes_cluster_version = each.value.kubernetes_cluster_version
kubernetes_cluster_agent_os_disk_size = "128"

tags = module.ctags.common_tags
sku_tier = var.sku_tier

enable_user_system_nodepool_split = true

additional_node_pools = contains(["ptlsbox", "ptl"], var.env) ? tolist([local.linux_node_pool, local.cron_job_node_pool]) : tolist([local.linux_node_pool, local.system_node_pool, local.cron_job_node_pool])

availability_zones = var.availability_zones
availability_zones = each.value.availability_zones

aks_version_checker_principal_id = data.azuread_service_principal.version_checker.object_id

aks_role_definition = "Contributor"

aks_auto_shutdown_principal_id = data.azuread_service_principal.aks_auto_shutdown.object_id

enable_automatic_channel_upgrade_patch = var.enable_automatic_channel_upgrade_patch
enable_automatic_channel_upgrade_patch = each.value.enable_automatic_channel_upgrade_patch

enable_node_os_channel_upgrade_nodeimage = true

node_os_maintenance_window_config = var.node_os_maintenance_window_config
node_os_maintenance_window_config = each.value.node_os_maintenance_window_config

additional_node_pools = contains(["ptlsbox", "ptl"], var.env) ? tolist([
{
name = "linux"
vm_size = lookup(each.value.linux_node_pool, "vm_size", "Standard_D4ds_v5")
min_count = lookup(each.value.linux_node_pool, "min_nodes", 2)
max_count = lookup(each.value.linux_node_pool, "max_nodes", 10)
max_pods = lookup(each.value.linux_node_pool, "max_pods", 30)
os_type = "Linux"
node_taints = []
enable_auto_scaling = true
mode = "User"
},
{
name = "cronjob"
vm_size = "Standard_D4ds_v5"
min_count = 0
max_count = 10
max_pods = 30
os_type = "Linux"
node_taints = ["dedicated=jobs:NoSchedule"]
enable_auto_scaling = true
mode = "User"
}
]) : tolist([
{
name = "linux"
vm_size = lookup(each.value.linux_node_pool, "vm_size", "Standard_D4ds_v5")
min_count = lookup(each.value.linux_node_pool, "min_nodes", 2)
max_count = lookup(each.value.linux_node_pool, "max_nodes", 10)
max_pods = lookup(each.value.linux_node_pool, "max_pods", 30)
os_type = "Linux"
node_taints = []
enable_auto_scaling = true
mode = "User"
},
{
name = "msnode"
vm_size = lookup(var.windows_node_pool, "vm_size", "Standard_D4ds_v5")
min_count = lookup(var.windows_node_pool, "min_nodes", 2)
max_count = lookup(var.windows_node_pool, "max_nodes", 4)
max_pods = lookup(var.windows_node_pool, "max_pods", 30)
os_type = "Windows"
node_taints = ["kubernetes.io/os=windows:NoSchedule"]
enable_auto_scaling = true
mode = "User"
},
{
name = "cronjob"
vm_size = "Standard_D4ds_v5"
min_count = 0
max_count = 10
max_pods = 30
os_type = "Linux"
node_taints = ["dedicated=jobs:NoSchedule"]
enable_auto_scaling = true
mode = "User"
}
])
}

module "ctags" {
Expand Down Expand Up @@ -165,8 +182,7 @@ resource "null_resource" "register_automatic_sku_preview" {
}

resource "azapi_resource" "managedCluster" {

count = var.cluster_automatic ? 1 : 0
count = var.cluster_automatic && var.env == "sbox" ? 1 : 0
type = "Microsoft.ContainerService/managedClusters@2024-03-02-preview"
parent_id = azurerm_resource_group.kubernetes_resource_group["01"].id
name = "ss-sbox-01-aks"
Expand Down
2 changes: 1 addition & 1 deletion components/aks/init.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ provider "azurerm" {
skip_provider_registration = "true"
features {}
alias = "dts-ss-stg"
}
}
10 changes: 0 additions & 10 deletions components/aks/inputs-default.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ variable "sku_tier" {
default = "Standard"
}

variable "system_node_pool" {
description = "Map to override the system node pool config"
default = {}
}

variable "linux_node_pool" {
description = "Map to override the linux node pool config"
default = {}
}

variable "windows_node_pool" {
description = "Map to override the windows node pool config"
default = {}
Expand Down
112 changes: 86 additions & 26 deletions components/aks/inputs-required.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,97 @@ variable "builtFrom" {}

variable "product" {}

# Remote State
# # Remote State
variable "control_vault" {}

# Kubernetes
variable "kubernetes_cluster_ssh_key" {}
variable "clusters" {
description = <<-EOF
Map of clusters to manage. Example:
clusters = {
"00" = {
kubernetes_cluster_version = "1.22.6"
kubernetes_cluster_ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCe..."
enable_automatic_channel_upgrade_patch = true

variable "kubernetes_cluster_agent_min_count" {
default = 1
}
variable "kubernetes_cluster_agent_max_count" {
default = 3
}
variable "kubernetes_cluster_agent_vm_size" {
default = "Standard_D4ds_v5"
}
system_node_pool = {
vm_size = "Standard_D4ds_v5"
min_nodes = 2
max_nodes = 4
}

variable "availability_zones" {
type = list(any)
}
linux_node_pool = {
vm_size = "Standard_D4ds_v5"
min_nodes = 4
max_nodes = 10
}

variable "clusters" {
type = map(map(string))
description = <<-EOF
Map of clusters to manage. Example:
clusters = {
"00" = {
kubernetes_version = "1.22.6"
},
"01" = {
kubernetes_version = "1.22.6"
}
windows_node_pool = {
vm_size = "Standard_D4ds_v5"
min_nodes = 2
max_nodes = 4
}

availability_zones = ["1"]
autoShutdown = true

node_os_maintenance_window_config = {
frequency = "Daily"
start_time = "16:00"
is_prod = false
}
},
"01" = {
kubernetes_cluster_version = "1.30"
kubernetes_cluster_ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCe..."
enable_automatic_channel_upgrade_patch = true

system_node_pool = {
min_nodes = 2
max_nodes = 4
}

linux_node_pool = {
vm_size = "Standard_D4ds_v5"
max_nodes = 10
max_nodes = 10
}

availability_zones = ["1"]
autoShutdown = true

node_os_maintenance_window_config = {
frequency = "Daily"
start_time = "16:00"
is_prod = false
}
}
}
EOF
type = map(object({
kubernetes_cluster_version = string
kubernetes_cluster_ssh_key = string
enable_automatic_channel_upgrade_patch = optional(bool, false)
system_node_pool = object({
min_nodes = number
max_nodes = number
})

linux_node_pool = object({
max_nodes = number
max_pods = number
})

node_os_maintenance_window_config = object({
frequency = string
start_time = string
is_prod = bool
})

availability_zones = list(string)
}))
}
EOF

variable "csi_driver_enabled" {
default = true
}
Loading
Loading