Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions apis/archiver/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions apis/archiver/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ limitations under the License.
package v1alpha1

import (
"fmt"
"regexp"
"strconv"
"time"

api "kubedb.dev/apimachinery/apis/kubedb/v1"

batch "k8s.io/api/batch/v1"
Expand Down Expand Up @@ -78,6 +83,13 @@ type LogBackupOptions struct {
// +optional
ConfigSecret *GenericSecretReference `json:"configSecret,omitempty"`

// RetentionPeriod is the retention policy to be used for Logs (i.e. '60d') means how long logs will be retained before being pruned.
// The retention policy is expressed in the form of `XXu` where `XX` is a positive integer and `u` is in `[dwm]` - days, weeks, months, years.
// +kubebuilder:validation:Pattern=^[1-9][0-9]*[dwmy]$
// +optional
RetentionPeriod string `json:"retentionPeriod,omitempty"`
// time.RFC3339 We need to parse the time to RFC3339 format

// SuccessfulLogHistoryLimit defines the number of successful Logs backup status that the incremental snapshot will retain
// The default value is 5.
// +kubebuilder:default=5
Expand All @@ -89,6 +101,31 @@ type LogBackupOptions struct {
// +kubebuilder:default=5
// +optional
FailedLogHistoryLimit int32 `json:"failedLogHistoryLimit,omitempty"`

// LogRetentionHistoryLimit defines the number of retention status the incremental snapshot will retain for debugging purposes.
// The default value is 5.
// +kubebuilder:default=5
// +optional
LogRetentionHistoryLimit int32 `json:"logRetentionHistoryLimit,omitempty"`
}

func ParseCutoffTimeFromPeriod(period string, now time.Time) (time.Time, error) {
regexPolicy := regexp.MustCompile(`^([1-9][0-9]*)([dwmy])$`)
unitFunc := map[string]func(int) time.Time{
"d": func(v int) time.Time { return now.AddDate(0, 0, -v) },
"w": func(v int) time.Time { return now.AddDate(0, 0, -v*7) },
"m": func(v int) time.Time { return now.AddDate(0, -v, 0) },
"y": func(v int) time.Time { return now.AddDate(-v, 0, 0) },
}
matches := regexPolicy.FindStringSubmatch(period)
if len(matches) < 3 {
return time.Time{}, fmt.Errorf("not a valid period")
}
value, err := strconv.Atoi(matches[1])
if err != nil {
return time.Time{}, fmt.Errorf("invalid numeric value: %w", err)
}
return unitFunc[matches[2]](value), nil
}

type Task struct {
Expand Down
7 changes: 7 additions & 0 deletions crds/archiver.kubedb.com_mariadbarchivers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6204,6 +6204,13 @@ spec:
default: 5
format: int32
type: integer
logRetentionHistoryLimit:
default: 5
format: int32
type: integer
retentionPeriod:
pattern: ^[1-9][0-9]*[dwmy]$
type: string
runtimeSettings:
properties:
container:
Expand Down
7 changes: 7 additions & 0 deletions crds/archiver.kubedb.com_mongodbarchivers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6204,6 +6204,13 @@ spec:
default: 5
format: int32
type: integer
logRetentionHistoryLimit:
default: 5
format: int32
type: integer
retentionPeriod:
pattern: ^[1-9][0-9]*[dwmy]$
type: string
runtimeSettings:
properties:
container:
Expand Down
7 changes: 7 additions & 0 deletions crds/archiver.kubedb.com_mssqlserverarchivers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6204,6 +6204,13 @@ spec:
default: 5
format: int32
type: integer
logRetentionHistoryLimit:
default: 5
format: int32
type: integer
retentionPeriod:
pattern: ^[1-9][0-9]*[dwmy]$
type: string
runtimeSettings:
properties:
container:
Expand Down
7 changes: 7 additions & 0 deletions crds/archiver.kubedb.com_mysqlarchivers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6204,6 +6204,13 @@ spec:
default: 5
format: int32
type: integer
logRetentionHistoryLimit:
default: 5
format: int32
type: integer
retentionPeriod:
pattern: ^[1-9][0-9]*[dwmy]$
type: string
runtimeSettings:
properties:
container:
Expand Down
7 changes: 7 additions & 0 deletions crds/archiver.kubedb.com_postgresarchivers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6204,6 +6204,13 @@ spec:
default: 5
format: int32
type: integer
logRetentionHistoryLimit:
default: 5
format: int32
type: integer
retentionPeriod:
pattern: ^[1-9][0-9]*[dwmy]$
type: string
runtimeSettings:
properties:
container:
Expand Down
Loading