From 37eec6794a2ead48b83c0b5b8e7859eec7b3f05e Mon Sep 17 00:00:00 2001 From: Hossain Mahmud Date: Wed, 1 Sep 2021 19:18:18 +0600 Subject: [PATCH] Add catalogs for NATS addon (#196) * update catalog Signed-off-by: hmsayem * Add overwrite flag Signed-off-by: hmsayem * Update image Signed-off-by: hmsayem * Fix build + run generator Signed-off-by: hossainemruz * Fix tests Signed-off-by: hossainemruz * Regen charts Signed-off-by: hossainemruz Co-authored-by: hossainemruz --- .../installer/v1alpha1/stash_catalog_types.go | 24 +++++++ .../v1alpha1/zz_generated.deepcopy.go | 65 ++++++++++++++++++- catalog/catalog.json | 6 ++ .../raw/nats/2.4.0/nats-backup-function.yaml | 39 +++++++++++ catalog/raw/nats/2.4.0/nats-backup-task.yaml | 22 +++++++ .../raw/nats/2.4.0/nats-restore-function.yaml | 32 +++++++++ catalog/raw/nats/2.4.0/nats-restore-task.yaml | 22 +++++++ charts/stash-catalog/README.md | 6 ++ .../nats/2.4.0/nats-backup-function.yaml | 43 ++++++++++++ .../nats/2.4.0/nats-backup-task.yaml | 26 ++++++++ .../nats/2.4.0/nats-restore-function.yaml | 36 ++++++++++ .../nats/2.4.0/nats-restore-task.yaml | 26 ++++++++ .../values.openapiv3_schema.yaml | 31 +++++++++ charts/stash-catalog/values.yaml | 16 +++++ charts/stash/values.openapiv3_schema.yaml | 31 +++++++++ 15 files changed, 423 insertions(+), 2 deletions(-) create mode 100644 catalog/raw/nats/2.4.0/nats-backup-function.yaml create mode 100644 catalog/raw/nats/2.4.0/nats-backup-task.yaml create mode 100644 catalog/raw/nats/2.4.0/nats-restore-function.yaml create mode 100644 catalog/raw/nats/2.4.0/nats-restore-task.yaml create mode 100644 charts/stash-catalog/templates/nats/2.4.0/nats-backup-function.yaml create mode 100644 charts/stash-catalog/templates/nats/2.4.0/nats-backup-task.yaml create mode 100644 charts/stash-catalog/templates/nats/2.4.0/nats-restore-function.yaml create mode 100644 charts/stash-catalog/templates/nats/2.4.0/nats-restore-task.yaml diff --git a/apis/installer/v1alpha1/stash_catalog_types.go b/apis/installer/v1alpha1/stash_catalog_types.go index 68314dab6..f30cc3c5b 100644 --- a/apis/installer/v1alpha1/stash_catalog_types.go +++ b/apis/installer/v1alpha1/stash_catalog_types.go @@ -53,6 +53,7 @@ type StashCatalogSpec struct { PerconaXtraDB StashPerconaXtraDBSpec `json:"perconaxtradb"` Postgres StashPostgresSpec `json:"postgres"` Redis StashRedisSpec `json:"redis"` + NATS StashNATSSpec `json:"nats"` } // StashElasticsearchSpec is the schema for Stash Elasticsearch values file @@ -180,6 +181,29 @@ type RedisRestore struct { Args string `json:"args"` } +// StashNATSSpec is the schema for Stash NATS values file +type StashNATSSpec struct { + Enabled bool `json:"enabled"` + Backup NATSBackup `json:"backup"` + Restore NATSRestore `json:"restore"` +} + +type NATSBackup struct { + // +optional + Args string `json:"args"` + // +optional + Streams []string `json:"streams"` +} + +type NATSRestore struct { + // +optional + Args string `json:"args"` + // +optional + Streams []string `json:"streams"` + // +optional + Overwrite bool `json:"overwrite"` +} + // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // StashCatalogList is a list of StashCatalogs diff --git a/apis/installer/v1alpha1/zz_generated.deepcopy.go b/apis/installer/v1alpha1/zz_generated.deepcopy.go index 7e80c2e19..ad44112bd 100644 --- a/apis/installer/v1alpha1/zz_generated.deepcopy.go +++ b/apis/installer/v1alpha1/zz_generated.deepcopy.go @@ -312,6 +312,48 @@ func (in *MySQLRestore) DeepCopy() *MySQLRestore { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NATSBackup) DeepCopyInto(out *NATSBackup) { + *out = *in + if in.Streams != nil { + in, out := &in.Streams, &out.Streams + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NATSBackup. +func (in *NATSBackup) DeepCopy() *NATSBackup { + if in == nil { + return nil + } + out := new(NATSBackup) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NATSRestore) DeepCopyInto(out *NATSRestore) { + *out = *in + if in.Streams != nil { + in, out := &in.Streams, &out.Streams + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NATSRestore. +func (in *NATSRestore) DeepCopy() *NATSRestore { + if in == nil { + return nil + } + out := new(NATSRestore) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NetVolAccessor) DeepCopyInto(out *NetVolAccessor) { *out = *in @@ -595,7 +637,7 @@ func (in *StashCatalog) DeepCopyInto(out *StashCatalog) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec + in.Spec.DeepCopyInto(&out.Spec) return } @@ -661,6 +703,7 @@ func (in *StashCatalogSpec) DeepCopyInto(out *StashCatalogSpec) { out.PerconaXtraDB = in.PerconaXtraDB out.Postgres = in.Postgres out.Redis = in.Redis + in.NATS.DeepCopyInto(&out.NATS) return } @@ -1034,6 +1077,24 @@ func (in *StashMysqlSpec) DeepCopy() *StashMysqlSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *StashNATSSpec) DeepCopyInto(out *StashNATSSpec) { + *out = *in + in.Backup.DeepCopyInto(&out.Backup) + in.Restore.DeepCopyInto(&out.Restore) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StashNATSSpec. +func (in *StashNATSSpec) DeepCopy() *StashNATSSpec { + if in == nil { + return nil + } + out := new(StashNATSSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *StashPerconaXtraDBSpec) DeepCopyInto(out *StashPerconaXtraDBSpec) { *out = *in @@ -1094,7 +1155,7 @@ func (in *StashSpec) DeepCopyInto(out *StashSpec) { in.Global.DeepCopyInto(&out.Global) out.Features = in.Features in.Community.DeepCopyInto(&out.Community) - out.Catalog = in.Catalog + in.Catalog.DeepCopyInto(&out.Catalog) in.Enterprise.DeepCopyInto(&out.Enterprise) return } diff --git a/catalog/catalog.json b/catalog/catalog.json index 2ad03edcb..6479aa33b 100644 --- a/catalog/catalog.json +++ b/catalog/catalog.json @@ -47,6 +47,12 @@ "8.0.21-v6" ] }, + { + "name": "nats", + "versions": [ + "2.4.0" + ] + }, { "name": "percona-xtradb", "versions": [ diff --git a/catalog/raw/nats/2.4.0/nats-backup-function.yaml b/catalog/raw/nats/2.4.0/nats-backup-function.yaml new file mode 100644 index 000000000..9399f88a5 --- /dev/null +++ b/catalog/raw/nats/2.4.0/nats-backup-function.yaml @@ -0,0 +1,39 @@ +apiVersion: stash.appscode.com/v1beta1 +kind: Function +metadata: + name: nats-backup-2.4.0 +spec: + args: + - backup-nats + - --provider=${REPOSITORY_PROVIDER:=} + - --bucket=${REPOSITORY_BUCKET:=} + - --endpoint=${REPOSITORY_ENDPOINT:=} + - --region=${REPOSITORY_REGION:=} + - --path=${REPOSITORY_PREFIX:=} + - --secret-dir=/etc/repository/secret + - --scratch-dir=/tmp + - --enable-cache=${ENABLE_CACHE:=true} + - --max-connections=${MAX_CONNECTIONS:=0} + - --hostname=${HOSTNAME:=} + - --interim-data-dir=${INTERIM_DATA_DIR} + - --nats-args=${args:=} + - --streams=${streams:=} + - --wait-timeout=${waitTimeout:=300} + - --namespace=${NAMESPACE:=default} + - --appbinding=${TARGET_NAME:=} + - --backupsession=${BACKUP_SESSION:=} + - --retention-keep-last=${RETENTION_KEEP_LAST:=0} + - --retention-keep-hourly=${RETENTION_KEEP_HOURLY:=0} + - --retention-keep-daily=${RETENTION_KEEP_DAILY:=0} + - --retention-keep-weekly=${RETENTION_KEEP_WEEKLY:=0} + - --retention-keep-monthly=${RETENTION_KEEP_MONTHLY:=0} + - --retention-keep-yearly=${RETENTION_KEEP_YEARLY:=0} + - --retention-keep-tags=${RETENTION_KEEP_TAGS:=} + - --retention-prune=${RETENTION_PRUNE:=false} + - --retention-dry-run=${RETENTION_DRY_RUN:=false} + - --output-dir=${outputDir:=} + - --license-apiservice=${LICENSE_APISERVICE:=} + image: stashed/stash-nats:2.4.0 + volumeMounts: + - mountPath: /etc/repository/secret + name: ${secretVolume} diff --git a/catalog/raw/nats/2.4.0/nats-backup-task.yaml b/catalog/raw/nats/2.4.0/nats-backup-task.yaml new file mode 100644 index 000000000..e74747de2 --- /dev/null +++ b/catalog/raw/nats/2.4.0/nats-backup-task.yaml @@ -0,0 +1,22 @@ +apiVersion: stash.appscode.com/v1beta1 +kind: Task +metadata: + name: nats-backup-2.4.0 +spec: + steps: + - name: nats-backup-2.4.0 + params: + - name: outputDir + value: /tmp/output + - name: secretVolume + value: secret-volume + - name: update-status + params: + - name: outputDir + value: /tmp/output + - name: secretVolume + value: secret-volume + volumes: + - name: secret-volume + secret: + secretName: ${REPOSITORY_SECRET_NAME} diff --git a/catalog/raw/nats/2.4.0/nats-restore-function.yaml b/catalog/raw/nats/2.4.0/nats-restore-function.yaml new file mode 100644 index 000000000..10db6c990 --- /dev/null +++ b/catalog/raw/nats/2.4.0/nats-restore-function.yaml @@ -0,0 +1,32 @@ +apiVersion: stash.appscode.com/v1beta1 +kind: Function +metadata: + name: nats-restore-2.4.0 +spec: + args: + - restore-nats + - --provider=${REPOSITORY_PROVIDER:=} + - --bucket=${REPOSITORY_BUCKET:=} + - --endpoint=${REPOSITORY_ENDPOINT:=} + - --region=${REPOSITORY_REGION:=} + - --path=${REPOSITORY_PREFIX:=} + - --secret-dir=/etc/repository/secret + - --scratch-dir=/tmp + - --enable-cache=${ENABLE_CACHE:=true} + - --max-connections=${MAX_CONNECTIONS:=0} + - --hostname=${HOSTNAME:=} + - --source-hostname=${SOURCE_HOSTNAME:=} + - --interim-data-dir=${INTERIM_DATA_DIR} + - --nats-args=${args:=} + - --streams=${streams:=} + - --overwrite=${overwrite:=false} + - --wait-timeout=${waitTimeout:=300} + - --namespace=${NAMESPACE:=default} + - --appbinding=${TARGET_NAME:=} + - --snapshot=${RESTORE_SNAPSHOTS:=} + - --output-dir=${outputDir:=} + - --license-apiservice=${LICENSE_APISERVICE:=} + image: stashed/stash-nats:2.4.0 + volumeMounts: + - mountPath: /etc/repository/secret + name: ${secretVolume} diff --git a/catalog/raw/nats/2.4.0/nats-restore-task.yaml b/catalog/raw/nats/2.4.0/nats-restore-task.yaml new file mode 100644 index 000000000..2407c90cd --- /dev/null +++ b/catalog/raw/nats/2.4.0/nats-restore-task.yaml @@ -0,0 +1,22 @@ +apiVersion: stash.appscode.com/v1beta1 +kind: Task +metadata: + name: nats-restore-2.4.0 +spec: + steps: + - name: nats-restore-2.4.0 + params: + - name: outputDir + value: /tmp/output + - name: secretVolume + value: secret-volume + - name: update-status + params: + - name: outputDir + value: /tmp/output + - name: secretVolume + value: secret-volume + volumes: + - name: secret-volume + secret: + secretName: ${REPOSITORY_SECRET_NAME} diff --git a/charts/stash-catalog/README.md b/charts/stash-catalog/README.md index 60f548ff1..f52a4ecee 100644 --- a/charts/stash-catalog/README.md +++ b/charts/stash-catalog/README.md @@ -74,6 +74,12 @@ The following table lists the configurable parameters of the `stash-catalog` cha | redis.enabled | If true, deploys Redis addon | `true` | | 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 | `""` | +| nats.enabled | If true, deploys NATS addon | `true` | +| nats.backup.args | Arguments to pass to `nats str backup` command during backup process | `""` | +| nats.backup.streams | List of streams to backup. Don't set this field if you want to backup all streams. | `""` | +| nats.restore.args | Arguments to pass to `nats str restore` command during restore process | `""` | +| nats.restore.streams | List of streams to restore. Don't set this field if you want to restore all the backed up streams. | `""` | +| nats.restore.overwrite | Specify whether to delete the old stream before restoring from backup. | `false` | Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example: diff --git a/charts/stash-catalog/templates/nats/2.4.0/nats-backup-function.yaml b/charts/stash-catalog/templates/nats/2.4.0/nats-backup-function.yaml new file mode 100644 index 000000000..778b5ae8c --- /dev/null +++ b/charts/stash-catalog/templates/nats/2.4.0/nats-backup-function.yaml @@ -0,0 +1,43 @@ +{{ if .Values.nats.enabled }} +apiVersion: stash.appscode.com/v1beta1 +kind: Function +metadata: + name: 'nats-backup-2.4.0' + labels: + {{- include "stash-catalog.labels" . | nindent 4 }} +spec: + args: + - backup-nats + - --provider=${REPOSITORY_PROVIDER:=} + - --bucket=${REPOSITORY_BUCKET:=} + - --endpoint=${REPOSITORY_ENDPOINT:=} + - --region=${REPOSITORY_REGION:=} + - --path=${REPOSITORY_PREFIX:=} + - --secret-dir=/etc/repository/secret + - --scratch-dir=/tmp + - --enable-cache=${ENABLE_CACHE:=true} + - --max-connections=${MAX_CONNECTIONS:=0} + - --hostname=${HOSTNAME:=} + - --interim-data-dir=${INTERIM_DATA_DIR} + - --nats-args=${args:=} + - --streams=${streams:=} + - --wait-timeout=${waitTimeout:={{ .Values.waitTimeout}}} + - --namespace=${NAMESPACE:=default} + - --appbinding=${TARGET_NAME:=} + - --backupsession=${BACKUP_SESSION:=} + - --retention-keep-last=${RETENTION_KEEP_LAST:=0} + - --retention-keep-hourly=${RETENTION_KEEP_HOURLY:=0} + - --retention-keep-daily=${RETENTION_KEEP_DAILY:=0} + - --retention-keep-weekly=${RETENTION_KEEP_WEEKLY:=0} + - --retention-keep-monthly=${RETENTION_KEEP_MONTHLY:=0} + - --retention-keep-yearly=${RETENTION_KEEP_YEARLY:=0} + - --retention-keep-tags=${RETENTION_KEEP_TAGS:=} + - --retention-prune=${RETENTION_PRUNE:=false} + - --retention-dry-run=${RETENTION_DRY_RUN:=false} + - --output-dir=${outputDir:=} + - --license-apiservice=${LICENSE_APISERVICE:=} + image: '{{ include "catalog.registry" . }}/stash-nats:2.4.0' + volumeMounts: + - mountPath: /etc/repository/secret + name: ${secretVolume} +{{ end }} diff --git a/charts/stash-catalog/templates/nats/2.4.0/nats-backup-task.yaml b/charts/stash-catalog/templates/nats/2.4.0/nats-backup-task.yaml new file mode 100644 index 000000000..dc2811231 --- /dev/null +++ b/charts/stash-catalog/templates/nats/2.4.0/nats-backup-task.yaml @@ -0,0 +1,26 @@ +{{ if .Values.nats.enabled }} +apiVersion: stash.appscode.com/v1beta1 +kind: Task +metadata: + name: 'nats-backup-2.4.0' + labels: + {{- include "stash-catalog.labels" . | nindent 4 }} +spec: + steps: + - name: nats-backup-2.4.0 + params: + - name: outputDir + value: /tmp/output + - name: secretVolume + value: secret-volume + - name: update-status + params: + - name: outputDir + value: /tmp/output + - name: secretVolume + value: secret-volume + volumes: + - name: secret-volume + secret: + secretName: ${REPOSITORY_SECRET_NAME} +{{ end }} diff --git a/charts/stash-catalog/templates/nats/2.4.0/nats-restore-function.yaml b/charts/stash-catalog/templates/nats/2.4.0/nats-restore-function.yaml new file mode 100644 index 000000000..5dd5df3c0 --- /dev/null +++ b/charts/stash-catalog/templates/nats/2.4.0/nats-restore-function.yaml @@ -0,0 +1,36 @@ +{{ if .Values.nats.enabled }} +apiVersion: stash.appscode.com/v1beta1 +kind: Function +metadata: + name: 'nats-restore-2.4.0' + labels: + {{- include "stash-catalog.labels" . | nindent 4 }} +spec: + args: + - restore-nats + - --provider=${REPOSITORY_PROVIDER:=} + - --bucket=${REPOSITORY_BUCKET:=} + - --endpoint=${REPOSITORY_ENDPOINT:=} + - --region=${REPOSITORY_REGION:=} + - --path=${REPOSITORY_PREFIX:=} + - --secret-dir=/etc/repository/secret + - --scratch-dir=/tmp + - --enable-cache=${ENABLE_CACHE:=true} + - --max-connections=${MAX_CONNECTIONS:=0} + - --hostname=${HOSTNAME:=} + - --source-hostname=${SOURCE_HOSTNAME:=} + - --interim-data-dir=${INTERIM_DATA_DIR} + - --nats-args=${args:=} + - --streams=${streams:=} + - --overwrite=${overwrite:=false} + - --wait-timeout=${waitTimeout:={{ .Values.waitTimeout}}} + - --namespace=${NAMESPACE:=default} + - --appbinding=${TARGET_NAME:=} + - --snapshot=${RESTORE_SNAPSHOTS:=} + - --output-dir=${outputDir:=} + - --license-apiservice=${LICENSE_APISERVICE:=} + image: '{{ include "catalog.registry" . }}/stash-nats:2.4.0' + volumeMounts: + - mountPath: /etc/repository/secret + name: ${secretVolume} +{{ end }} diff --git a/charts/stash-catalog/templates/nats/2.4.0/nats-restore-task.yaml b/charts/stash-catalog/templates/nats/2.4.0/nats-restore-task.yaml new file mode 100644 index 000000000..628e1e162 --- /dev/null +++ b/charts/stash-catalog/templates/nats/2.4.0/nats-restore-task.yaml @@ -0,0 +1,26 @@ +{{ if .Values.nats.enabled }} +apiVersion: stash.appscode.com/v1beta1 +kind: Task +metadata: + name: 'nats-restore-2.4.0' + labels: + {{- include "stash-catalog.labels" . | nindent 4 }} +spec: + steps: + - name: nats-restore-2.4.0 + params: + - name: outputDir + value: /tmp/output + - name: secretVolume + value: secret-volume + - name: update-status + params: + - name: outputDir + value: /tmp/output + - name: secretVolume + value: secret-volume + volumes: + - name: secret-volume + secret: + secretName: ${REPOSITORY_SECRET_NAME} +{{ end }} diff --git a/charts/stash-catalog/values.openapiv3_schema.yaml b/charts/stash-catalog/values.openapiv3_schema.yaml index d63612c53..616274102 100644 --- a/charts/stash-catalog/values.openapiv3_schema.yaml +++ b/charts/stash-catalog/values.openapiv3_schema.yaml @@ -91,6 +91,36 @@ properties: - enabled - restore type: object + nats: + description: StashNATSSpec is the schema for Stash NATS values file + properties: + backup: + properties: + args: + type: string + streams: + items: + type: string + type: array + type: object + enabled: + type: boolean + restore: + properties: + args: + type: string + overwrite: + type: boolean + streams: + items: + type: string + type: array + type: object + required: + - backup + - enabled + - restore + type: object perconaxtradb: description: StashPerconaXtraDBSpec is the schema for Stash Percona XtraDB values file @@ -173,6 +203,7 @@ required: - mariadb - mongodb - mysql +- nats - perconaxtradb - postgres - redis diff --git a/charts/stash-catalog/values.yaml b/charts/stash-catalog/values.yaml index 87002e69f..4af38ba5c 100644 --- a/charts/stash-catalog/values.yaml +++ b/charts/stash-catalog/values.yaml @@ -86,3 +86,19 @@ redis: restore: # Arguments to pass to `redis` command during restore process args: "" +nats: + # If true, deploys NATS addon + enabled: true + # optional argument to send to the backup or restore process + backup: + # Arguments to pass to `nats str backup` command during backup process + args: "" + # List of streams to backup. Don't set this field if you want to backup all streams. + streams: "" + restore: + # Arguments to pass to `nats str restore` command during restore process + args: "" + # List of streams to restore. Don't set this field if you want to restore all the backed up streams. + streams: "" + # Specify whether to delete the old stream before restoring from backup. + overwrite: false diff --git a/charts/stash/values.openapiv3_schema.yaml b/charts/stash/values.openapiv3_schema.yaml index 5fcd08b97..2095c9c1b 100644 --- a/charts/stash/values.openapiv3_schema.yaml +++ b/charts/stash/values.openapiv3_schema.yaml @@ -131,6 +131,36 @@ properties: - enabled - restore type: object + nats: + description: StashNATSSpec is the schema for Stash NATS values file + properties: + backup: + properties: + args: + type: string + streams: + items: + type: string + type: array + type: object + enabled: + type: boolean + restore: + properties: + args: + type: string + overwrite: + type: boolean + streams: + items: + type: string + type: array + type: object + required: + - backup + - enabled + - restore + type: object perconaxtradb: description: StashPerconaXtraDBSpec is the schema for Stash Percona XtraDB values file @@ -213,6 +243,7 @@ properties: - mariadb - mongodb - mysql + - nats - perconaxtradb - postgres - redis