github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/apis/dataprotection/v1alpha1/backupschedule_types.go (about)

     1  /*
     2  Copyright (C) 2022-2023 ApeCloud Co., Ltd
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1alpha1
    18  
    19  import (
    20  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    21  )
    22  
    23  // BackupScheduleSpec defines the desired state of BackupSchedule.
    24  type BackupScheduleSpec struct {
    25  	// Which backupPolicy is applied to perform this backup.
    26  	// +kubebuilder:validation:Required
    27  	// +kubebuilder:validation:Pattern:=`^[a-z0-9]([a-z0-9\.\-]*[a-z0-9])?$`
    28  	BackupPolicyName string `json:"backupPolicyName"`
    29  
    30  	// startingDeadlineMinutes defines the deadline in minutes for starting the
    31  	// backup workload if it misses scheduled time for any reason.
    32  	// +optional
    33  	// +kubebuilder:validation:Minimum=0
    34  	// +kubebuilder:validation:Maximum=1440
    35  	StartingDeadlineMinutes *int64 `json:"startingDeadlineMinutes,omitempty"`
    36  
    37  	// schedules defines the list of backup schedules.
    38  	// +kubebuilder:validation:Required
    39  	// +kubebuilder:validation:MinItems=1
    40  	Schedules []SchedulePolicy `json:"schedules"`
    41  }
    42  
    43  type SchedulePolicy struct {
    44  	// enabled specifies whether the backup schedule is enabled or not.
    45  	// +optional
    46  	Enabled *bool `json:"enabled,omitempty"`
    47  
    48  	// backupMethod specifies the backup method name that is defined in backupPolicy.
    49  	// +kubebuilder:validation:Required
    50  	BackupMethod string `json:"backupMethod"`
    51  
    52  	// the cron expression for schedule, the timezone is in UTC.
    53  	// see https://en.wikipedia.org/wiki/Cron.
    54  	// +kubebuilder:validation:Required
    55  	CronExpression string `json:"cronExpression"`
    56  
    57  	// retentionPeriod determines a duration up to which the backup should be kept.
    58  	// controller will remove all backups that are older than the RetentionPeriod.
    59  	// For example, RetentionPeriod of `30d` will keep only the backups of last 30 days.
    60  	// Sample duration format:
    61  	// - years: 	2y
    62  	// - months: 	6mo
    63  	// - days: 		30d
    64  	// - hours: 	12h
    65  	// - minutes: 	30m
    66  	// You can also combine the above durations. For example: 30d12h30m
    67  	// +optional
    68  	// +kubebuilder:default="7d"
    69  	RetentionPeriod RetentionPeriod `json:"retentionPeriod,omitempty"`
    70  }
    71  
    72  // BackupScheduleStatus defines the observed state of BackupSchedule.
    73  type BackupScheduleStatus struct {
    74  	// phase describes the phase of the BackupSchedule.
    75  	// +optional
    76  	Phase BackupSchedulePhase `json:"phase,omitempty"`
    77  
    78  	// observedGeneration is the most recent generation observed for this
    79  	// BackupSchedule. It refers to the BackupSchedule's generation, which is
    80  	// updated on mutation by the API Server.
    81  	// +optional
    82  	ObservedGeneration int64 `json:"observedGeneration,omitempty"`
    83  
    84  	// failureReason is an error that caused the backup to fail.
    85  	// +optional
    86  	FailureReason string `json:"failureReason,omitempty"`
    87  
    88  	// schedules describes the status of each schedule.
    89  	// +optional
    90  	Schedules map[string]ScheduleStatus `json:"schedules,omitempty"`
    91  }
    92  
    93  // BackupSchedulePhase defines the phase of BackupSchedule
    94  type BackupSchedulePhase string
    95  
    96  const (
    97  	// BackupSchedulePhaseAvailable means the backup schedule is available.
    98  	BackupSchedulePhaseAvailable BackupSchedulePhase = "Available"
    99  
   100  	// BackupSchedulePhaseFailed means the backup schedule is failed.
   101  	BackupSchedulePhaseFailed BackupSchedulePhase = "Failed"
   102  )
   103  
   104  // ScheduleStatus defines the status of each schedule.
   105  type ScheduleStatus struct {
   106  	// phase describes the phase of the schedule.
   107  	// +optional
   108  	Phase SchedulePhase `json:"phase,omitempty"`
   109  
   110  	// failureReason is an error that caused the backup to fail.
   111  	// +optional
   112  	FailureReason string `json:"failureReason,omitempty"`
   113  
   114  	// lastScheduleTime records the last time the backup was scheduled.
   115  	// +optional
   116  	LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty"`
   117  
   118  	// lastSuccessfulTime records the last time the backup was successfully completed.
   119  	// +optional
   120  	LastSuccessfulTime *metav1.Time `json:"lastSuccessfulTime,omitempty"`
   121  }
   122  
   123  // SchedulePhase defines the phase of schedule
   124  type SchedulePhase string
   125  
   126  const (
   127  	ScheduleRunning SchedulePhase = "Running"
   128  	ScheduleFailed  SchedulePhase = "Failed"
   129  )
   130  
   131  // +genclient
   132  // +k8s:openapi-gen=true
   133  // +kubebuilder:object:root=true
   134  // +kubebuilder:subresource:status
   135  // +kubebuilder:resource:categories={kubeblocks},scope=Namespaced,shortName=bs
   136  // +kubebuilder:printcolumn:name="STATUS",type=string,JSONPath=`.status.phase`
   137  // +kubebuilder:printcolumn:name="AGE",type=date,JSONPath=`.metadata.creationTimestamp`
   138  
   139  // BackupSchedule is the Schema for the backupschedules API.
   140  type BackupSchedule struct {
   141  	metav1.TypeMeta   `json:",inline"`
   142  	metav1.ObjectMeta `json:"metadata,omitempty"`
   143  
   144  	Spec   BackupScheduleSpec   `json:"spec,omitempty"`
   145  	Status BackupScheduleStatus `json:"status,omitempty"`
   146  }
   147  
   148  // +kubebuilder:object:root=true
   149  
   150  // BackupScheduleList contains a list of BackupSchedule.
   151  type BackupScheduleList struct {
   152  	metav1.TypeMeta `json:",inline"`
   153  	metav1.ListMeta `json:"metadata,omitempty"`
   154  	Items           []BackupSchedule `json:"items"`
   155  }
   156  
   157  func init() {
   158  	SchemeBuilder.Register(&BackupSchedule{}, &BackupScheduleList{})
   159  }