Skip to content

Commit

Permalink
feat: add ServiceMonitor toggle and additional_values variable to cus…
Browse files Browse the repository at this point in the history
…tomize Helm values
  • Loading branch information
Monska85 committed May 16, 2024
1 parent e925fee commit f0b0722
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 19 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<!-- BEGIN_TF_DOCS -->
## Providers

Expand All @@ -22,6 +24,7 @@ This module installs [Descheduler](https://github.com/kubernetes-sigs/deschedule

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_additional_values"></a> [additional\_values](#input\_additional\_values) | Additional values to pass to the helm chart. | `list(string)` | `[]` | no |
| <a name="input_chart_version"></a> [chart\_version](#input\_chart\_version) | Chart version to install. | `string` | `"0.29.0"` | no |
| <a name="input_create_namespace"></a> [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 |
| <a name="input_helm_release_name"></a> [helm\_release\_name](#input\_helm\_release\_name) | Name of the helm release. | `string` | `"descheduler"` | no |
Expand All @@ -30,6 +33,8 @@ This module installs [Descheduler](https://github.com/kubernetes-sigs/deschedule
| <a name="input_low_node_utilization_enabled"></a> [low\_node\_utilization\_enabled](#input\_low\_node\_utilization\_enabled) | Enable low node utilization descheduler strategy. | `bool` | `true` | no |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Namespace to install the descheduler. | `string` | `"descheduler"` | no |
| <a name="input_node_selector_labels"></a> [node\_selector\_labels](#input\_node\_selector\_labels) | Node selector labels used by descheduler for limit pod eviction in selected nodes. | `map(string)` | `{}` | no |
| <a name="input_service_monitor_enabled"></a> [service\_monitor\_enabled](#input\_service\_monitor\_enabled) | Enable Prometheus service monitor. | `bool` | `false` | no |
| <a name="input_service_monitor_namespace"></a> [service\_monitor\_namespace](#input\_service\_monitor\_namespace) | Service monitor namespace. | `string` | `""` | no |

## Outputs

Expand Down
6 changes: 6 additions & 0 deletions files/values.yaml.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ~}
30 changes: 17 additions & 13 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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}"])
}

Expand All @@ -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,
)
}
}
Expand All @@ -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
)
}
30 changes: 24 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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 = ""
}

0 comments on commit f0b0722

Please sign in to comment.