From bf44eefd50b9ae32a47d27312572a0e84a0139f2 Mon Sep 17 00:00:00 2001 From: SK Ali Arman Date: Mon, 4 Mar 2024 15:47:12 +0600 Subject: [PATCH] Add MariaDB Addon for Backup and Restore with Restic (#876) Signed-off-by: SK Ali Arman Signed-off-by: hmsayem Co-authored-by: hmsayem --- .../kubedb_kubestash_catalog_types.go | 16 +++ .../v1alpha1/zz_generated.deepcopy.go | 51 ++++++++ .../kubestash/raw/mariadb/mariadb-addon.yaml | 102 ++++++++++++++++ .../raw/mariadb/mariadb-backup-function.yaml | 15 +++ .../raw/mariadb/mariadb-restore-function.yaml | 16 +++ charts/kubedb-kubestash-catalog/README.md | 2 + .../templates/mariadb/mariadb-addon.yaml | 111 ++++++++++++++++++ .../templates/mariadb/mariadb-backup.yaml | 24 ++++ .../templates/mariadb/mariadb-restore.yaml | 25 ++++ .../values.openapiv3_schema.yaml | 17 +++ charts/kubedb-kubestash-catalog/values.yaml | 8 ++ charts/kubedb/values.openapiv3_schema.yaml | 17 +++ 12 files changed, 404 insertions(+) create mode 100644 catalog/kubestash/raw/mariadb/mariadb-addon.yaml create mode 100644 catalog/kubestash/raw/mariadb/mariadb-backup-function.yaml create mode 100644 catalog/kubestash/raw/mariadb/mariadb-restore-function.yaml create mode 100644 charts/kubedb-kubestash-catalog/templates/mariadb/mariadb-addon.yaml create mode 100644 charts/kubedb-kubestash-catalog/templates/mariadb/mariadb-backup.yaml create mode 100644 charts/kubedb-kubestash-catalog/templates/mariadb/mariadb-restore.yaml diff --git a/apis/installer/v1alpha1/kubedb_kubestash_catalog_types.go b/apis/installer/v1alpha1/kubedb_kubestash_catalog_types.go index 2fe203222..549b923b3 100644 --- a/apis/installer/v1alpha1/kubedb_kubestash_catalog_types.go +++ b/apis/installer/v1alpha1/kubedb_kubestash_catalog_types.go @@ -52,6 +52,7 @@ type KubedbKubestashCatalogSpec struct { Kubedbmanifest StashKubedbmanifestSpec `json:"kubedbmanifest"` Mongodb StashMongodbSpec `json:"mongodb"` Mysql StashMysqlSpec `json:"mysql"` + Mariadb StashMariadbSpec `json:"mariadb"` Redis StashRedisSpec `json:"redis"` Postgres StashPostgresSpec `json:"postgres"` } @@ -136,6 +137,21 @@ type MySQLRestore struct { Args string `json:"args"` } +type StashMariadbSpec struct { + Backup MariaDBBackup `json:"backup"` + Restore MariaDBRestore `json:"restore"` +} + +type MariaDBBackup struct { + // +optional + Args string `json:"args"` +} + +type MariaDBRestore struct { + // +optional + Args string `json:"args"` +} + // StashRedisSpec is the schema for Stash Redis values file type StashRedisSpec struct { Backup RedisBackup `json:"backup"` diff --git a/apis/installer/v1alpha1/zz_generated.deepcopy.go b/apis/installer/v1alpha1/zz_generated.deepcopy.go index 83173c521..80844ff76 100644 --- a/apis/installer/v1alpha1/zz_generated.deepcopy.go +++ b/apis/installer/v1alpha1/zz_generated.deepcopy.go @@ -937,6 +937,7 @@ func (in *KubedbKubestashCatalogSpec) DeepCopyInto(out *KubedbKubestashCatalogSp out.Kubedbmanifest = in.Kubedbmanifest out.Mongodb = in.Mongodb out.Mysql = in.Mysql + out.Mariadb = in.Mariadb out.Redis = in.Redis out.Postgres = in.Postgres return @@ -2133,6 +2134,38 @@ func (in *KubedbWebhookServerValues) DeepCopy() *KubedbWebhookServerValues { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MariaDBBackup) DeepCopyInto(out *MariaDBBackup) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MariaDBBackup. +func (in *MariaDBBackup) DeepCopy() *MariaDBBackup { + if in == nil { + return nil + } + out := new(MariaDBBackup) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MariaDBRestore) DeepCopyInto(out *MariaDBRestore) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MariaDBRestore. +func (in *MariaDBRestore) DeepCopy() *MariaDBRestore { + if in == nil { + return nil + } + out := new(MariaDBRestore) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MongoDBBackup) DeepCopyInto(out *MongoDBBackup) { *out = *in @@ -2905,6 +2938,24 @@ func (in *StashKubedbmanifestSpec) DeepCopy() *StashKubedbmanifestSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *StashMariadbSpec) DeepCopyInto(out *StashMariadbSpec) { + *out = *in + out.Backup = in.Backup + out.Restore = in.Restore + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StashMariadbSpec. +func (in *StashMariadbSpec) DeepCopy() *StashMariadbSpec { + if in == nil { + return nil + } + out := new(StashMariadbSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *StashMongodbSpec) DeepCopyInto(out *StashMongodbSpec) { *out = *in diff --git a/catalog/kubestash/raw/mariadb/mariadb-addon.yaml b/catalog/kubestash/raw/mariadb/mariadb-addon.yaml new file mode 100644 index 000000000..c488d9f18 --- /dev/null +++ b/catalog/kubestash/raw/mariadb/mariadb-addon.yaml @@ -0,0 +1,102 @@ +apiVersion: addons.kubestash.com/v1alpha1 +kind: Addon +metadata: + name: mariadb-addon +spec: + backupTasks: + - name: logical-backup + function: mariadb-backup + driver: Restic + executor: Job + singleton: true + parameters: + - name: args + usage: Arguments to be passed to the dump command. + required: false + default: "--all-databases" + - name: enableCache + usage: Enable or disable caching. Disabling caching may impact backup performance. + required: false + default: "true" + - name: scratchDir + usage: Directory for holding temporary files and restic cache. + required: false + default: /kubestash-tmp + volumeTemplate: + - name: kubestash-tmp-volume + usage: Holds temporary files and restic cache. + source: + emptyDir: { } + volumeMounts: + - name: kubestash-tmp-volume + mountPath: /kubestash-tmp + - name: manifest-backup + function: kubedbmanifest-backup + driver: Restic + executor: Job + singleton: true + parameters: + - name: enableCache + usage: Enable or disable caching. Disabling caching may impact backup performance. + required: false + default: "true" + - name: scratchDir + usage: Directory for holding temporary files and restic cache. + required: false + default: /kubestash-tmp + volumeTemplate: + - name: kubestash-tmp-volume + usage: Holds temporary files and restic cache. + source: + emptyDir: { } + volumeMounts: + - name: kubestash-tmp-volume + mountPath: /kubestash-tmp + restoreTasks: + - name: logical-backup-restore + function: mariadb-restore + driver: Restic + executor: Job + singleton: true + parameters: + - name: args + usage: Arguments to be passed to the dump command. + required: false + - name: enableCache + usage: Enable or disable caching. Disabling caching may impact backup performance. + required: false + default: "true" + - name: scratchDir + usage: Directory for holding temporary files and restic cache. + required: false + default: /kubestash-tmp + volumeTemplate: + - name: kubestash-tmp-volume + usage: Holds temporary files and restic cache. + source: + emptyDir: { } + volumeMounts: + - name: kubestash-tmp-volume + mountPath: /kubestash-tmp + - name: manifest-restore + function: kubedbmanifest-restore + driver: Restic + executor: Job + singleton: true + parameters: + - name: enableCache + usage: Enable or disable caching. Disabling caching may impact backup performance. + required: false + default: "true" + - name: scratchDir + usage: Directory for holding temporary files and restic cache. + required: false + default: /kubestash-tmp + volumeTemplate: + - name: kubestash-tmp-volume + usage: Holds temporary files and restic cache. + source: + emptyDir: { } + volumeMounts: + - name: kubestash-tmp-volume + mountPath: /kubestash-tmp \ No newline at end of file diff --git a/catalog/kubestash/raw/mariadb/mariadb-backup-function.yaml b/catalog/kubestash/raw/mariadb/mariadb-backup-function.yaml new file mode 100644 index 000000000..82d8c844f --- /dev/null +++ b/catalog/kubestash/raw/mariadb/mariadb-backup-function.yaml @@ -0,0 +1,15 @@ +apiVersion: addons.kubestash.com/v1alpha1 +kind: Function +metadata: + name: mariadb-backup +spec: + args: + - backup + - --namespace=${namespace:=default} + - --backupsession=${backupSession:=} + - --enable-cache=${enableCache:=} + - --scratch-dir=${scratchDir:=} + - --wait-timeout=${waitTimeout:=300} + - --mariadb-args=${args:=} + - --db-version=${dbVersion:=} + image: skaliarman/mariadb-restic-plugin:restic-backup_linux_amd64test12 diff --git a/catalog/kubestash/raw/mariadb/mariadb-restore-function.yaml b/catalog/kubestash/raw/mariadb/mariadb-restore-function.yaml new file mode 100644 index 000000000..602cbdd27 --- /dev/null +++ b/catalog/kubestash/raw/mariadb/mariadb-restore-function.yaml @@ -0,0 +1,16 @@ +apiVersion: addons.kubestash.com/v1alpha1 +kind: Function +metadata: + name: mariadb-restore +spec: + args: + - restore + - --namespace=${namespace:=default} + - --restoresession=${restoreSession:=} + - --snapshot=${snapshot:=} + - --enable-cache=${enableCache:=} + - --scratch-dir=${scratchDir:=} + - --wait-timeout=${waitTimeout:=300} + - --mariadb-args=${args:=} + - --db-version=${dbVersion:=} + image: skaliarman/mariadb-restic-plugin:restic-backup_linux_amd64test12 diff --git a/charts/kubedb-kubestash-catalog/README.md b/charts/kubedb-kubestash-catalog/README.md index 1f7e0091a..949778997 100644 --- a/charts/kubedb-kubestash-catalog/README.md +++ b/charts/kubedb-kubestash-catalog/README.md @@ -85,6 +85,8 @@ The following table lists the configurable parameters of the `kubedb-kubestash-c | postgres.restore.args | Arguments to pass to `psql` command during restore process | "" | | mysql.backup.args | Arguments to pass to `mysqldump` command during bakcup process | "" | | mysql.restore.args | Arguments to pass to `mysql` command during restore process | "" | +| mariadb.backup.args | Arguments to pass to `mariadb-dump` command during bakcup process | "" | +| mariadb.restore.args | Arguments to pass to `mariadb` command during restore process | "" | | redis.backup.args | Arguments to pass to `redis-dump` command during bakcup process | "" | | redis.restore.args | Arguments to pass to `redis` command during restore process | "" | diff --git a/charts/kubedb-kubestash-catalog/templates/mariadb/mariadb-addon.yaml b/charts/kubedb-kubestash-catalog/templates/mariadb/mariadb-addon.yaml new file mode 100644 index 000000000..76c6cb523 --- /dev/null +++ b/charts/kubedb-kubestash-catalog/templates/mariadb/mariadb-addon.yaml @@ -0,0 +1,111 @@ +{{ $featureGates := .Values.featureGates }} +{{- if .Values.global }} + {{ $featureGates = mergeOverwrite dict .Values.featureGates .Values.global.featureGates }} +{{- end }} + +{{ if $featureGates.MariaDB }} +apiVersion: addons.kubestash.com/v1alpha1 +kind: Addon +metadata: + name: 'mariadb-addon' + labels: + {{- include "kubedb-kubestash-catalog.labels" . | nindent 4 }} +spec: + backupTasks: + - driver: Restic + executor: Job + function: mariadb-backup + name: logical-backup + parameters: + - default: --all-databases + name: args + required: false + usage: Arguments to be passed to the dump command. + - default: "true" + name: enableCache + required: false + usage: Enable or disable caching. Disabling caching may impact backup performance. + - default: /kubestash-tmp + name: scratchDir + required: false + usage: Directory for holding temporary files and restic cache. + singleton: true + volumeMounts: + - mountPath: /kubestash-tmp + name: kubestash-tmp-volume + volumeTemplate: + - name: kubestash-tmp-volume + source: + emptyDir: {} + usage: Holds temporary files and restic cache. + - driver: Restic + executor: Job + function: kubedbmanifest-backup + name: manifest-backup + parameters: + - default: "true" + name: enableCache + required: false + usage: Enable or disable caching. Disabling caching may impact backup performance. + - default: /kubestash-tmp + name: scratchDir + required: false + usage: Directory for holding temporary files and restic cache. + singleton: true + volumeMounts: + - mountPath: /kubestash-tmp + name: kubestash-tmp-volume + volumeTemplate: + - name: kubestash-tmp-volume + source: + emptyDir: {} + usage: Holds temporary files and restic cache. + restoreTasks: + - driver: Restic + executor: Job + function: mariadb-restore + name: logical-backup-restore + parameters: + - name: args + required: false + usage: Arguments to be passed to the dump command. + - default: "true" + name: enableCache + required: false + usage: Enable or disable caching. Disabling caching may impact backup performance. + - default: /kubestash-tmp + name: scratchDir + required: false + usage: Directory for holding temporary files and restic cache. + singleton: true + volumeMounts: + - mountPath: /kubestash-tmp + name: kubestash-tmp-volume + volumeTemplate: + - name: kubestash-tmp-volume + source: + emptyDir: {} + usage: Holds temporary files and restic cache. + - driver: Restic + executor: Job + function: kubedbmanifest-restore + name: manifest-restore + parameters: + - default: "true" + name: enableCache + required: false + usage: Enable or disable caching. Disabling caching may impact backup performance. + - default: /kubestash-tmp + name: scratchDir + required: false + usage: Directory for holding temporary files and restic cache. + singleton: true + volumeMounts: + - mountPath: /kubestash-tmp + name: kubestash-tmp-volume + volumeTemplate: + - name: kubestash-tmp-volume + source: + emptyDir: {} + usage: Holds temporary files and restic cache. +{{ end }} diff --git a/charts/kubedb-kubestash-catalog/templates/mariadb/mariadb-backup.yaml b/charts/kubedb-kubestash-catalog/templates/mariadb/mariadb-backup.yaml new file mode 100644 index 000000000..f233a0171 --- /dev/null +++ b/charts/kubedb-kubestash-catalog/templates/mariadb/mariadb-backup.yaml @@ -0,0 +1,24 @@ +{{ $featureGates := .Values.featureGates }} +{{- if .Values.global }} + {{ $featureGates = mergeOverwrite dict .Values.featureGates .Values.global.featureGates }} +{{- end }} + +{{ if $featureGates.MariaDB }} +apiVersion: addons.kubestash.com/v1alpha1 +kind: Function +metadata: + name: 'mariadb-backup' + labels: + {{- include "kubedb-kubestash-catalog.labels" . | nindent 4 }} +spec: + args: + - backup + - --namespace=${namespace:=default} + - --backupsession=${backupSession:=} + - --enable-cache=${enableCache:=} + - --scratch-dir=${scratchDir:=} + - --wait-timeout=${waitTimeout:={{ .Values.waitTimeout}}} + - --mariadb-args=${args:={{ .Values.mariadb.args }}} + - --db-version=${dbVersion:=} + image: '{{ include "image.dockerHub" (merge (dict "_repo" "skaliarman/mariadb-restic-plugin") $) }}:restic-backup_linux_amd64test12' +{{ end }} diff --git a/charts/kubedb-kubestash-catalog/templates/mariadb/mariadb-restore.yaml b/charts/kubedb-kubestash-catalog/templates/mariadb/mariadb-restore.yaml new file mode 100644 index 000000000..5e0540c12 --- /dev/null +++ b/charts/kubedb-kubestash-catalog/templates/mariadb/mariadb-restore.yaml @@ -0,0 +1,25 @@ +{{ $featureGates := .Values.featureGates }} +{{- if .Values.global }} + {{ $featureGates = mergeOverwrite dict .Values.featureGates .Values.global.featureGates }} +{{- end }} + +{{ if $featureGates.MariaDB }} +apiVersion: addons.kubestash.com/v1alpha1 +kind: Function +metadata: + name: 'mariadb-restore' + labels: + {{- include "kubedb-kubestash-catalog.labels" . | nindent 4 }} +spec: + args: + - restore + - --namespace=${namespace:=default} + - --restoresession=${restoreSession:=} + - --snapshot=${snapshot:=} + - --enable-cache=${enableCache:=} + - --scratch-dir=${scratchDir:=} + - --wait-timeout=${waitTimeout:={{ .Values.waitTimeout}}} + - --mariadb-args=${args:={{ .Values.mariadb.args }}} + - --db-version=${dbVersion:=} + image: '{{ include "image.dockerHub" (merge (dict "_repo" "skaliarman/mariadb-restic-plugin") $) }}:restic-backup_linux_amd64test12' +{{ end }} diff --git a/charts/kubedb-kubestash-catalog/values.openapiv3_schema.yaml b/charts/kubedb-kubestash-catalog/values.openapiv3_schema.yaml index cb1c08d0b..44765dce2 100644 --- a/charts/kubedb-kubestash-catalog/values.openapiv3_schema.yaml +++ b/charts/kubedb-kubestash-catalog/values.openapiv3_schema.yaml @@ -28,6 +28,22 @@ properties: required: - enabled type: object + mariadb: + properties: + backup: + properties: + args: + type: string + type: object + restore: + properties: + args: + type: string + type: object + required: + - backup + - restore + type: object mongodb: description: StashMongodbSpec is the schema for Stash MongoDB values file properties: @@ -144,6 +160,7 @@ required: - elasticsearch - featureGates - kubedbmanifest +- mariadb - mongodb - mysql - opensearch diff --git a/charts/kubedb-kubestash-catalog/values.yaml b/charts/kubedb-kubestash-catalog/values.yaml index 7f8184acd..b5c9657e0 100644 --- a/charts/kubedb-kubestash-catalog/values.yaml +++ b/charts/kubedb-kubestash-catalog/values.yaml @@ -88,6 +88,14 @@ mysql: restore: # Arguments to pass to `mysql` command during restore process args: "" +mariadb: + # optional argument to send mariadb-dump or mariadb command + backup: + # Arguments to pass to `mariadb-dump` command during bakcup process + args: "" + restore: + # Arguments to pass to `mariadb` command during restore process + args: "" redis: # optional argument to send redis-dump or redis command backup: diff --git a/charts/kubedb/values.openapiv3_schema.yaml b/charts/kubedb/values.openapiv3_schema.yaml index f05bf996b..2f5fbf67f 100644 --- a/charts/kubedb/values.openapiv3_schema.yaml +++ b/charts/kubedb/values.openapiv3_schema.yaml @@ -3081,6 +3081,22 @@ properties: required: - enabled type: object + mariadb: + properties: + backup: + properties: + args: + type: string + type: object + restore: + properties: + args: + type: string + type: object + required: + - backup + - restore + type: object mongodb: description: StashMongodbSpec is the schema for Stash MongoDB values file properties: @@ -3199,6 +3215,7 @@ properties: - enabled - featureGates - kubedbmanifest + - mariadb - mongodb - mysql - opensearch