Skip to content

Commit

Permalink
feat: add automatic filesystem trim feature using recurringjob
Browse files Browse the repository at this point in the history
  • Loading branch information
hbollon committed Jan 24, 2024
1 parent 797e42e commit a05fe57
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
6 changes: 6 additions & 0 deletions charts/longhorn/templates/backup-storageclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ parameters:
numberOfReplicas: {{ $.Values.numberOfReplicas | quote }}
staleReplicaTimeout: "30"
fromBackup: ""
{{- if $.Values.recurringJobSelector }}
recurringJobSelector:
{{- with $.Values.recurringJobSelector }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
recurringJobs: '[
{{- if $.Values.backups.config.snapshot_enabled }}
{
Expand Down
24 changes: 24 additions & 0 deletions charts/longhorn/templates/recurring-job-filesystem-trim.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{- if $.Values.automaticFilesystemTrim.enabled -}}

---
apiVersion: longhorn.io/v1beta2
kind: RecurringJob
metadata:
name: {{ $.Release.Name }}-filesystem-trim
labels:
name: {{ $.Release.Name }}-filesystem-trim
spec:
concurrency: 1
cron: {{ $.Values.automaticFilesystemTrim.cron | quote }}
{{- if and ($.Values.automaticFilesystemTrim.jobGroup) (ne $.Values.automaticFilesystemTrim.jobGroup "") }}
groups:
- {{ $.Values.automaticFilesystemTrim.jobGroup | quote }}
{{- else }}
groups: []
{{- end }}
labels: {}
name: fs-trim
retain: 0
task: filesystem-trim

{{- end -}}
4 changes: 4 additions & 0 deletions charts/longhorn/values.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
---
automaticFilesystemTrim:
enabled: false
cron: 0 6 * * *
recurringJobSelector: ""
10 changes: 10 additions & 0 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ locals {
persistence = {
defaultClass = var.enable_pv_backups && var.set_default_storage_class ? "false" : "true"
defaultClassReplicaCount = var.replica_count
recurringJobSelector = {
enable = var.automatic_filesystem_trim.enabled && !var.set_default_storage_class ? "true" : "false"
jobList = var.automatic_filesystem_trim.enabled && !var.set_default_storage_class ? var.recurring_job_selectors : null
}
}
longhornManager = {
tolerations = var.tolerations
Expand Down Expand Up @@ -63,6 +67,12 @@ locals {
servicemonitor = {
enabled = var.enable_service_monitor
}
automaticFilesystemTrim = {
enabled = var.automatic_filesystem_trim.enabled
cron = var.automatic_filesystem_trim.cron
job_group = var.automatic_filesystem_trim.job_group
}
recurringJobSelector = var.automatic_filesystem_trim.enabled && var.enable_pv_backups && var.set_default_storage_class ? var.recurring_job_selectors : null
}]
}

Expand Down
20 changes: 20 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,26 @@ variable "oidc" {
default = null
}

variable "automatic_filesystem_trim" {
description = "Settings to enable and configure automatic filesystem trim of volumes managed by Longhorn."
type = object({
enabled = bool
cron = string
job_group = string
})
default = {
enabled = false
cron = "0 6 * * *"
job_group = ""
}
}

variable "recurring_job_selectors" {
description = "Define a group list to add to recurring job selector for the default storageclass (the custom backup one if `set_default_storage_class` is set or else the Longhorn default one)"
type = string
default = ""
}

variable "replica_count" {
description = "Amount of replicas created by Longhorn for each volume."
type = number
Expand Down

0 comments on commit a05fe57

Please sign in to comment.