Skip to content

Commit

Permalink
feat: add variable to set resources with default values
Browse files Browse the repository at this point in the history
Having default values is good practice to prevent that our components could eventually starve other workloads on the cluster. However, these should probably be adapted in production clusters and are only a safeguard in case someone forgets to set them.
  • Loading branch information
lentidas committed Apr 3, 2024
1 parent d28653f commit afcef52
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 3 deletions.
2 changes: 2 additions & 0 deletions aks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ module "thanos" {
app_autosync = var.app_autosync
dependency_ids = var.dependency_ids

resources = var.resources

thanos = var.thanos

helm_values = concat(local.helm_values, var.helm_values)
Expand Down
2 changes: 2 additions & 0 deletions eks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module "thanos" {
app_autosync = var.app_autosync
dependency_ids = var.dependency_ids

resources = var.resources

thanos = var.thanos

helm_values = concat(local.helm_values, var.helm_values)
Expand Down
2 changes: 2 additions & 0 deletions kind/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module "thanos" {
app_autosync = var.app_autosync
dependency_ids = var.dependency_ids

resources = var.resources

thanos = var.thanos

helm_values = concat(local.helm_values, var.helm_values)
Expand Down
27 changes: 24 additions & 3 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ locals {
persistence = {
enabled = false
}
resources = {
requests = { for k, v in var.resources.redis.requests : k => v if v != null }
limits = { for k, v in var.resources.redis.limits : k => v if v != null }
}
}
}
thanos = {
Expand All @@ -35,7 +39,10 @@ locals {
persistence = {
enabled = false
}
resources = local.thanos.storegateway_resources
resources = {
requests = { for k, v in var.resources.storegateway.requests : k => v if v != null }
limits = { for k, v in var.resources.storegateway.limits : k => v if v != null }
}
networkPolicy = {
enabled = false
}
Expand Down Expand Up @@ -72,7 +79,10 @@ locals {
stores = [
"thanos-storegateway:10901"
]
resources = local.thanos.query_resources
resources = {
requests = { for k, v in var.resources.query.requests : k => v if v != null }
limits = { for k, v in var.resources.query.limits : k => v if v != null }
}
networkPolicy = {
enabled = false
}
Expand All @@ -83,7 +93,10 @@ locals {
retentionResolutionRaw = "${local.thanos.compactor_retention.raw}"
retentionResolution5m = "${local.thanos.compactor_retention.five_min}"
retentionResolution1h = "${local.thanos.compactor_retention.one_hour}"
resources = local.thanos.compactor_resources
resources = {
requests = { for k, v in var.resources.compactor.requests : k => v if v != null }
limits = { for k, v in var.resources.compactor.limits : k => v if v != null }
}
persistence = {
# The Access Mode needs to be set as ReadWriteOnce because AWS Elastic Block storage does not support other
# modes (https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes).
Expand All @@ -101,6 +114,10 @@ locals {

bucketweb = {
enabled = true
resources = {
requests = { for k, v in var.resources.bucketweb.requests : k => v if v != null }
limits = { for k, v in var.resources.bucketweb.limits : k => v if v != null }
}
sidecars = [{
args = concat([
"--http-address=0.0.0.0:9075",
Expand Down Expand Up @@ -188,6 +205,10 @@ locals {
}

queryFrontend = {
resources = {
requests = { for k, v in var.resources.query_frontend.requests : k => v if v != null }
limits = { for k, v in var.resources.query_frontend.limits : k => v if v != null }
}
extraFlags = [
# Query Frontend response cache config -> https://thanos.io/tip/components/query-frontend.md/#caching
<<-EOT
Expand Down
2 changes: 2 additions & 0 deletions sks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module "thanos" {
app_autosync = var.app_autosync
dependency_ids = var.dependency_ids

resources = var.resources

thanos = var.thanos

helm_values = concat(local.helm_values, var.helm_values)
Expand Down
78 changes: 78 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,84 @@ variable "thanos" {
default = {}
}

variable "resources" {
description = <<-EOT
Resource limits and requests for Thanos' components. Follow the style on https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/[official documentation] to understand the format of the values.
IMPORTANT: These are not production values. You should always adjust them to your needs.
EOT
type = object({

query = optional(object({
requests = optional(object({
cpu = optional(string, "250m")
memory = optional(string, "512Mi")
}), {})
limits = optional(object({
cpu = optional(string)
memory = optional(string, "512Mi")
}), {})
}), {})

query_frontend = optional(object({
requests = optional(object({
cpu = optional(string, "250m")
memory = optional(string, "256Mi")
}), {})
limits = optional(object({
cpu = optional(string)
memory = optional(string, "512Mi")
}), {})
}), {})

bucketweb = optional(object({
requests = optional(object({
cpu = optional(string, "50m")
memory = optional(string, "128Mi")
}), {})
limits = optional(object({
cpu = optional(string)
memory = optional(string, "128Mi")
}), {})
}), {})

compactor = optional(object({
requests = optional(object({
cpu = optional(string, "250m")
memory = optional(string, "256Mi")
}), {})
limits = optional(object({
cpu = optional(string)
memory = optional(string, "512Mi")
}), {})
}), {})

storegateway = optional(object({
requests = optional(object({
cpu = optional(string, "250m")
memory = optional(string, "512Mi")
}), {})
limits = optional(object({
cpu = optional(string)
memory = optional(string, "512Mi")
}), {})
}), {})

redis = optional(object({
requests = optional(object({
cpu = optional(string, "200m")
memory = optional(string, "256Mi")
}), {})
limits = optional(object({
cpu = optional(string)
memory = optional(string, "512Mi")
}), {})
}), {})

})
default = {}
}

variable "enable_service_monitor" {
description = "Boolean to enable the deployment of a service monitor for Prometheus. This also enables the deployment of default Prometheus rules and Grafana dashboards, which are embedded inside the chart templates and are taken from the official Thanos examples, available https://github.com/thanos-io/thanos/blob/main/examples/alerts/alerts.yaml[here]."
type = bool
Expand Down

0 comments on commit afcef52

Please sign in to comment.