-
Notifications
You must be signed in to change notification settings - Fork 494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
br: a more straight forward operator interface #5710
base: master
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5710 +/- ##
========================================
Coverage 61.47% 61.47%
========================================
Files 235 235
Lines 30653 30825 +172
========================================
+ Hits 18843 18951 +108
- Misses 9920 9963 +43
- Partials 1890 1911 +21
|
if backup.Spec.LogStop { | ||
switch backup.Spec.LogSubcommand { | ||
case "log-start": | ||
if IsLogBackupAlreadyPaused(backup) { | ||
return LogResumeCommand | ||
} | ||
return LogStartCommand | ||
case "log-stop": | ||
return LogStopCommand | ||
} | ||
if backup.Spec.LogTruncateUntil != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it needed to compatible with the old fields?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, user shouldn't mix up these two interface to avoid mistakes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the old existing Backup user MUST update their pipeline to use these new fields, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we don't want handle corner case like:
Spec:
logSubcommand: log-start
logStop: true
```
BTW, I am fresh to operator. Would there be any problem?
I tested updating operator online while a pitr task is running.
Seems there wouldn't be any problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to keep compatible with the old fields, because tidbcloud depends on current implementation. I think we can make old fields have higher priority. For example:
if backup.Spec.LogStop
return LogStopCommand
if backup.Spec.LogTruncateUntil != "" && backup.Spec.LogTruncateUntil != backup.Status.LogSuccessTruncateUntil
return LogTruncateCommand
switch backup.Spec.LogSubcommand
...
// default command is log start
return LogStartCommand
@@ -145,6 +145,7 @@ func (c *Controller) sync(key string) error { | |||
return err | |||
} | |||
|
|||
klog.Infof("Syncing Backup %s/%s", ns, name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This log should be debug level.
"resume", | ||
fmt.Sprintf("--task-name=%s", backup.Name), | ||
} | ||
// if bo.CommitTS != "" && bo.CommitTS != "0" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest to remove these comment codes. They seem useless.
if backup.Spec.LogStop { | ||
switch backup.Spec.LogSubcommand { | ||
case "log-start": | ||
if IsLogBackupAlreadyPaused(backup) { | ||
return LogResumeCommand | ||
} | ||
return LogStartCommand | ||
case "log-stop": | ||
return LogStopCommand | ||
} | ||
if backup.Spec.LogTruncateUntil != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to keep compatible with the old fields, because tidbcloud depends on current implementation. I think we can make old fields have higher priority. For example:
if backup.Spec.LogStop
return LogStopCommand
if backup.Spec.LogTruncateUntil != "" && backup.Spec.LogTruncateUntil != backup.Status.LogSuccessTruncateUntil
return LogTruncateCommand
switch backup.Spec.LogSubcommand
...
// default command is log start
return LogStartCommand
|
||
func IsBackupPaused(backup *Backup) bool { | ||
if backup.Spec.Mode == BackupModeLog { | ||
return IsLogBackupSubCommandOntheCondition(backup, BackupPaused) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems log backup sub command condition has no BackupPaused
status
@@ -230,6 +230,10 @@ func (c *Controller) updateBackup(cur interface{}) { | |||
return | |||
} | |||
|
|||
if newBackup.Spec.Mode == v1alpha1.BackupModeLog && newBackup.Spec.LogSubcommand == string(v1alpha1.LogStartCommand) && v1alpha1.IsBackupPaused(newBackup) { | |||
newBackup.Spec.LogSubcommand = string(v1alpha1.LogResumeCommand) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why add this hack logic. We shouldn't modify the spec
fields even the user inputs wrong value.
return IsLogBackupSubCommandOntheCondition(backup, BackupPaused) | ||
} | ||
_, condition := GetBackupCondition(&backup.Status, BackupPaused) | ||
return condition != nil && condition.Status == corev1.ConditionTrue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only means the log backup is ever paused, not means it is paused. I guess you want to check if the log backup is paused. Only backup.Status.Phase
represents the current status.
@@ -392,3 +416,13 @@ func IsLogBackupAlreadyTruncate(backup *Backup) bool { | |||
func IsLogBackupAlreadyStop(backup *Backup) bool { | |||
return backup.Spec.Mode == BackupModeLog && backup.Status.Phase == BackupStopped | |||
} | |||
|
|||
// IsLogBackupAlreadyStop return whether log backup has already paused. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// IsLogBackupAlreadyStop return whether log backup has already paused. | |
// IsLogBackupAlreadyPaused return whether log backup has already paused. |
return backup.Spec.Mode == BackupModeLog && backup.Status.Phase == BackupPaused | ||
} | ||
|
||
// IsLogBackupAlreadyRestart return whether log backup has already resumed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// IsLogBackupAlreadyRestart return whether log backup has already resumed. | |
// IsLogBackupAlreadyRunning return whether log backup has already resumed. |
For the state machine figure, please also add the scenarios where the state change due to gc-ttl. @RidRisR |
Co-authored-by: WangLe1321 <[email protected]>
Co-authored-by: WangLe1321 <[email protected]>
What problem does this PR solve?
Closes #5699
What is changed and how does it work?
Now, the crd to control log backup would loops like
(If no subcommand is provided, the default value is
log-start
)If the task is not created before:
log-start: would start the task
log-pause/log-stop: would not run until start finished
If the task is running:
log-start: would skip and do nothing
log-pause: would pause the task
log-stop:would stop the task
If the task is paused:
log-start: would resume the task
log-pause: would skip and do nothing
log-stop: would stop the task
If the task is stopped:
log-start/log-pause/log-stop: would do nothing
Code changes
Tests
Side effects
Related changes
Release Notes
Please refer to Release Notes Language Style Guide before writing the release note.