-
Notifications
You must be signed in to change notification settings - Fork 127
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
ETCD-636: add automated backup sidecar #1287
Changes from all commits
23f4dc0
6dea950
3834e36
4f43535
eb7ebe1
5f88f3c
0ae4b22
4c8ff99
9181812
371fad6
e6e335a
726bcbe
b288cc0
c631a66
19d4099
9987b56
26deca1
a960611
a7d9e5c
53c0a49
4c9ccc5
b4f9919
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: config.openshift.io/v1alpha1 | ||
kind: Backup | ||
metadata: | ||
name: default | ||
annotations: | ||
default: "true" | ||
spec: | ||
etcd: | ||
schedule: "20 4 * * *" | ||
timeZone: "UTC" | ||
retentionPolicy: | ||
retentionType: RetentionNumber | ||
retentionNumber: | ||
maxNumberOfBackups: 5 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package backuprestore | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
|
||
"k8s.io/klog/v2" | ||
|
||
"github.com/adhocore/gronx/pkg/tasker" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
type backupNoConfig struct { | ||
schedule string | ||
timeZone string | ||
scheduler *tasker.Tasker | ||
backupOptions | ||
} | ||
|
||
func NewBackupNoConfigCommand(errOut io.Writer) *cobra.Command { | ||
backupNoConf := &backupNoConfig{ | ||
backupOptions: backupOptions{errOut: errOut}, | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "backup-server", | ||
Short: "Backs up a snapshot of etcd database and static pod resources without config", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
must := func(fn func() error) { | ||
if err := fn(); err != nil { | ||
if cmd.HasParent() { | ||
klog.Fatal(err) | ||
} | ||
fmt.Fprint(backupNoConf.errOut, err.Error()) | ||
} | ||
} | ||
|
||
must(backupNoConf.Validate) | ||
must(backupNoConf.Run) | ||
}, | ||
} | ||
backupNoConf.AddFlags(cmd.Flags()) | ||
return cmd | ||
} | ||
|
||
func (b *backupNoConfig) AddFlags(fs *pflag.FlagSet) { | ||
fs.StringVar(&b.schedule, "schedule", "", "schedule specifies the cron schedule to run the backup") | ||
fs.StringVar(&b.timeZone, "timezone", "", "timezone specifies the timezone of the cron schedule to run the backup") | ||
|
||
b.backupOptions.AddFlags(fs) | ||
} | ||
|
||
func (b *backupNoConfig) Validate() error { | ||
return b.backupOptions.Validate() | ||
} | ||
|
||
func (b *backupNoConfig) Run() 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. You don't need to use this scheduler here, but rather you want to just write a simple controller, similar in concept to https://github.com/kubernetes/kubernetes/blob/master/pkg/controller/cronjob/cronjob_controllerv2.go. The main bits are:
|
||
b.scheduler = tasker.New(tasker.Option{ | ||
Verbose: true, | ||
Tz: b.timeZone, | ||
}) | ||
|
||
err := b.scheduleBackup() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
doneCh := make(chan struct{}) | ||
go func() { | ||
b.scheduler.Run() | ||
doneCh <- struct{}{} | ||
}() | ||
|
||
<-doneCh | ||
return nil | ||
} | ||
|
||
func (b *backupNoConfig) scheduleBackup() error { | ||
var err error | ||
b.scheduler.Task(b.schedule, func(ctx context.Context) (int, error) { | ||
err = backup(&b.backupOptions) | ||
return 0, err | ||
}, false) | ||
|
||
return err | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Still have to review to this later and see if all of this aligns with what's outlined in the enhancement, but manifest changes related to this feature like this need to be feature gated and can't be in GA by default.