-
Notifications
You must be signed in to change notification settings - Fork 498
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
support cleanPolicy for backup CR #3002
Changes from 11 commits
26b1eb8
0bae349
aedf29b
f2d7cc7
69d2cad
31217f9
7d896d9
e484693
a6c7b80
fe9c627
d177a55
32d164f
4e1d38f
c5e77dc
6341abc
337934b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import ( | |
"fmt" | ||
"io" | ||
"os/exec" | ||
"strings" | ||
|
||
"k8s.io/klog" | ||
|
||
|
@@ -67,14 +68,14 @@ func (bo *Options) cleanRemoteBackupData(bucket string, opts []string) error { | |
destBucket := util.NormalizeBucketURI(bucket) | ||
args := util.ConstructArgs(constants.RcloneConfigArg, opts, "deletefile", destBucket, "") | ||
output, err := exec.Command("rclone", args...).CombinedOutput() | ||
if err != nil { | ||
if exitError, ok := err.(*exec.ExitError); ok { | ||
if code := exitError.ExitCode(); code == 3 || code == 4 { | ||
klog.Infof("cluster %s backup %s has already been deleted before", bo, bucket) | ||
return nil | ||
} | ||
} | ||
return fmt.Errorf("cluster %s, execute rclone deletefile command failed, output: %s, err: %v", bo, string(output), err) | ||
if err != nil && !strings.Contains(string(output), "doesn't exist") { | ||
return fmt.Errorf("cluster %s, execute rclone deletefile command to delete archive failed, output: %s, err: %v", bo, string(output), err) | ||
} | ||
|
||
args = util.ConstructArgs(constants.RcloneConfigArg, opts, "deletefile", fmt.Sprintf("%s.tmp", destBucket), "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when will this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After file is archived and uploaded to S3.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this is for backup with |
||
output, err = exec.Command("rclone", args...).CombinedOutput() | ||
if err != nil && !strings.Contains(string(output), "doesn't exist") { | ||
return fmt.Errorf("cluster %s, execute rclone deletefile command to delete tmp file failed, output: %s, err: %v", bo, string(output), err) | ||
} | ||
|
||
klog.Infof("cluster %s backup %s was deleted successfully", bo, bucket) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,6 +323,23 @@ func (bm *BackupManager) performBackup(backup *v1alpha1.Backup, db *sql.DB) erro | |
|
||
remotePath := strings.TrimPrefix(archiveBackupPath, constants.BackupRootPath+"/") | ||
bucketURI := bm.getDestBucketURI(remotePath) | ||
backup.Status.BackupPath = bucketURI | ||
err = bm.StatusUpdater.Update(backup, &v1alpha1.BackupCondition{ | ||
Type: v1alpha1.BackupPrepare, | ||
Status: corev1.ConditionTrue, | ||
}) | ||
if err != nil { | ||
errs = append(errs, err) | ||
uerr := bm.StatusUpdater.Update(backup, &v1alpha1.BackupCondition{ | ||
Type: v1alpha1.BackupFailed, | ||
Status: corev1.ConditionTrue, | ||
Reason: "UpdateBackupPathFailed", | ||
Message: err.Error(), | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why setting this condition if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copyed from https://github.com/pingcap/tidb-operator/blob/master/cmd/backup-manager/app/backup/manager.go#L159 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO it's meaningless to call our current architecture relies on our backup job to update does it cause problems when the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we omit this error, we might be unable to clean files on the Cloud when we delete this CR because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but the (if this is not true, I think we should fix it. one more API call does not help) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So should we omit this error? What about BR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we didn't omit the error, the job fails |
||
errs = append(errs, uerr) | ||
return errorutils.NewAggregate(errs) | ||
} | ||
|
||
err = bm.backupDataToRemote(archiveBackupPath, bucketURI, opts) | ||
if err != nil { | ||
errs = append(errs, err) | ||
|
@@ -342,7 +359,6 @@ func (bm *BackupManager) performBackup(backup *v1alpha1.Backup, db *sql.DB) erro | |
|
||
finish := time.Now() | ||
|
||
backup.Status.BackupPath = bucketURI | ||
backup.Status.TimeStarted = metav1.Time{Time: started} | ||
backup.Status.TimeCompleted = metav1.Time{Time: finish} | ||
backup.Status.BackupSize = size | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,7 +288,7 @@ func newBackup() *v1alpha1.Backup { | |
}, | ||
StorageClassName: pointer.StringPtr("local-storage"), | ||
StorageSize: "1Gi", | ||
CleanData: true, | ||
CleanPolicy: v1alpha1.CleanPolicyTypeDelete, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add tests for other values? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will add tests later |
||
}, | ||
} | ||
} |
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.
why changing this back?
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.
Because according to test, this error code is not accurate. When
rclone
returnsdir doesn't exist
error the exit code is 1. May the last time I forgot to usehack/local-up-operator.sh
to update operator.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.
maybe
rclone delete
is a better command in this scenariohttps://rclone.org/commands/rclone_delete/
in my testing, it succeeds if no file found at the specified path
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. It won't even return error. Should we use this command?
C.C. @DanielZhangQD
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.
It's OK if the file can be removed if exist.
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.
Revise to
rclone delete
in 4e1d38f