Skip to content

Commit

Permalink
more restricted subCommand check
Browse files Browse the repository at this point in the history
  • Loading branch information
RidRisR committed Sep 25, 2024
1 parent 90cf8f2 commit a31daf1
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/backup-manager/app/backup/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ func (bm *Manager) stopLogBackup(ctx context.Context, backup *v1alpha1.Backup) (
return updateStatus, "", nil
}

// pauseLogBackup stops log backup.
// pauseLogBackup pauses log backup.
func (bm *Manager) pauseLogBackup(ctx context.Context, backup *v1alpha1.Backup) (*controller.BackupUpdateStatus, string, error) {
started := time.Now()

Expand Down
9 changes: 7 additions & 2 deletions docs/api-references/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ Default is current timestamp.</p>
<td>
<code>logSubcommand</code></br>
<em>
string
<a href="#logsubcommandtype">
LogSubCommandType
</a>
</em>
</td>
<td>
Expand Down Expand Up @@ -4248,7 +4250,9 @@ Default is current timestamp.</p>
<td>
<code>logSubcommand</code></br>
<em>
string
<a href="#logsubcommandtype">
LogSubCommandType
</a>
</em>
</td>
<td>
Expand Down Expand Up @@ -8914,6 +8918,7 @@ BackupConditionType
<p>
(<em>Appears on:</em>
<a href="#backupcondition">BackupCondition</a>,
<a href="#backupspec">BackupSpec</a>,
<a href="#logsubcommandstatus">LogSubCommandStatus</a>)
</p>
<p>
Expand Down
15 changes: 15 additions & 0 deletions manifests/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,11 @@ spec:
logStop:
type: boolean
logSubcommand:
enum:
- ""
- log-start
- log-stop
- log-pause
type: string
logTruncateUntil:
type: string
Expand Down Expand Up @@ -4356,6 +4361,11 @@ spec:
logStop:
type: boolean
logSubcommand:
enum:
- ""
- log-start
- log-stop
- log-pause
type: string
logTruncateUntil:
type: string
Expand Down Expand Up @@ -6708,6 +6718,11 @@ spec:
logStop:
type: boolean
logSubcommand:
enum:
- ""
- log-start
- log-stop
- log-pause
type: string
logTruncateUntil:
type: string
Expand Down
5 changes: 5 additions & 0 deletions manifests/crd/v1/pingcap.com_backups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,11 @@ spec:
logStop:
type: boolean
logSubcommand:
enum:
- ""
- log-start
- log-stop
- log-pause
type: string
logTruncateUntil:
type: string
Expand Down
10 changes: 10 additions & 0 deletions manifests/crd/v1/pingcap.com_backupschedules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,11 @@ spec:
logStop:
type: boolean
logSubcommand:
enum:
- ""
- log-start
- log-stop
- log-pause
type: string
logTruncateUntil:
type: string
Expand Down Expand Up @@ -4356,6 +4361,11 @@ spec:
logStop:
type: boolean
logSubcommand:
enum:
- ""
- log-start
- log-stop
- log-pause
type: string
logTruncateUntil:
type: string
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/pingcap/v1alpha1/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,15 @@ func ParseLogBackupSubcommand(backup *Backup) LogSubCommandType {
switch backup.Spec.LogSubcommand {
case "":
fallthrough
case "log-start":
case LogStartCommand:
if IsLogBackupAlreadyPaused(backup) {
subCommand = LogResumeCommand
} else {
subCommand = LogStartCommand
}
case "log-stop":
case LogStopCommand:
subCommand = LogStopCommand
case "log-pause":
case LogPauseCommand:
subCommand = LogPauseCommand
default:
return LogUnknownCommand
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/pingcap/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2181,7 +2181,8 @@ type BackupSpec struct {
CommitTs string `json:"commitTs,omitempty"`
// Subcommand is the subcommand for BR, such as start, stop, pause etc.
// +optional
LogSubcommand string `json:"logSubcommand,omitempty"`
// +kubebuilder:validation:Enum:="";"log-start";"log-stop";"log-pause"
LogSubcommand LogSubCommandType `json:"logSubcommand,omitempty"`
// LogTruncateUntil is log backup truncate until timestamp.
// Format supports TSO or datetime, e.g. '400036290571534337', '2018-05-11 01:42:23'.
// +optional
Expand Down

0 comments on commit a31daf1

Please sign in to comment.