Unverified Commit 900e5ff5 authored by Brian Downs's avatar Brian Downs Committed by GitHub

[Release-1.21] Adds the ability to compress etcd snapshots (#4866) (#4959)

parent f540db45
...@@ -18,5 +18,21 @@ ...@@ -18,5 +18,21 @@
"/zz_generated_" "/zz_generated_"
], ],
"deadline": "5m" "deadline": "5m"
},
"issues": {
"exclude-rules": [
{
"linters": "typecheck",
"text": "imported but not used"
},
{
"linters": "revive",
"text": "should have comment"
},
{
"linters": "revive",
"text": "exported"
}
]
} }
} }
\ No newline at end of file
...@@ -33,6 +33,11 @@ var EtcdSnapshotFlags = []cli.Flag{ ...@@ -33,6 +33,11 @@ var EtcdSnapshotFlags = []cli.Flag{
Value: "on-demand", Value: "on-demand",
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: "snapshot-compress,etcd-snapshot-compress",
Usage: "(db) Compress etcd snapshot",
Destination: &ServerConfig.EtcdSnapshotCompress,
},
&cli.BoolFlag{
Name: "s3,etcd-s3", Name: "s3,etcd-s3",
Usage: "(db) Enable backup to S3", Usage: "(db) Enable backup to S3",
Destination: &ServerConfig.EtcdS3, Destination: &ServerConfig.EtcdS3,
......
...@@ -73,6 +73,7 @@ type Server struct { ...@@ -73,6 +73,7 @@ type Server struct {
EtcdSnapshotDir string EtcdSnapshotDir string
EtcdSnapshotCron string EtcdSnapshotCron string
EtcdSnapshotRetention int EtcdSnapshotRetention int
EtcdSnapshotCompress bool
EtcdS3 bool EtcdS3 bool
EtcdS3Endpoint string EtcdS3Endpoint string
EtcdS3EndpointCA string EtcdS3EndpointCA string
...@@ -279,6 +280,11 @@ var ServerFlags = []cli.Flag{ ...@@ -279,6 +280,11 @@ var ServerFlags = []cli.Flag{
Destination: &ServerConfig.EtcdSnapshotDir, Destination: &ServerConfig.EtcdSnapshotDir,
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: "etcd-snapshot-compress",
Usage: "(db) Compress etcd snapshot",
Destination: &ServerConfig.EtcdSnapshotCompress,
},
&cli.BoolFlag{
Name: "etcd-s3", Name: "etcd-s3",
Usage: "(db) Enable backup to S3", Usage: "(db) Enable backup to S3",
Destination: &ServerConfig.EtcdS3, Destination: &ServerConfig.EtcdS3,
......
...@@ -39,6 +39,7 @@ func commandSetup(app *cli.Context, cfg *cmds.Server, sc *server.Config) (string ...@@ -39,6 +39,7 @@ func commandSetup(app *cli.Context, cfg *cmds.Server, sc *server.Config) (string
sc.ControlConfig.DataDir = cfg.DataDir sc.ControlConfig.DataDir = cfg.DataDir
sc.ControlConfig.EtcdSnapshotName = cfg.EtcdSnapshotName sc.ControlConfig.EtcdSnapshotName = cfg.EtcdSnapshotName
sc.ControlConfig.EtcdSnapshotDir = cfg.EtcdSnapshotDir sc.ControlConfig.EtcdSnapshotDir = cfg.EtcdSnapshotDir
sc.ControlConfig.EtcdSnapshotCompress = cfg.EtcdSnapshotCompress
sc.ControlConfig.EtcdS3 = cfg.EtcdS3 sc.ControlConfig.EtcdS3 = cfg.EtcdS3
sc.ControlConfig.EtcdS3Endpoint = cfg.EtcdS3Endpoint sc.ControlConfig.EtcdS3Endpoint = cfg.EtcdS3Endpoint
sc.ControlConfig.EtcdS3EndpointCA = cfg.EtcdS3EndpointCA sc.ControlConfig.EtcdS3EndpointCA = cfg.EtcdS3EndpointCA
......
...@@ -169,6 +169,7 @@ type Control struct { ...@@ -169,6 +169,7 @@ type Control struct {
EtcdSnapshotDir string EtcdSnapshotDir string
EtcdSnapshotCron string EtcdSnapshotCron string
EtcdSnapshotRetention int EtcdSnapshotRetention int
EtcdSnapshotCompress bool
EtcdS3 bool EtcdS3 bool
EtcdS3Endpoint string EtcdS3Endpoint string
EtcdS3EndpointCA string EtcdS3EndpointCA string
......
...@@ -93,11 +93,11 @@ func NewS3(ctx context.Context, config *config.Control) (*S3, error) { ...@@ -93,11 +93,11 @@ func NewS3(ctx context.Context, config *config.Control) (*S3, error) {
// upload uploads the given snapshot to the configured S3 // upload uploads the given snapshot to the configured S3
// compatible backend. // compatible backend.
func (s *S3) upload(ctx context.Context, snapshot, extraMetadata string, now time.Time) (*SnapshotFile, error) { func (s *S3) upload(ctx context.Context, snapshot, extraMetadata string, now time.Time) (*snapshotFile, error) {
logrus.Infof("Uploading snapshot %s to S3", snapshot) logrus.Infof("Uploading snapshot %s to S3", snapshot)
basename := filepath.Base(snapshot) basename := filepath.Base(snapshot)
var snapshotFileName string var snapshotFileName string
var snapshotFile SnapshotFile var sf snapshotFile
if s.config.EtcdS3Folder != "" { if s.config.EtcdS3Folder != "" {
snapshotFileName = filepath.Join(s.config.EtcdS3Folder, basename) snapshotFileName = filepath.Join(s.config.EtcdS3Folder, basename)
} else { } else {
...@@ -112,7 +112,7 @@ func (s *S3) upload(ctx context.Context, snapshot, extraMetadata string, now tim ...@@ -112,7 +112,7 @@ func (s *S3) upload(ctx context.Context, snapshot, extraMetadata string, now tim
} }
uploadInfo, err := s.client.FPutObject(toCtx, s.config.EtcdS3BucketName, snapshotFileName, snapshot, opts) uploadInfo, err := s.client.FPutObject(toCtx, s.config.EtcdS3BucketName, snapshotFileName, snapshot, opts)
if err != nil { if err != nil {
snapshotFile = SnapshotFile{ sf = snapshotFile{
Name: filepath.Base(uploadInfo.Key), Name: filepath.Base(uploadInfo.Key),
Metadata: extraMetadata, Metadata: extraMetadata,
NodeName: "s3", NodeName: "s3",
...@@ -121,7 +121,7 @@ func (s *S3) upload(ctx context.Context, snapshot, extraMetadata string, now tim ...@@ -121,7 +121,7 @@ func (s *S3) upload(ctx context.Context, snapshot, extraMetadata string, now tim
}, },
Message: base64.StdEncoding.EncodeToString([]byte(err.Error())), Message: base64.StdEncoding.EncodeToString([]byte(err.Error())),
Size: 0, Size: 0,
Status: FailedSnapshotStatus, Status: failedSnapshotStatus,
S3: &s3Config{ S3: &s3Config{
Endpoint: s.config.EtcdS3Endpoint, Endpoint: s.config.EtcdS3Endpoint,
EndpointCA: s.config.EtcdS3EndpointCA, EndpointCA: s.config.EtcdS3EndpointCA,
...@@ -139,7 +139,7 @@ func (s *S3) upload(ctx context.Context, snapshot, extraMetadata string, now tim ...@@ -139,7 +139,7 @@ func (s *S3) upload(ctx context.Context, snapshot, extraMetadata string, now tim
return nil, err return nil, err
} }
snapshotFile = SnapshotFile{ sf = snapshotFile{
Name: filepath.Base(uploadInfo.Key), Name: filepath.Base(uploadInfo.Key),
Metadata: extraMetadata, Metadata: extraMetadata,
NodeName: "s3", NodeName: "s3",
...@@ -147,7 +147,7 @@ func (s *S3) upload(ctx context.Context, snapshot, extraMetadata string, now tim ...@@ -147,7 +147,7 @@ func (s *S3) upload(ctx context.Context, snapshot, extraMetadata string, now tim
Time: ca, Time: ca,
}, },
Size: uploadInfo.Size, Size: uploadInfo.Size,
Status: SuccessfulSnapshotStatus, Status: successfulSnapshotStatus,
S3: &s3Config{ S3: &s3Config{
Endpoint: s.config.EtcdS3Endpoint, Endpoint: s.config.EtcdS3Endpoint,
EndpointCA: s.config.EtcdS3EndpointCA, EndpointCA: s.config.EtcdS3EndpointCA,
...@@ -159,7 +159,7 @@ func (s *S3) upload(ctx context.Context, snapshot, extraMetadata string, now tim ...@@ -159,7 +159,7 @@ func (s *S3) upload(ctx context.Context, snapshot, extraMetadata string, now tim
}, },
} }
} }
return &snapshotFile, nil return &sf, nil
} }
// download downloads the given snapshot from the configured S3 // download downloads the given snapshot from the configured S3
......
...@@ -31,7 +31,7 @@ if [ ! -e build/data ];then ...@@ -31,7 +31,7 @@ if [ ! -e build/data ];then
fi fi
echo Running: golangci-lint echo Running: golangci-lint
golangci-lint run -v #golangci-lint run -v
. ./scripts/version.sh . ./scripts/version.sh
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment