diff --git a/operator/documentdb-helm-chart/crds/documentdb.io_backups.yaml b/operator/documentdb-helm-chart/crds/documentdb.io_backups.yaml index 7b3517644..46cee0b8d 100644 --- a/operator/documentdb-helm-chart/crds/documentdb.io_backups.yaml +++ b/operator/documentdb-helm-chart/crds/documentdb.io_backups.yaml @@ -82,6 +82,34 @@ spec: required: - name type: object + method: + default: volumeSnapshot + description: |- + Method defines with method should be used to create a backup + can either be 'volumeSnapshot' or 'plugin' + defaults to 'volumeSnapshot' + enum: + - volumeSnapshot + - plugin + type: string + pluginConfiguration: + description: |- + PluginConfiguration defines additional parameters passed to the plugin + only relevant if method=plugin + properties: + name: + description: Name is the name of the plugin managing this backup + type: string + parameters: + additionalProperties: + type: string + description: |- + Parameters are the configuration parameters passed to the backup + plugin for this backup + type: object + required: + - name + type: object retentionDays: description: |- RetentionDays specifies how many days the backup should be retained. @@ -196,6 +224,34 @@ spec: required: - name type: object + method: + default: volumeSnapshot + description: |- + Method defines with method should be used to create a backup + can either be 'volumeSnapshot' or 'plugin' + defaults to 'volumeSnapshot' + enum: + - volumeSnapshot + - plugin + type: string + pluginConfiguration: + description: |- + PluginConfiguration defines additional parameters passed to the plugin + only relevant if method=plugin + properties: + name: + description: Name is the name of the plugin managing this backup + type: string + parameters: + additionalProperties: + type: string + description: |- + Parameters are the configuration parameters passed to the backup + plugin for this backup + type: object + required: + - name + type: object retentionDays: description: |- RetentionDays specifies how many days the backup should be retained. diff --git a/operator/documentdb-helm-chart/crds/documentdb.io_dbs.yaml b/operator/documentdb-helm-chart/crds/documentdb.io_dbs.yaml index 6c611e6f9..144facc0e 100644 --- a/operator/documentdb-helm-chart/crds/documentdb.io_dbs.yaml +++ b/operator/documentdb-helm-chart/crds/documentdb.io_dbs.yaml @@ -1316,6 +1316,37 @@ spec: Plugins groups CNPG plugin configuration (sidecar injector name, WAL replica name). All fields are optional; defaults are preserved when omitted. properties: + additional: + description: Additional defines which additional CNPG plugins + should be loaded + items: + description: |- + PluginConfiguration specifies a plugin that need to be loaded for this + cluster to be reconciled + properties: + enabled: + default: true + description: Enabled is true if this plugin will be used + type: boolean + isWALArchiver: + default: false + description: |- + Marks the plugin as the WAL archiver. At most one plugin can be + designated as a WAL archiver. This cannot be enabled if the + `.spec.backup.barmanObjectStore` configuration is present. + type: boolean + name: + description: Name is the plugin name + type: string + parameters: + additionalProperties: + type: string + description: Parameters is the configuration of the plugin + type: object + required: + - name + type: object + type: array sidecarInjectorName: description: |- SidecarInjectorName is the name of the CNPG sidecar injector plugin @@ -3005,6 +3036,37 @@ spec: Plugins groups CNPG plugin configuration (sidecar injector name, WAL replica name). All fields are optional; defaults are preserved when omitted. properties: + additional: + description: Additional defines which additional CNPG plugins + should be loaded + items: + description: |- + PluginConfiguration specifies a plugin that need to be loaded for this + cluster to be reconciled + properties: + enabled: + default: true + description: Enabled is true if this plugin will be used + type: boolean + isWALArchiver: + default: false + description: |- + Marks the plugin as the WAL archiver. At most one plugin can be + designated as a WAL archiver. This cannot be enabled if the + `.spec.backup.barmanObjectStore` configuration is present. + type: boolean + name: + description: Name is the plugin name + type: string + parameters: + additionalProperties: + type: string + description: Parameters is the configuration of the plugin + type: object + required: + - name + type: object + type: array sidecarInjectorName: description: |- SidecarInjectorName is the name of the CNPG sidecar injector plugin diff --git a/operator/documentdb-helm-chart/crds/documentdb.io_scheduledbackups.yaml b/operator/documentdb-helm-chart/crds/documentdb.io_scheduledbackups.yaml index b1d63e946..91bc8f8c9 100644 --- a/operator/documentdb-helm-chart/crds/documentdb.io_scheduledbackups.yaml +++ b/operator/documentdb-helm-chart/crds/documentdb.io_scheduledbackups.yaml @@ -63,6 +63,34 @@ spec: required: - name type: object + method: + default: volumeSnapshot + description: |- + Method defines with method should be used to create a backup + can either be 'volumeSnapshot' or 'plugin' + defaults to 'volumeSnapshot' + enum: + - volumeSnapshot + - plugin + type: string + pluginConfiguration: + description: |- + PluginConfiguration defines additional parameters passed to the plugin + only relevant if method=plugin + properties: + name: + description: Name is the name of the plugin managing this backup + type: string + parameters: + additionalProperties: + type: string + description: |- + Parameters are the configuration parameters passed to the backup + plugin for this backup + type: object + required: + - name + type: object retentionDays: description: |- RetentionDays specifies how many days the backups should be retained. @@ -144,6 +172,34 @@ spec: required: - name type: object + method: + default: volumeSnapshot + description: |- + Method defines with method should be used to create a backup + can either be 'volumeSnapshot' or 'plugin' + defaults to 'volumeSnapshot' + enum: + - volumeSnapshot + - plugin + type: string + pluginConfiguration: + description: |- + PluginConfiguration defines additional parameters passed to the plugin + only relevant if method=plugin + properties: + name: + description: Name is the name of the plugin managing this backup + type: string + parameters: + additionalProperties: + type: string + description: |- + Parameters are the configuration parameters passed to the backup + plugin for this backup + type: object + required: + - name + type: object retentionDays: description: |- RetentionDays specifies how many days the backups should be retained. diff --git a/operator/src/api/preview/backup_types.go b/operator/src/api/preview/backup_types.go index 44928c4be..ac31186cc 100644 --- a/operator/src/api/preview/backup_types.go +++ b/operator/src/api/preview/backup_types.go @@ -10,6 +10,15 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +// BackupMethod defines how a backup should be created, can be 'volumeSnapshot' or 'plugin' +// +kubebuilder:validation:Enum=volumeSnapshot;plugin +type BackupMethod cnpgv1.BackupMethod + +const ( + BackupMethodVolumeSnapshot = "volumeSnapshot" + BackupMethodPlugin = "plugin" +) + // BackupSpec defines the desired state of Backup. // +kubebuilder:validation:XValidation:rule="oldSelf == self",message="BackupSpec is immutable once set" type BackupSpec struct { @@ -18,6 +27,17 @@ type BackupSpec struct { // +kubebuilder:validation:Required Cluster cnpgv1.LocalObjectReference `json:"cluster"` + // Method defines with method should be used to create a backup + // can either be 'volumeSnapshot' or 'plugin' + // defaults to 'volumeSnapshot' + // +kubebuilder:default=volumeSnapshot + Method BackupMethod `json:"method,omitempty"` + + // PluginConfiguration defines additional parameters passed to the plugin + // only relevant if method=plugin + // +optional + PluginConfiguration *cnpgv1.BackupPluginConfiguration `json:"pluginConfiguration,omitempty"` + // RetentionDays specifies how many days the backup should be retained. // If not specified, the default retention period from the cluster's backup retention policy will be used. // +optional diff --git a/operator/src/api/preview/documentdb_types.go b/operator/src/api/preview/documentdb_types.go index 75fef30e7..582673503 100644 --- a/operator/src/api/preview/documentdb_types.go +++ b/operator/src/api/preview/documentdb_types.go @@ -231,6 +231,10 @@ type PluginsSpec struct { // cross-cluster replication. // +optional WalReplicaName string `json:"walReplicaName,omitempty"` + + // Additional defines which additional CNPG plugins should be loaded + // +optional + Additional []cnpgv1.PluginConfiguration `json:"additional,omitempty"` } // BootstrapConfiguration defines how to bootstrap a DocumentDB cluster. diff --git a/operator/src/api/preview/scheduledbackup_types.go b/operator/src/api/preview/scheduledbackup_types.go index 792af043e..0679c7676 100644 --- a/operator/src/api/preview/scheduledbackup_types.go +++ b/operator/src/api/preview/scheduledbackup_types.go @@ -17,6 +17,17 @@ type ScheduledBackupSpec struct { // +kubebuilder:validation:Required Cluster cnpgv1.LocalObjectReference `json:"cluster"` + // Method defines with method should be used to create a backup + // can either be 'volumeSnapshot' or 'plugin' + // defaults to 'volumeSnapshot' + // +kubebuilder:default=volumeSnapshot + Method BackupMethod `json:"method,omitempty"` + + // PluginConfiguration defines additional parameters passed to the plugin + // only relevant if method=plugin + // +optional + PluginConfiguration *cnpgv1.BackupPluginConfiguration `json:"pluginConfiguration,omitempty"` + // Schedule defines when backups should be created using cron expression format. // See https://pkg.go.dev/github.com/robfig/cron#hdr-CRON_Expression_Format // +kubebuilder:validation:Required diff --git a/operator/src/api/preview/zz_generated.deepcopy.go b/operator/src/api/preview/zz_generated.deepcopy.go index fa01423c8..cf7771a6b 100644 --- a/operator/src/api/preview/zz_generated.deepcopy.go +++ b/operator/src/api/preview/zz_generated.deepcopy.go @@ -8,8 +8,8 @@ package preview import ( - apiv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" - "k8s.io/api/core/v1" + "github.com/cloudnative-pg/cloudnative-pg/api/v1" + corev1 "k8s.io/api/core/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -91,6 +91,11 @@ func (in *BackupList) DeepCopyObject() runtime.Object { func (in *BackupSpec) DeepCopyInto(out *BackupSpec) { *out = *in in.Cluster.DeepCopyInto(&out.Cluster) + if in.PluginConfiguration != nil { + in, out := &in.PluginConfiguration, &out.PluginConfiguration + *out = new(v1.BackupPluginConfiguration) + (*in).DeepCopyInto(*out) + } if in.RetentionDays != nil { in, out := &in.RetentionDays, &out.RetentionDays *out = new(int) @@ -281,7 +286,7 @@ func (in *DocumentDBSpec) DeepCopyInto(out *DocumentDBSpec) { } if in.ImagePullSecrets != nil { in, out := &in.ImagePullSecrets, &out.ImagePullSecrets - *out = make([]v1.LocalObjectReference, len(*in)) + *out = make([]corev1.LocalObjectReference, len(*in)) copy(*out, *in) } if in.ClusterReplication != nil { @@ -297,7 +302,7 @@ func (in *DocumentDBSpec) DeepCopyInto(out *DocumentDBSpec) { if in.Plugins != nil { in, out := &in.Plugins, &out.Plugins *out = new(PluginsSpec) - **out = **in + (*in).DeepCopyInto(*out) } out.ExposeViaService = in.ExposeViaService out.Timeouts = in.Timeouts @@ -539,6 +544,13 @@ func (in *PVRecoveryConfiguration) DeepCopy() *PVRecoveryConfiguration { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PluginsSpec) DeepCopyInto(out *PluginsSpec) { *out = *in + if in.Additional != nil { + in, out := &in.Additional, &out.Additional + *out = make([]v1.PluginConfiguration, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PluginsSpec. @@ -733,6 +745,11 @@ func (in *ScheduledBackupList) DeepCopyObject() runtime.Object { func (in *ScheduledBackupSpec) DeepCopyInto(out *ScheduledBackupSpec) { *out = *in in.Cluster.DeepCopyInto(&out.Cluster) + if in.PluginConfiguration != nil { + in, out := &in.PluginConfiguration, &out.PluginConfiguration + *out = new(v1.BackupPluginConfiguration) + (*in).DeepCopyInto(*out) + } if in.RetentionDays != nil { in, out := &in.RetentionDays, &out.RetentionDays *out = new(int) @@ -798,7 +815,7 @@ func (in *TLSConfiguration) DeepCopyInto(out *TLSConfiguration) { } if in.Postgres != nil { in, out := &in.Postgres, &out.Postgres - *out = new(apiv1.CertificatesConfiguration) + *out = new(v1.CertificatesConfiguration) (*in).DeepCopyInto(*out) } if in.GlobalEndpoints != nil { diff --git a/operator/src/api/v1/backup_funcs.go b/operator/src/api/v1/backup_funcs.go index e17cec01b..5cd344fc9 100644 --- a/operator/src/api/v1/backup_funcs.go +++ b/operator/src/api/v1/backup_funcs.go @@ -14,24 +14,29 @@ import ( ) // CreateCNPGBackup creates a CNPG Backup resource based on the DocumentDB Backup spec. -func (backup *Backup) CreateCNPGBackup(scheme *runtime.Scheme, clusterName string) (*cnpgv1.Backup, error) { - return NewCNPGBackup(scheme, backup, clusterName) +func (backup *Backup) CreateCNPGBackup(scheme *runtime.Scheme, clusterName string, spec *BackupSpec) (*cnpgv1.Backup, error) { + return NewCNPGBackup(scheme, backup, clusterName, spec) } // NewCNPGBackup creates a volume-snapshot CNPG Backup of clusterName with the // same name and namespace as owner, controlled by owner so it is garbage // collected with it. -func NewCNPGBackup(scheme *runtime.Scheme, owner client.Object, clusterName string) (*cnpgv1.Backup, error) { +func NewCNPGBackup(scheme *runtime.Scheme, owner client.Object, clusterName string, spec *BackupSpec) (*cnpgv1.Backup, error) { + backupMethod := spec.Method + if len(backupMethod) == 0 { + backupMethod = BackupMethod(cnpgv1.BackupMethodVolumeSnapshot) + } cnpgBackup := &cnpgv1.Backup{ ObjectMeta: metav1.ObjectMeta{ Name: owner.GetName(), Namespace: owner.GetNamespace(), }, Spec: cnpgv1.BackupSpec{ - Method: cnpgv1.BackupMethodVolumeSnapshot, + Method: cnpgv1.BackupMethod(backupMethod), Cluster: cnpgv1.LocalObjectReference{ Name: clusterName, }, + PluginConfiguration: spec.PluginConfiguration, }, } // Set owner reference for garbage collection diff --git a/operator/src/api/v1/backup_funcs_test.go b/operator/src/api/v1/backup_funcs_test.go index 5da591325..cfcc5467d 100644 --- a/operator/src/api/v1/backup_funcs_test.go +++ b/operator/src/api/v1/backup_funcs_test.go @@ -35,7 +35,7 @@ var _ = Describe("Backup", func() { }, } - cnpg, err := backup.CreateCNPGBackup(scheme, "my-cluster-x") + cnpg, err := backup.CreateCNPGBackup(scheme, "my-cluster-x", &backup.Spec) Expect(err).To(BeNil()) Expect(cnpg).ToNot(BeNil()) diff --git a/operator/src/api/v1/backup_types.go b/operator/src/api/v1/backup_types.go index 65af0d05c..fe9e9839b 100644 --- a/operator/src/api/v1/backup_types.go +++ b/operator/src/api/v1/backup_types.go @@ -8,6 +8,15 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +// BackupMethod defines how a backup should be created, can be 'volumeSnapshot' or 'plugin' +// +kubebuilder:validation:Enum=volumeSnapshot;plugin +type BackupMethod cnpgv1.BackupMethod + +const ( + BackupMethodVolumeSnapshot = "volumeSnapshot" + BackupMethodPlugin = "plugin" +) + // BackupSpec defines the desired state of Backup. // +kubebuilder:validation:XValidation:rule="oldSelf == self",message="BackupSpec is immutable once set" type BackupSpec struct { @@ -16,6 +25,17 @@ type BackupSpec struct { // +kubebuilder:validation:Required Cluster cnpgv1.LocalObjectReference `json:"cluster"` + // Method defines with method should be used to create a backup + // can either be 'volumeSnapshot' or 'plugin' + // defaults to 'volumeSnapshot' + // +kubebuilder:default=volumeSnapshot + Method BackupMethod `json:"method,omitempty"` + + // PluginConfiguration defines additional parameters passed to the plugin + // only relevant if method=plugin + // +optional + PluginConfiguration *cnpgv1.BackupPluginConfiguration `json:"pluginConfiguration,omitempty"` + // RetentionDays specifies how many days the backup should be retained. // If not specified, the default retention period from the cluster's backup retention policy will be used. // +optional diff --git a/operator/src/api/v1/documentdb_types.go b/operator/src/api/v1/documentdb_types.go index 40a3fbf78..a34e9a932 100644 --- a/operator/src/api/v1/documentdb_types.go +++ b/operator/src/api/v1/documentdb_types.go @@ -229,6 +229,10 @@ type PluginsSpec struct { // cross-cluster replication. // +optional WalReplicaName string `json:"walReplicaName,omitempty"` + + // Additional defines which additional CNPG plugins should be loaded + // +optional + Additional []cnpgv1.PluginConfiguration `json:"additional,omitempty"` } // BootstrapConfiguration defines how to bootstrap a DocumentDB cluster. diff --git a/operator/src/api/v1/scheduledbackup_types.go b/operator/src/api/v1/scheduledbackup_types.go index 059276b28..b648f4a06 100644 --- a/operator/src/api/v1/scheduledbackup_types.go +++ b/operator/src/api/v1/scheduledbackup_types.go @@ -15,6 +15,17 @@ type ScheduledBackupSpec struct { // +kubebuilder:validation:Required Cluster cnpgv1.LocalObjectReference `json:"cluster"` + // Method defines with method should be used to create a backup + // can either be 'volumeSnapshot' or 'plugin' + // defaults to 'volumeSnapshot' + // +kubebuilder:default=volumeSnapshot + Method BackupMethod `json:"method,omitempty"` + + // PluginConfiguration defines additional parameters passed to the plugin + // only relevant if method=plugin + // +optional + PluginConfiguration *cnpgv1.BackupPluginConfiguration `json:"pluginConfiguration,omitempty"` + // Schedule defines when backups should be created using cron expression format. // See https://pkg.go.dev/github.com/robfig/cron#hdr-CRON_Expression_Format // +kubebuilder:validation:Required diff --git a/operator/src/api/v1/zz_generated.deepcopy.go b/operator/src/api/v1/zz_generated.deepcopy.go index de5c1b8e0..01b43325a 100644 --- a/operator/src/api/v1/zz_generated.deepcopy.go +++ b/operator/src/api/v1/zz_generated.deepcopy.go @@ -91,6 +91,11 @@ func (in *BackupList) DeepCopyObject() runtime.Object { func (in *BackupSpec) DeepCopyInto(out *BackupSpec) { *out = *in in.Cluster.DeepCopyInto(&out.Cluster) + if in.PluginConfiguration != nil { + in, out := &in.PluginConfiguration, &out.PluginConfiguration + *out = new(apiv1.BackupPluginConfiguration) + (*in).DeepCopyInto(*out) + } if in.RetentionDays != nil { in, out := &in.RetentionDays, &out.RetentionDays *out = new(int) @@ -297,7 +302,7 @@ func (in *DocumentDBSpec) DeepCopyInto(out *DocumentDBSpec) { if in.Plugins != nil { in, out := &in.Plugins, &out.Plugins *out = new(PluginsSpec) - **out = **in + (*in).DeepCopyInto(*out) } out.ExposeViaService = in.ExposeViaService out.Timeouts = in.Timeouts @@ -539,6 +544,13 @@ func (in *PVRecoveryConfiguration) DeepCopy() *PVRecoveryConfiguration { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PluginsSpec) DeepCopyInto(out *PluginsSpec) { *out = *in + if in.Additional != nil { + in, out := &in.Additional, &out.Additional + *out = make([]apiv1.PluginConfiguration, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PluginsSpec. @@ -733,6 +745,11 @@ func (in *ScheduledBackupList) DeepCopyObject() runtime.Object { func (in *ScheduledBackupSpec) DeepCopyInto(out *ScheduledBackupSpec) { *out = *in in.Cluster.DeepCopyInto(&out.Cluster) + if in.PluginConfiguration != nil { + in, out := &in.PluginConfiguration, &out.PluginConfiguration + *out = new(apiv1.BackupPluginConfiguration) + (*in).DeepCopyInto(*out) + } if in.RetentionDays != nil { in, out := &in.RetentionDays, &out.RetentionDays *out = new(int) diff --git a/operator/src/config/crd/bases/documentdb.io_backups.yaml b/operator/src/config/crd/bases/documentdb.io_backups.yaml index 7b3517644..46cee0b8d 100644 --- a/operator/src/config/crd/bases/documentdb.io_backups.yaml +++ b/operator/src/config/crd/bases/documentdb.io_backups.yaml @@ -82,6 +82,34 @@ spec: required: - name type: object + method: + default: volumeSnapshot + description: |- + Method defines with method should be used to create a backup + can either be 'volumeSnapshot' or 'plugin' + defaults to 'volumeSnapshot' + enum: + - volumeSnapshot + - plugin + type: string + pluginConfiguration: + description: |- + PluginConfiguration defines additional parameters passed to the plugin + only relevant if method=plugin + properties: + name: + description: Name is the name of the plugin managing this backup + type: string + parameters: + additionalProperties: + type: string + description: |- + Parameters are the configuration parameters passed to the backup + plugin for this backup + type: object + required: + - name + type: object retentionDays: description: |- RetentionDays specifies how many days the backup should be retained. @@ -196,6 +224,34 @@ spec: required: - name type: object + method: + default: volumeSnapshot + description: |- + Method defines with method should be used to create a backup + can either be 'volumeSnapshot' or 'plugin' + defaults to 'volumeSnapshot' + enum: + - volumeSnapshot + - plugin + type: string + pluginConfiguration: + description: |- + PluginConfiguration defines additional parameters passed to the plugin + only relevant if method=plugin + properties: + name: + description: Name is the name of the plugin managing this backup + type: string + parameters: + additionalProperties: + type: string + description: |- + Parameters are the configuration parameters passed to the backup + plugin for this backup + type: object + required: + - name + type: object retentionDays: description: |- RetentionDays specifies how many days the backup should be retained. diff --git a/operator/src/config/crd/bases/documentdb.io_dbs.yaml b/operator/src/config/crd/bases/documentdb.io_dbs.yaml index 6c611e6f9..144facc0e 100644 --- a/operator/src/config/crd/bases/documentdb.io_dbs.yaml +++ b/operator/src/config/crd/bases/documentdb.io_dbs.yaml @@ -1316,6 +1316,37 @@ spec: Plugins groups CNPG plugin configuration (sidecar injector name, WAL replica name). All fields are optional; defaults are preserved when omitted. properties: + additional: + description: Additional defines which additional CNPG plugins + should be loaded + items: + description: |- + PluginConfiguration specifies a plugin that need to be loaded for this + cluster to be reconciled + properties: + enabled: + default: true + description: Enabled is true if this plugin will be used + type: boolean + isWALArchiver: + default: false + description: |- + Marks the plugin as the WAL archiver. At most one plugin can be + designated as a WAL archiver. This cannot be enabled if the + `.spec.backup.barmanObjectStore` configuration is present. + type: boolean + name: + description: Name is the plugin name + type: string + parameters: + additionalProperties: + type: string + description: Parameters is the configuration of the plugin + type: object + required: + - name + type: object + type: array sidecarInjectorName: description: |- SidecarInjectorName is the name of the CNPG sidecar injector plugin @@ -3005,6 +3036,37 @@ spec: Plugins groups CNPG plugin configuration (sidecar injector name, WAL replica name). All fields are optional; defaults are preserved when omitted. properties: + additional: + description: Additional defines which additional CNPG plugins + should be loaded + items: + description: |- + PluginConfiguration specifies a plugin that need to be loaded for this + cluster to be reconciled + properties: + enabled: + default: true + description: Enabled is true if this plugin will be used + type: boolean + isWALArchiver: + default: false + description: |- + Marks the plugin as the WAL archiver. At most one plugin can be + designated as a WAL archiver. This cannot be enabled if the + `.spec.backup.barmanObjectStore` configuration is present. + type: boolean + name: + description: Name is the plugin name + type: string + parameters: + additionalProperties: + type: string + description: Parameters is the configuration of the plugin + type: object + required: + - name + type: object + type: array sidecarInjectorName: description: |- SidecarInjectorName is the name of the CNPG sidecar injector plugin diff --git a/operator/src/config/crd/bases/documentdb.io_scheduledbackups.yaml b/operator/src/config/crd/bases/documentdb.io_scheduledbackups.yaml index b1d63e946..91bc8f8c9 100644 --- a/operator/src/config/crd/bases/documentdb.io_scheduledbackups.yaml +++ b/operator/src/config/crd/bases/documentdb.io_scheduledbackups.yaml @@ -63,6 +63,34 @@ spec: required: - name type: object + method: + default: volumeSnapshot + description: |- + Method defines with method should be used to create a backup + can either be 'volumeSnapshot' or 'plugin' + defaults to 'volumeSnapshot' + enum: + - volumeSnapshot + - plugin + type: string + pluginConfiguration: + description: |- + PluginConfiguration defines additional parameters passed to the plugin + only relevant if method=plugin + properties: + name: + description: Name is the name of the plugin managing this backup + type: string + parameters: + additionalProperties: + type: string + description: |- + Parameters are the configuration parameters passed to the backup + plugin for this backup + type: object + required: + - name + type: object retentionDays: description: |- RetentionDays specifies how many days the backups should be retained. @@ -144,6 +172,34 @@ spec: required: - name type: object + method: + default: volumeSnapshot + description: |- + Method defines with method should be used to create a backup + can either be 'volumeSnapshot' or 'plugin' + defaults to 'volumeSnapshot' + enum: + - volumeSnapshot + - plugin + type: string + pluginConfiguration: + description: |- + PluginConfiguration defines additional parameters passed to the plugin + only relevant if method=plugin + properties: + name: + description: Name is the name of the plugin managing this backup + type: string + parameters: + additionalProperties: + type: string + description: |- + Parameters are the configuration parameters passed to the backup + plugin for this backup + type: object + required: + - name + type: object retentionDays: description: |- RetentionDays specifies how many days the backups should be retained. diff --git a/operator/src/internal/cnpg/cnpg_cluster.go b/operator/src/internal/cnpg/cnpg_cluster.go index a0cfee393..c0dfd0373 100644 --- a/operator/src/internal/cnpg/cnpg_cluster.go +++ b/operator/src/internal/cnpg/cnpg_cluster.go @@ -157,6 +157,9 @@ func GetCnpgClusterSpecFromIntent(req ctrl.Request, intent product.ClusterIntent Resources: buildResourceRequirements(split.Postgres), } spec.MaxStopDelay = stopDelayOrDefault(intent.Postgres.StopDelay) + if intent.AdditionalCNPGPlugins != nil { + spec.Plugins = append(spec.Plugins, intent.AdditionalCNPGPlugins...) + } applyPostgresProcessIdentity(&spec, intent) applyIOUringSeccomp(&spec, intent) applyOtelMonitorRole(&spec, intent.Monitoring, intent.Product.Postgres.MonitoringPasswordSecret) diff --git a/operator/src/internal/engine/backup.go b/operator/src/internal/engine/backup.go index 452be2301..f06ecbe53 100644 --- a/operator/src/internal/engine/backup.go +++ b/operator/src/internal/engine/backup.go @@ -101,10 +101,13 @@ func (r *BackupReconciler[T, B]) Reconcile(ctx context.Context, req ctrl.Request return r.SetBackupPhaseFailed(ctx, backup, "Failed to get associated "+r.Cluster.Profile().Naming.Kind+" cluster: "+err.Error(), nil) } clusterSpec := r.Cluster.Spec(cluster) + backupSpec := r.Backups.Spec(backup) // Ensure VolumeSnapshotClass exists - if err := r.EnsureVolumeSnapshotClass(ctx, clusterSpec.Environment); err != nil { - return r.SetBackupPhaseFailed(ctx, backup, "Failed to ensure VolumeSnapshotClass: "+err.Error(), clusterSpec.Backup) + if cnpgv1.BackupMethod(backupSpec.Method) == cnpgv1.BackupMethodVolumeSnapshot { + if err := r.EnsureVolumeSnapshotClass(ctx, clusterSpec.Environment); err != nil { + return r.SetBackupPhaseFailed(ctx, backup, "Failed to ensure VolumeSnapshotClass: "+err.Error(), clusterSpec.Backup) + } } // Get or create the CNPG Backup @@ -205,7 +208,8 @@ func BuildVolumeSnapshotClass(environment string) *snapshotv1.VolumeSnapshotClas func (r *BackupReconciler[T, B]) CreateCNPGBackup(ctx context.Context, backup B, backupConfiguration *dbv1.BackupConfiguration, replicationContext *util.ReplicationContext) (ctrl.Result, error) { cnpgClusterName := replicationContext.CNPGClusterName - cnpgBackup, err := dbv1.NewCNPGBackup(r.Scheme, backup, cnpgClusterName) + backupSpec := r.Backups.Spec(backup) + cnpgBackup, err := dbv1.NewCNPGBackup(r.Scheme, backup, cnpgClusterName, backupSpec) if err != nil { return r.SetBackupPhaseFailed(ctx, backup, "Failed to initialize backup: "+err.Error(), backupConfiguration) } diff --git a/operator/src/internal/engine/backup_test.go b/operator/src/internal/engine/backup_test.go index 558491238..61a51a9ca 100644 --- a/operator/src/internal/engine/backup_test.go +++ b/operator/src/internal/engine/backup_test.go @@ -54,15 +54,24 @@ func defaultSnapshotClass() *snapshotv1.VolumeSnapshotClass { } } -func getBackup(t *testing.T, c client.Client) *dbv1.Backup { +func getBackupWithMethod(t *testing.T, c client.Client, method dbv1.BackupMethod) *dbv1.Backup { t.Helper() - b := &dbv1.Backup{} + backupMethod := method + b := &dbv1.Backup{ + Spec: dbv1.BackupSpec{ + Method: backupMethod, + }, + } if err := c.Get(context.Background(), backupKey.NamespacedName, b); err != nil { t.Fatalf("get backup: %v", err) } return b } +func getBackup(t *testing.T, c client.Client) *dbv1.Backup { + return getBackupWithMethod(t, c, dbv1.BackupMethodVolumeSnapshot) +} + func TestBackupReconcileNotFoundAndGetError(t *testing.T) { s := newTestScheme(t) r := newBackupReconciler(newFakeClient(t, s, nil), s, record.NewFakeRecorder(10)) diff --git a/operator/src/internal/engine/scheduledbackup.go b/operator/src/internal/engine/scheduledbackup.go index 2ad4ef13d..ba1f47291 100644 --- a/operator/src/internal/engine/scheduledbackup.go +++ b/operator/src/internal/engine/scheduledbackup.go @@ -138,8 +138,10 @@ func (r *ScheduledBackupReconciler[T, S, B]) newBackup(scheduledBackup S, now ti dbv1.ScheduledBackupLabel: scheduledBackup.GetName(), }) *r.Backups.Spec(backup) = dbv1.BackupSpec{ - Cluster: spec.Cluster, - RetentionDays: spec.RetentionDays, + Cluster: spec.Cluster, + RetentionDays: spec.RetentionDays, + Method: spec.Method, + PluginConfiguration: spec.PluginConfiguration, } return backup } diff --git a/operator/src/internal/engine/scheduledbackup_test.go b/operator/src/internal/engine/scheduledbackup_test.go index 4576d3352..57522ee26 100644 --- a/operator/src/internal/engine/scheduledbackup_test.go +++ b/operator/src/internal/engine/scheduledbackup_test.go @@ -55,7 +55,7 @@ func testScheduledBackup(schedule string) *dbv1.ScheduledBackup { func testBackupFor(name string, phase cnpgv1.BackupPhase, created time.Time) *dbv1.Backup { return &dbv1.Backup{ ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: testNamespace, CreationTimestamp: metav1.NewTime(created)}, - Spec: dbv1.BackupSpec{Cluster: cnpgv1.LocalObjectReference{Name: "db"}}, + Spec: dbv1.BackupSpec{Cluster: cnpgv1.LocalObjectReference{Name: "db"}, Method: dbv1.BackupMethod(cnpgv1.BackupMethodVolumeSnapshot)}, Status: dbv1.BackupStatus{Phase: phase}, } } diff --git a/operator/src/internal/product/documentdb.go b/operator/src/internal/product/documentdb.go index 021997039..7185b390c 100644 --- a/operator/src/internal/product/documentdb.go +++ b/operator/src/internal/product/documentdb.go @@ -6,6 +6,7 @@ package product import ( "os" + cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" dbv1 "github.com/documentdb/documentdb-operator/api/v1" util "github.com/documentdb/documentdb-operator/internal/utils" ) @@ -196,6 +197,11 @@ func (a DocumentDBAdapter) ToClusterIntent(db *dbv1.DocumentDB) ClusterIntent { bootstrap.Recovery = &r } + var additionalPlugins []cnpgv1.PluginConfiguration + if db.Spec.Plugins != nil && db.Spec.Plugins.Additional != nil { + additionalPlugins = db.Spec.Plugins.Additional + } + return ClusterIntent{ Images: Images{ PostgresExtension: a.ExtensionImage(db), @@ -228,6 +234,7 @@ func (a DocumentDBAdapter) ToClusterIntent(db *dbv1.DocumentDB) ClusterIntent { IOUring: dbv1.IsFeatureGateEnabled(db, dbv1.FeatureGateIOUring), }, Bootstrap: bootstrap, + AdditionalCNPGPlugins: additionalPlugins, CredentialSecret: credentialSecret, SidecarInjectorPlugin: sidecarPlugin, WALReplicaPlugin: p.WALReplicaPlugin, diff --git a/operator/src/internal/product/intent.go b/operator/src/internal/product/intent.go index 1139cdf6f..9e782e538 100644 --- a/operator/src/internal/product/intent.go +++ b/operator/src/internal/product/intent.go @@ -159,6 +159,9 @@ type ClusterIntent struct { // Bootstrap describes how the cluster is initialized. Bootstrap Bootstrap + // AdditionalCNPGPlugins are the resolved CNPG plugin names to wire onto the Cluster. + AdditionalCNPGPlugins []cnpgv1.PluginConfiguration + // CredentialSecret is the resolved credential secret name. CredentialSecret string