@@ -944,9 +944,12 @@ type MongodSpecInMemory struct {
944944}
945945
946946type BackupTaskSpec struct {
947- Name string `json:"name"`
948- Enabled bool `json:"enabled"`
949- Keep int `json:"keep,omitempty"`
947+ Name string `json:"name"`
948+ Enabled bool `json:"enabled"`
949+ // Deprecated: Use Retention instead. This field will be removed in the future
950+ Keep int `json:"keep,omitempty"`
951+ // +optional
952+ Retention * BackupTaskSpecRetention `json:"retention,omitempty"`
950953 Schedule string `json:"schedule,omitempty"`
951954 StorageName string `json:"storageName,omitempty"`
952955 CompressionType compress.CompressionType `json:"compressionType,omitempty"`
@@ -956,6 +959,36 @@ type BackupTaskSpec struct {
956959 Type defs.BackupType `json:"type,omitempty"`
957960}
958961
962+ func (task * BackupTaskSpec ) GetRetention (cr * PerconaServerMongoDB ) BackupTaskSpecRetention {
963+ if task .Retention != nil && cr .CompareVersion ("1.21.0" ) >= 0 {
964+ return * task .Retention
965+ }
966+ return BackupTaskSpecRetention {
967+ Type : BackupTaskSpecRetentionTypeCount ,
968+ Count : task .Keep ,
969+ DeleteFromStorage : true ,
970+ }
971+ }
972+
973+ type BackupTaskSpecRetentionType string
974+
975+ const (
976+ BackupTaskSpecRetentionTypeCount = "count"
977+ )
978+
979+ type BackupTaskSpecRetention struct {
980+ // +kubebuilder:validation:Minimum=0
981+ Count int `json:"count,omitempty"`
982+
983+ // +kubebuilder:validation:Required
984+ // +kubebuilder:validation:Enum={count}
985+ Type string `json:"type,omitempty"`
986+
987+ // +kubebuilder:validation:Required
988+ // +kubebuilder:default=true
989+ DeleteFromStorage bool `json:"deleteFromStorage,omitempty"`
990+ }
991+
959992func (task * BackupTaskSpec ) JobName (cr * PerconaServerMongoDB ) string {
960993 return fmt .Sprintf ("%s-backup-%s-%s" , cr .Name , task .Name , cr .Namespace )
961994}
0 commit comments