Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add automatic filesystem trim feature using recurringjob #22

Merged
merged 2 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 82 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ Description: Override of target revision of the application chart.

Type: `string`

Default: `"v3.0.0"`
Default: `"v3.1.0"`

==== [[input_helm_values]] <<input_helm_values,helm_values>>

Expand Down Expand Up @@ -473,6 +473,45 @@ object({

Default: `null`

==== [[input_automatic_filesystem_trim]] <<input_automatic_filesystem_trim,automatic_filesystem_trim>>

Description: Settings to enable and configure automatic filesystem trim of volumes managed by Longhorn.

Type:
[source,hcl]
----
object({
enabled = bool
cron = string
job_group = string
})
----

Default:
[source,json]
----
{
"cron": "0 6 * * *",
"enabled": false,
"job_group": ""
}
----

==== [[input_recurring_job_selectors]] <<input_recurring_job_selectors,recurring_job_selectors>>

Description: Define a group list to add to recurring job selector for the default storage class (the custom backup one if `set_default_storage_class` is set or else the Longhorn default one).

Type:
[source,hcl]
----
list(object({
name = string
isGroup = bool
}))
----

Default: `null`

==== [[input_replica_count]] <<input_replica_count,replica_count>>

Description: Amount of replicas created by Longhorn for each volume.
Expand Down Expand Up @@ -595,7 +634,7 @@ Description: ID to pass other modules in order to refer to this module as a depe
|[[input_target_revision]] <<input_target_revision,target_revision>>
|Override of target revision of the application chart.
|`string`
|`"v3.0.0"`
|`"v3.1.0"`
|no

|[[input_helm_values]] <<input_helm_values,helm_values>>
Expand Down Expand Up @@ -763,6 +802,47 @@ object({
|`null`
|no

|[[input_automatic_filesystem_trim]] <<input_automatic_filesystem_trim,automatic_filesystem_trim>>
|Settings to enable and configure automatic filesystem trim of volumes managed by Longhorn.
|

[source]
----
object({
enabled = bool
cron = string
job_group = string
})
----

|

[source]
----
{
"cron": "0 6 * * *",
"enabled": false,
"job_group": ""
}
----

|no

|[[input_recurring_job_selectors]] <<input_recurring_job_selectors,recurring_job_selectors>>
|Define a group list to add to recurring job selector for the default storage class (the custom backup one if `set_default_storage_class` is set or else the Longhorn default one).
|

[source]
----
list(object({
name = string
isGroup = bool
}))
----

|`null`
|no

|[[input_replica_count]] <<input_replica_count,replica_count>>
|Amount of replicas created by Longhorn for each volume.
|`number`
Expand Down
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 -}}
16 changes: 13 additions & 3 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ locals {
domain = format("longhorn.apps.%s", var.base_domain)
domain_full = format("longhorn.apps.%s.%s", var.cluster_name, var.base_domain)

# Generate a list of tolerations in a string format of `key=value:effect` for all the tolerations that have
# an `operator` equal to `Equal`. This list of strings will be joined to pass as the value of
# Generate a list of tolerations in a string format of `key=value:effect` for all the tolerations that have
# an `operator` equal to `Equal`. This list of strings will be joined to pass as the value of
# `defaultSettings.taintToleration`.
tolerations_list = [for toleration in var.tolerations : "${toleration.key}=${toleration.value}:${toleration.effect}" if toleration.operator == "Equal"]

Expand All @@ -18,8 +18,12 @@ locals {
taintToleration = join(";", local.tolerations_list)
}
persistence = {
defaultClass = var.enable_pv_backups && var.set_default_storage_class ? "false" : "true"
defaultClass = tostring(var.enable_pv_backups && var.set_default_storage_class)
defaultClassReplicaCount = var.replica_count
recurringJobSelector = {
enable = tostring(var.automatic_filesystem_trim.enabled && !var.set_default_storage_class)
jobList = var.automatic_filesystem_trim.enabled && !var.set_default_storage_class && var.recurring_job_selectors != null ? jsonencode(var.recurring_job_selectors) : null
}
}
longhornManager = {
tolerations = var.tolerations
Expand Down Expand Up @@ -66,6 +70,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 ? jsonencode(var.recurring_job_selectors) : null
}]
}

Expand Down
23 changes: 23 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,29 @@ 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 storage class (the custom backup one if `set_default_storage_class` is set or else the Longhorn default one)."
type = list(object({
name = string
isGroup = bool
}))
default = null
}

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