Skip to content

Commit

Permalink
feat: add workload scaling policies (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
varnastadeus authored Aug 12, 2024
1 parent b735801 commit eb89712
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ Usage examples are located in [terraform provider repo](https://github.com/casta
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13 |
| <a name="requirement_azuread"></a> [azuread](#requirement\_azuread) | >= 2.22.0 |
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | >= 3.7.0 |
| <a name="requirement_castai"></a> [castai](#requirement\_castai) | ~> 7.10 |
| <a name="requirement_castai"></a> [castai](#requirement\_castai) | ~> 7.11 |
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | >= 2.0.0 |

## Providers
Expand All @@ -302,7 +302,7 @@ Usage examples are located in [terraform provider repo](https://github.com/casta
|------|---------|
| <a name="provider_azuread"></a> [azuread](#provider\_azuread) | >= 2.22.0 |
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | >= 3.7.0 |
| <a name="provider_castai"></a> [castai](#provider\_castai) | ~> 7.10 |
| <a name="provider_castai"></a> [castai](#provider\_castai) | ~> 7.11 |
| <a name="provider_helm"></a> [helm](#provider\_helm) | >= 2.0.0 |
| <a name="provider_null"></a> [null](#provider\_null) | n/a |

Expand All @@ -326,6 +326,7 @@ No modules.
| [castai_node_configuration.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/node_configuration) | resource |
| [castai_node_configuration_default.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/node_configuration_default) | resource |
| [castai_node_template.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/node_template) | resource |
| [castai_workload_scaling_policy.this](https://registry.terraform.io/providers/castai/castai/latest/docs/resources/workload_scaling_policy) | resource |
| [helm_release.castai_agent](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [helm_release.castai_cluster_controller](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [helm_release.castai_cluster_controller_self_managed](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
Expand Down Expand Up @@ -386,6 +387,7 @@ No modules.
| <a name="input_wait_for_cluster_ready"></a> [wait\_for\_cluster\_ready](#input\_wait\_for\_cluster\_ready) | Wait for cluster to be ready before finishing the module execution, this option requires `castai_api_token` to be set | `bool` | `false` | no |
| <a name="input_workload_autoscaler_values"></a> [workload\_autoscaler\_values](#input\_workload\_autoscaler\_values) | List of YAML formatted string with cluster-workload-autoscaler values | `list(string)` | `[]` | no |
| <a name="input_workload_autoscaler_version"></a> [workload\_autoscaler\_version](#input\_workload\_autoscaler\_version) | Version of castai-workload-autoscaler helm chart. Default latest | `string` | `null` | no |
| <a name="input_workload_scaling_policies"></a> [workload\_scaling\_policies](#input\_workload\_scaling\_policies) | Map of workload scaling policies to create | `any` | `{}` | no |

## Outputs

Expand Down
21 changes: 21 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,27 @@ resource "castai_node_template" "this" {
depends_on = [castai_autoscaler.castai_autoscaler_policies]
}

resource "castai_workload_scaling_policy" "this" {
for_each = { for k, v in var.workload_scaling_policies : k => v }

name = try(each.value.name, each.key)
cluster_id = castai_aks_cluster.castai_cluster.id

apply_type = try(each.value.apply_type, "DEFERRED")
management_option = try(each.value.management_option, "READ_ONLY")
cpu {
function = try(each.value.cpu.function, "QUANTILE")
overhead = try(each.value.cpu.overhead, 0)
apply_threshold = try(each.value.cpu.apply_threshold, 0.1)
args = try(each.value.cpu.args, ["0.8"])
}
memory {
function = try(each.value.memory.function, "MAX")
overhead = try(each.value.memory.overhead, 0.1)
apply_threshold = try(each.value.memory.apply_threshold, 0.1)
}
}

resource "helm_release" "castai_agent" {
name = "castai-agent"
repository = "https://castai.github.io/helm-charts"
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ variable "node_templates" {
default = {}
}

variable "workload_scaling_policies" {
type = any
description = "Map of workload scaling policies to create"
default = {}
}

variable "install_security_agent" {
type = bool
default = false
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ terraform {
}
castai = {
source = "castai/castai"
version = "~> 7.10"
version = "~> 7.11"
}
helm = {
source = "hashicorp/helm"
Expand Down

0 comments on commit eb89712

Please sign in to comment.