diff --git a/CHANGELOG.md b/CHANGELOG.md index db941be..101d612 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,15 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [0.2.0] - 2024-05-16 + +[Compare with previous version](https://github.com/sparkfabrik/terraform-helm-descheduler/compare/0.1.0...0.2.0) + +### Added + +- Add `ServiceMonitor` configuration for Prometheus. +- Add `additional_values` variable to allow customizing the Helm chart values. + ## [0.1.0] - 2024-05-15 - First release. diff --git a/README.md b/README.md index d99641a..5c46327 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ This module installs [Descheduler](https://github.com/kubernetes-sigs/descheduler/) using the official [Helm Chart](https://github.com/kubernetes-sigs/descheduler/tree/master/charts/descheduler) in a Kubernetes cluster. +In this module, we have created simple Terraform variables to easily configure some features of the Descheduler. For example, you can filter the monitored nodes by labels, using the most used syntax for selector labels and you can turn on/off the low node utilization strategy. For the full list of available variables, please check the [Inputs](#inputs) section below. + ## Providers @@ -22,6 +24,7 @@ This module installs [Descheduler](https://github.com/kubernetes-sigs/deschedule | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| +| [additional\_values](#input\_additional\_values) | Additional values to pass to the helm chart. | `list(string)` | `[]` | no | | [chart\_version](#input\_chart\_version) | Chart version to install. | `string` | `"0.29.0"` | no | | [create\_namespace](#input\_create\_namespace) | Create namespace for the ingress controller. If false, the namespace must be created before using this module. | `bool` | `true` | no | | [helm\_release\_name](#input\_helm\_release\_name) | Name of the helm release. | `string` | `"descheduler"` | no | @@ -30,6 +33,8 @@ This module installs [Descheduler](https://github.com/kubernetes-sigs/deschedule | [low\_node\_utilization\_enabled](#input\_low\_node\_utilization\_enabled) | Enable low node utilization descheduler strategy. | `bool` | `true` | no | | [namespace](#input\_namespace) | Namespace to install the descheduler. | `string` | `"descheduler"` | no | | [node\_selector\_labels](#input\_node\_selector\_labels) | Node selector labels used by descheduler for limit pod eviction in selected nodes. | `map(string)` | `{}` | no | +| [service\_monitor\_enabled](#input\_service\_monitor\_enabled) | Enable Prometheus service monitor. | `bool` | `false` | no | +| [service\_monitor\_namespace](#input\_service\_monitor\_namespace) | Service monitor namespace. | `string` | `""` | no | ## Outputs diff --git a/files/values.yaml.tftpl b/files/values.yaml.tftpl index e39ad74..9bbb66f 100644 --- a/files/values.yaml.tftpl +++ b/files/values.yaml.tftpl @@ -14,3 +14,9 @@ deschedulerPolicy: strategies: LowNodeUtilization: enabled: ${low_node_utilization_enabled} + +%{~ if service_monitor_enabled } +serviceMonitor: + enabled: ${service_monitor_enabled} + namespace: "${service_monitor_namespace}" +%{~ endif ~} diff --git a/main.tf b/main.tf index 8751994..3e4da16 100644 --- a/main.tf +++ b/main.tf @@ -4,8 +4,7 @@ locals { var.k8s_additional_labels, ) - final_namespace = var.create_namespace ? resource.kubernetes_namespace_v1.this[0].metadata[0].name : data.kubernetes_namespace_v1.this[0].metadata[0].name - + final_namespace = var.create_namespace ? resource.kubernetes_namespace_v1.this[0].metadata[0].name : data.kubernetes_namespace_v1.this[0].metadata[0].name node_selector_labels_string = var.node_selector_labels == null ? "" : join(",", [for k, v in var.node_selector_labels : "${k}=${v}"]) } @@ -15,8 +14,8 @@ resource "kubernetes_namespace_v1" "this" { metadata { name = var.namespace labels = merge( - local.k8s_full_labels, { name = var.namespace }, + local.k8s_full_labels, ) } } @@ -36,14 +35,19 @@ resource "helm_release" "this" { version = var.chart_version namespace = local.final_namespace - values = [ - templatefile( - "${path.module}/files/values.yaml.tftpl", - { - common_labels = local.k8s_full_labels - node_selector_labels_string = local.node_selector_labels_string - low_node_utilization_enabled = var.low_node_utilization_enabled - } - ), - ] + values = concat( + [ + templatefile( + "${path.module}/files/values.yaml.tftpl", + { + common_labels = local.k8s_full_labels + node_selector_labels_string = local.node_selector_labels_string + low_node_utilization_enabled = var.low_node_utilization_enabled + service_monitor_enabled = var.service_monitor_enabled + service_monitor_namespace = var.service_monitor_namespace + } + ), + ], + var.additional_values + ) } diff --git a/variables.tf b/variables.tf index 77c9d06..b5bc83f 100644 --- a/variables.tf +++ b/variables.tf @@ -1,15 +1,15 @@ -variable "namespace" { - description = "Namespace to install the descheduler." - type = string - default = "descheduler" -} - variable "create_namespace" { description = "Create namespace for the ingress controller. If false, the namespace must be created before using this module." type = bool default = true } +variable "namespace" { + description = "Namespace to install the descheduler." + type = string + default = "descheduler" +} + variable "helm_release_name" { description = "Name of the helm release." type = string @@ -22,6 +22,12 @@ variable "chart_version" { default = "0.29.0" } +variable "additional_values" { + description = "Additional values to pass to the helm chart." + type = list(string) + default = [] +} + variable "k8s_labels" { description = "Set of labels to apply to all resources." type = map(string) @@ -47,3 +53,15 @@ variable "low_node_utilization_enabled" { type = bool default = true } + +variable "service_monitor_enabled" { + description = "Enable Prometheus service monitor." + type = bool + default = false +} + +variable "service_monitor_namespace" { + description = "Service monitor namespace." + type = string + default = "" +}