[Engine-1.21] - Add etcd s3 timeout (#4207) (#4229)

pull/4237/head
Brian Downs 2021-10-18 10:45:47 -07:00 committed by GitHub
parent 0c3f752620
commit 697f7e471a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 8 deletions

View File

@ -1,6 +1,8 @@
package cmds
import (
"time"
"github.com/rancher/k3s/pkg/version"
"github.com/urfave/cli"
)
@ -77,6 +79,17 @@ var EtcdSnapshotFlags = []cli.Flag{
Usage: "(db) S3 folder",
Destination: &ServerConfig.EtcdS3Folder,
},
&cli.BoolFlag{
Name: "s3-insecure,etcd-s3-insecure",
Usage: "(db) Disables S3 over HTTPS",
Destination: &ServerConfig.EtcdS3Insecure,
},
&cli.DurationFlag{
Name: "s3-timeout,etcd-s3-timeout",
Usage: "(db) S3 timeout",
Destination: &ServerConfig.EtcdS3Timeout,
Value: 30 * time.Second,
},
}
func NewEtcdSnapshotCommand(action func(*cli.Context) error, subcommands []cli.Command) cli.Command {

View File

@ -3,6 +3,7 @@ package cmds
import (
"context"
"sync"
"time"
"github.com/rancher/k3s/pkg/version"
"github.com/urfave/cli"
@ -89,6 +90,8 @@ type Server struct {
EtcdS3BucketName string
EtcdS3Region string
EtcdS3Folder string
EtcdS3Timeout time.Duration
EtcdS3Insecure bool
}
var (
@ -331,6 +334,17 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command {
Usage: "(db) S3 folder",
Destination: &ServerConfig.EtcdS3Folder,
},
&cli.BoolFlag{
Name: "etcd-s3-insecure",
Usage: "(db) Disables S3 over HTTPS",
Destination: &ServerConfig.EtcdS3Insecure,
},
&cli.DurationFlag{
Name: "etcd-s3-timeout",
Usage: "(db) S3 timeout",
Destination: &ServerConfig.EtcdS3Timeout,
Value: 30 * time.Second,
},
cli.StringFlag{
Name: "default-local-storage-path",
Usage: "(storage) Default local storage path for local provisioner storage class",

View File

@ -49,6 +49,8 @@ func commandSetup(app *cli.Context, cfg *cmds.Server, sc *server.Config) (string
sc.ControlConfig.EtcdS3BucketName = cfg.EtcdS3BucketName
sc.ControlConfig.EtcdS3Region = cfg.EtcdS3Region
sc.ControlConfig.EtcdS3Folder = cfg.EtcdS3Folder
sc.ControlConfig.EtcdS3Insecure = cfg.EtcdS3Insecure
sc.ControlConfig.EtcdS3Timeout = cfg.EtcdS3Timeout
sc.ControlConfig.Runtime = &config.ControlRuntime{}
return server.ResolveDataDir(cfg.DataDir)

View File

@ -149,6 +149,8 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
serverConfig.ControlConfig.EtcdS3BucketName = cfg.EtcdS3BucketName
serverConfig.ControlConfig.EtcdS3Region = cfg.EtcdS3Region
serverConfig.ControlConfig.EtcdS3Folder = cfg.EtcdS3Folder
serverConfig.ControlConfig.EtcdS3Insecure = cfg.EtcdS3Insecure
serverConfig.ControlConfig.EtcdS3Timeout = cfg.EtcdS3Timeout
} else {
logrus.Info("ETCD snapshots are disabled")
}

View File

@ -8,6 +8,7 @@ import (
"net/http"
"sort"
"strings"
"time"
"github.com/k3s-io/kine/pkg/endpoint"
"github.com/rancher/wrangler-api/pkg/generated/controllers/core"
@ -166,6 +167,8 @@ type Control struct {
EtcdS3BucketName string
EtcdS3Region string
EtcdS3Folder string
EtcdS3Timeout time.Duration
EtcdS3Insecure bool
ServerNodeName string
BindAddress string

View File

@ -1059,7 +1059,7 @@ func (e *ETCD) DeleteSnapshots(ctx context.Context, snapshots []string) error {
objectsCh := make(chan minio.ObjectInfo)
ctx, cancel := context.WithTimeout(ctx, defaultS3OpTimeout)
ctx, cancel := context.WithTimeout(ctx, e.config.EtcdS3Timeout)
defer cancel()
go func() {

View File

@ -14,7 +14,6 @@ import (
"path/filepath"
"sort"
"strings"
"time"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
@ -23,8 +22,6 @@ import (
"github.com/sirupsen/logrus"
)
const defaultS3OpTimeout = time.Second * 30
// S3 maintains state for S3 functionality.
type S3 struct {
config *config.Control
@ -71,7 +68,7 @@ func NewS3(ctx context.Context, config *config.Control) (*S3, error) {
logrus.Infof("Checking if S3 bucket %s exists", config.EtcdS3BucketName)
ctx, cancel := context.WithTimeout(ctx, defaultS3OpTimeout)
ctx, cancel := context.WithTimeout(ctx, config.EtcdS3Timeout)
defer cancel()
exists, err := c.BucketExists(ctx, config.EtcdS3BucketName)
@ -100,7 +97,7 @@ func (s *S3) upload(ctx context.Context, snapshot string) error {
snapshotFileName = basename
}
toCtx, cancel := context.WithTimeout(ctx, defaultS3OpTimeout)
toCtx, cancel := context.WithTimeout(ctx, s.config.EtcdS3Timeout)
defer cancel()
opts := minio.PutObjectOptions{
ContentType: "application/zip",
@ -124,7 +121,7 @@ func (s *S3) Download(ctx context.Context) error {
}
logrus.Debugf("retrieving snapshot: %s", remotePath)
toCtx, cancel := context.WithTimeout(ctx, defaultS3OpTimeout)
toCtx, cancel := context.WithTimeout(ctx, s.config.EtcdS3Timeout)
defer cancel()
r, err := s.client.GetObject(toCtx, s.config.EtcdS3BucketName, remotePath, minio.GetObjectOptions{})
@ -178,7 +175,7 @@ func (s *S3) snapshotPrefix() string {
func (s *S3) snapshotRetention(ctx context.Context) error {
var snapshotFiles []minio.ObjectInfo
toCtx, cancel := context.WithTimeout(ctx, defaultS3OpTimeout)
toCtx, cancel := context.WithTimeout(ctx, s.config.EtcdS3Timeout)
defer cancel()
loo := minio.ListObjectsOptions{