Skip to content

Commit

Permalink
feat: add workload scaling policies (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
varnastadeus authored Aug 12, 2024
1 parent ea35938 commit 54f7c36
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,14 +457,14 @@ terraform-docs markdown table . --output-file README.md
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 2.49 |
| <a name="requirement_castai"></a> [castai](#requirement\_castai) | ~> 7.4 |
| <a name="requirement_castai"></a> [castai](#requirement\_castai) | ~> 7.11 |
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | >= 2.0.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_castai"></a> [castai](#provider\_castai) | ~> 7.4 |
| <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 @@ -481,6 +481,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 @@ -531,18 +532,20 @@ No modules.
| <a name="input_install_egressd"></a> [install\_egressd](#input\_install\_egressd) | Optional flag for installation of Egressd (Network cost monitoring) (https://docs.cast.ai/docs/network-cost) | `bool` | `false` | no |
| <a name="input_install_security_agent"></a> [install\_security\_agent](#input\_install\_security\_agent) | Optional flag for installation of security agent (https://docs.cast.ai/product-overview/console/security-insights/) | `bool` | `false` | no |
| <a name="input_install_workload_autoscaler"></a> [install\_workload\_autoscaler](#input\_install\_workload\_autoscaler) | Optional flag for installation of workload autoscaler (https://docs.cast.ai/docs/workload-autoscaling-configuration) | `bool` | `false` | no |
| <a name="input_kvisor_controller_extra_args"></a> [kvisor\_controller\_extra\_args](#input\_kvisor\_controller\_extra\_args) | Extra arguments for the kvisor controller. Optionally enable kvisor to lint Kubernetes YAML manifests, scan workload images and check if workloads pass CIS Kubernetes Benchmarks as well as NSA, WASP and PCI recommendations. | `map(string)` | <pre>{<br> "image-scan-enabled": "true",<br> "kube-bench-enabled": "true",<br> "kube-linter-enabled": "true"<br>}</pre> | no |
| <a name="input_kvisor_values"></a> [kvisor\_values](#input\_kvisor\_values) | List of YAML formatted string with kvisor values | `list(string)` | `[]` | no |
| <a name="input_kvisor_version"></a> [kvisor\_version](#input\_kvisor\_version) | Version of kvisor chart. Default latest | `string` | `null` | no |
| <a name="input_kvisor_controller_extra_args"></a> [kvisor\_controller\_extra\_args](#input\_kvisor\_controller\_extra\_args) | Map of extra arguments for the kvisor controller | `map(string)` |`{`<br>`kube-linter-enabled = true`<br>`image-scan-enabled = true`<br>`kube-bench-enabled = true`<br>`}`| no |
| <a name="input_node_configurations"></a> [node\_configurations](#input\_node\_configurations) | Map of EKS node configurations to create | `any` | `{}` | no |
| <a name="input_node_templates"></a> [node\_templates](#input\_node\_templates) | Map of node templates to create | `any` | `{}` | no |
| <a name="input_pod_pinner_values"></a> [pod\_pinner\_values](#input\_pod\_pinner\_values) | List of YAML formatted string values for agent helm chart | `list(string)` | `[]` | no |
| <a name="input_pod_pinner_version"></a> [pod\_pinner\_version](#input\_pod\_pinner\_version) | Version of pod-pinner helm chart. Default latest | `string` | `null` | no |
| <a name="input_self_managed"></a> [self\_managed](#input\_self\_managed) | Whether CAST AI components' upgrades are managed by a customer; by default upgrades are managed CAST AI central system. | `bool` | `false` | no |
| <a name="input_spot_handler_values"></a> [spot\_handler\_values](#input\_spot\_handler\_values) | List of YAML formatted string with spot-handler values | `list(string)` | `[]` | no |
| <a name="input_spot_handler_version"></a> [spot\_handler\_version](#input\_spot\_handler\_version) | Version of castai-spot-handler helm chart. Default latest | `string` | `null` | no |
| <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
25 changes: 23 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,27 @@ resource "castai_node_configuration_default" "this" {
configuration_id = var.default_node_configuration
}

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_eks_cluster.my_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 Expand Up @@ -334,7 +355,7 @@ resource "helm_release" "castai_workload_autoscaler" {
value = "castai-cluster-controller"
}

depends_on = [helm_release.castai_agent]
depends_on = [helm_release.castai_agent, helm_release.castai_cluster_controller]

lifecycle {
ignore_changes = [version]
Expand Down Expand Up @@ -365,7 +386,7 @@ resource "helm_release" "castai_workload_autoscaler_self_managed" {
value = "castai-cluster-controller"
}

depends_on = [helm_release.castai_agent, helm_release.castai_workload_autoscaler]
depends_on = [helm_release.castai_agent, helm_release.castai_cluster_controller]
}

#---------------------------------------------------#
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,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 @@ -8,7 +8,7 @@ terraform {
}
castai = {
source = "castai/castai"
version = "~> 7.10"
version = "~> 7.11"
}
helm = {
source = "hashicorp/helm"
Expand Down

0 comments on commit 54f7c36

Please sign in to comment.