|
| 1 | +package mdb |
| 2 | + |
| 3 | +import v1 "github.com/mongodb/mongodb-kubernetes/api/v1" |
| 4 | + |
| 5 | +type BackupMode string |
| 6 | + |
| 7 | +// Backup contains configuration options for configuring |
| 8 | +// backup for this MongoDB resource |
| 9 | +type Backup struct { |
| 10 | + // +kubebuilder:validation:Enum=enabled;disabled;terminated |
| 11 | + // +optional |
| 12 | + Mode BackupMode `json:"mode"` |
| 13 | + |
| 14 | + // AutoTerminateOnDeletion indicates if the Operator should stop and terminate the Backup before the cleanup, |
| 15 | + // when the MongoDB CR is deleted |
| 16 | + // +optional |
| 17 | + AutoTerminateOnDeletion bool `json:"autoTerminateOnDeletion,omitempty"` |
| 18 | + |
| 19 | + // +optional |
| 20 | + SnapshotSchedule *SnapshotSchedule `json:"snapshotSchedule,omitempty"` |
| 21 | + |
| 22 | + // Encryption settings |
| 23 | + // +optional |
| 24 | + Encryption *Encryption `json:"encryption,omitempty"` |
| 25 | + |
| 26 | + // Assignment Labels set in the Ops Manager |
| 27 | + // +optional |
| 28 | + AssignmentLabels []string `json:"assignmentLabels,omitempty"` |
| 29 | +} |
| 30 | + |
| 31 | +type SnapshotSchedule struct { |
| 32 | + // Number of hours between snapshots. |
| 33 | + // +kubebuilder:validation:Enum=6;8;12;24 |
| 34 | + // +optional |
| 35 | + SnapshotIntervalHours *int `json:"snapshotIntervalHours,omitempty"` |
| 36 | + |
| 37 | + // Number of days to keep recent snapshots. |
| 38 | + // +kubebuilder:validation:Minimum=1 |
| 39 | + // +kubebuilder:validation:Maximum=365 |
| 40 | + // +optional |
| 41 | + SnapshotRetentionDays *int `json:"snapshotRetentionDays,omitempty"` |
| 42 | + |
| 43 | + // Number of days to retain daily snapshots. Setting 0 will disable this rule. |
| 44 | + // +kubebuilder:validation:Minimum=0 |
| 45 | + // +kubebuilder:validation:Maximum=365 |
| 46 | + // +optional |
| 47 | + DailySnapshotRetentionDays *int `json:"dailySnapshotRetentionDays"` |
| 48 | + |
| 49 | + // Number of weeks to retain weekly snapshots. Setting 0 will disable this rule |
| 50 | + // +kubebuilder:validation:Minimum=0 |
| 51 | + // +kubebuilder:validation:Maximum=365 |
| 52 | + // +optional |
| 53 | + WeeklySnapshotRetentionWeeks *int `json:"weeklySnapshotRetentionWeeks,omitempty"` |
| 54 | + // Number of months to retain weekly snapshots. Setting 0 will disable this rule. |
| 55 | + // +kubebuilder:validation:Minimum=0 |
| 56 | + // +kubebuilder:validation:Maximum=36 |
| 57 | + // +optional |
| 58 | + MonthlySnapshotRetentionMonths *int `json:"monthlySnapshotRetentionMonths,omitempty"` |
| 59 | + // Number of hours in the past for which a point-in-time snapshot can be created. |
| 60 | + // +kubebuilder:validation:Enum=1;2;3;4;5;6;7;15;30;60;90;120;180;360 |
| 61 | + // +optional |
| 62 | + PointInTimeWindowHours *int `json:"pointInTimeWindowHours,omitempty"` |
| 63 | + |
| 64 | + // Hour of the day to schedule snapshots using a 24-hour clock, in UTC. |
| 65 | + // +kubebuilder:validation:Minimum=0 |
| 66 | + // +kubebuilder:validation:Maximum=23 |
| 67 | + // +optional |
| 68 | + ReferenceHourOfDay *int `json:"referenceHourOfDay,omitempty"` |
| 69 | + |
| 70 | + // Minute of the hour to schedule snapshots, in UTC. |
| 71 | + // +kubebuilder:validation:Minimum=0 |
| 72 | + // +kubebuilder:validation:Maximum=59 |
| 73 | + // +optional |
| 74 | + ReferenceMinuteOfHour *int `json:"referenceMinuteOfHour,omitempty"` |
| 75 | + |
| 76 | + // Day of the week when Ops Manager takes a full snapshot. This ensures a recent complete backup. Ops Manager sets the default value to SUNDAY. |
| 77 | + // +kubebuilder:validation:Enum=SUNDAY;MONDAY;TUESDAY;WEDNESDAY;THURSDAY;FRIDAY;SATURDAY |
| 78 | + // +optional |
| 79 | + FullIncrementalDayOfWeek *string `json:"fullIncrementalDayOfWeek,omitempty"` |
| 80 | + |
| 81 | + // +kubebuilder:validation:Enum=15;30;60 |
| 82 | + ClusterCheckpointIntervalMin *int `json:"clusterCheckpointIntervalMin,omitempty"` |
| 83 | +} |
| 84 | + |
| 85 | +type BackupStatus struct { |
| 86 | + StatusName string `json:"statusName"` |
| 87 | +} |
| 88 | + |
| 89 | +// Encryption contains encryption settings |
| 90 | +type Encryption struct { |
| 91 | + // Kmip corresponds to the KMIP configuration assigned to the Ops Manager Project's configuration. |
| 92 | + // +optional |
| 93 | + Kmip *KmipConfig `json:"kmip,omitempty"` |
| 94 | +} |
| 95 | + |
| 96 | +// KmipConfig contains Project-level KMIP configuration |
| 97 | +type KmipConfig struct { |
| 98 | + // KMIP Client configuration |
| 99 | + Client v1.KmipClientConfig `json:"client"` |
| 100 | +} |
| 101 | + |
| 102 | +func (b *Backup) IsKmipEnabled() bool { |
| 103 | + if b.Encryption == nil || b.Encryption.Kmip == nil { |
| 104 | + return false |
| 105 | + } |
| 106 | + return true |
| 107 | +} |
| 108 | + |
| 109 | +func (b *Backup) GetKmip() *KmipConfig { |
| 110 | + if !b.IsKmipEnabled() { |
| 111 | + return nil |
| 112 | + } |
| 113 | + return b.Encryption.Kmip |
| 114 | +} |
0 commit comments