Unverified Commit 697f7e47 authored by Brian Downs's avatar Brian Downs Committed by GitHub

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

parent 0c3f7526
package cmds package cmds
import ( import (
"time"
"github.com/rancher/k3s/pkg/version" "github.com/rancher/k3s/pkg/version"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
...@@ -77,6 +79,17 @@ var EtcdSnapshotFlags = []cli.Flag{ ...@@ -77,6 +79,17 @@ var EtcdSnapshotFlags = []cli.Flag{
Usage: "(db) S3 folder", Usage: "(db) S3 folder",
Destination: &ServerConfig.EtcdS3Folder, 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 { func NewEtcdSnapshotCommand(action func(*cli.Context) error, subcommands []cli.Command) cli.Command {
......
...@@ -3,6 +3,7 @@ package cmds ...@@ -3,6 +3,7 @@ package cmds
import ( import (
"context" "context"
"sync" "sync"
"time"
"github.com/rancher/k3s/pkg/version" "github.com/rancher/k3s/pkg/version"
"github.com/urfave/cli" "github.com/urfave/cli"
...@@ -89,6 +90,8 @@ type Server struct { ...@@ -89,6 +90,8 @@ type Server struct {
EtcdS3BucketName string EtcdS3BucketName string
EtcdS3Region string EtcdS3Region string
EtcdS3Folder string EtcdS3Folder string
EtcdS3Timeout time.Duration
EtcdS3Insecure bool
} }
var ( var (
...@@ -331,6 +334,17 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command { ...@@ -331,6 +334,17 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command {
Usage: "(db) S3 folder", Usage: "(db) S3 folder",
Destination: &ServerConfig.EtcdS3Folder, 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{ cli.StringFlag{
Name: "default-local-storage-path", Name: "default-local-storage-path",
Usage: "(storage) Default local storage path for local provisioner storage class", Usage: "(storage) Default local storage path for local provisioner storage class",
......
...@@ -49,6 +49,8 @@ func commandSetup(app *cli.Context, cfg *cmds.Server, sc *server.Config) (string ...@@ -49,6 +49,8 @@ func commandSetup(app *cli.Context, cfg *cmds.Server, sc *server.Config) (string
sc.ControlConfig.EtcdS3BucketName = cfg.EtcdS3BucketName sc.ControlConfig.EtcdS3BucketName = cfg.EtcdS3BucketName
sc.ControlConfig.EtcdS3Region = cfg.EtcdS3Region sc.ControlConfig.EtcdS3Region = cfg.EtcdS3Region
sc.ControlConfig.EtcdS3Folder = cfg.EtcdS3Folder sc.ControlConfig.EtcdS3Folder = cfg.EtcdS3Folder
sc.ControlConfig.EtcdS3Insecure = cfg.EtcdS3Insecure
sc.ControlConfig.EtcdS3Timeout = cfg.EtcdS3Timeout
sc.ControlConfig.Runtime = &config.ControlRuntime{} sc.ControlConfig.Runtime = &config.ControlRuntime{}
return server.ResolveDataDir(cfg.DataDir) return server.ResolveDataDir(cfg.DataDir)
......
...@@ -149,6 +149,8 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont ...@@ -149,6 +149,8 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
serverConfig.ControlConfig.EtcdS3BucketName = cfg.EtcdS3BucketName serverConfig.ControlConfig.EtcdS3BucketName = cfg.EtcdS3BucketName
serverConfig.ControlConfig.EtcdS3Region = cfg.EtcdS3Region serverConfig.ControlConfig.EtcdS3Region = cfg.EtcdS3Region
serverConfig.ControlConfig.EtcdS3Folder = cfg.EtcdS3Folder serverConfig.ControlConfig.EtcdS3Folder = cfg.EtcdS3Folder
serverConfig.ControlConfig.EtcdS3Insecure = cfg.EtcdS3Insecure
serverConfig.ControlConfig.EtcdS3Timeout = cfg.EtcdS3Timeout
} else { } else {
logrus.Info("ETCD snapshots are disabled") logrus.Info("ETCD snapshots are disabled")
} }
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"net/http" "net/http"
"sort" "sort"
"strings" "strings"
"time"
"github.com/k3s-io/kine/pkg/endpoint" "github.com/k3s-io/kine/pkg/endpoint"
"github.com/rancher/wrangler-api/pkg/generated/controllers/core" "github.com/rancher/wrangler-api/pkg/generated/controllers/core"
...@@ -166,6 +167,8 @@ type Control struct { ...@@ -166,6 +167,8 @@ type Control struct {
EtcdS3BucketName string EtcdS3BucketName string
EtcdS3Region string EtcdS3Region string
EtcdS3Folder string EtcdS3Folder string
EtcdS3Timeout time.Duration
EtcdS3Insecure bool
ServerNodeName string ServerNodeName string
BindAddress string BindAddress string
......
...@@ -1059,7 +1059,7 @@ func (e *ETCD) DeleteSnapshots(ctx context.Context, snapshots []string) error { ...@@ -1059,7 +1059,7 @@ func (e *ETCD) DeleteSnapshots(ctx context.Context, snapshots []string) error {
objectsCh := make(chan minio.ObjectInfo) objectsCh := make(chan minio.ObjectInfo)
ctx, cancel := context.WithTimeout(ctx, defaultS3OpTimeout) ctx, cancel := context.WithTimeout(ctx, e.config.EtcdS3Timeout)
defer cancel() defer cancel()
go func() { go func() {
......
...@@ -14,7 +14,6 @@ import ( ...@@ -14,7 +14,6 @@ import (
"path/filepath" "path/filepath"
"sort" "sort"
"strings" "strings"
"time"
"github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials" "github.com/minio/minio-go/v7/pkg/credentials"
...@@ -23,8 +22,6 @@ import ( ...@@ -23,8 +22,6 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
const defaultS3OpTimeout = time.Second * 30
// S3 maintains state for S3 functionality. // S3 maintains state for S3 functionality.
type S3 struct { type S3 struct {
config *config.Control config *config.Control
...@@ -71,7 +68,7 @@ func NewS3(ctx context.Context, config *config.Control) (*S3, error) { ...@@ -71,7 +68,7 @@ func NewS3(ctx context.Context, config *config.Control) (*S3, error) {
logrus.Infof("Checking if S3 bucket %s exists", config.EtcdS3BucketName) 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() defer cancel()
exists, err := c.BucketExists(ctx, config.EtcdS3BucketName) exists, err := c.BucketExists(ctx, config.EtcdS3BucketName)
...@@ -100,7 +97,7 @@ func (s *S3) upload(ctx context.Context, snapshot string) error { ...@@ -100,7 +97,7 @@ func (s *S3) upload(ctx context.Context, snapshot string) error {
snapshotFileName = basename snapshotFileName = basename
} }
toCtx, cancel := context.WithTimeout(ctx, defaultS3OpTimeout) toCtx, cancel := context.WithTimeout(ctx, s.config.EtcdS3Timeout)
defer cancel() defer cancel()
opts := minio.PutObjectOptions{ opts := minio.PutObjectOptions{
ContentType: "application/zip", ContentType: "application/zip",
...@@ -124,7 +121,7 @@ func (s *S3) Download(ctx context.Context) error { ...@@ -124,7 +121,7 @@ func (s *S3) Download(ctx context.Context) error {
} }
logrus.Debugf("retrieving snapshot: %s", remotePath) logrus.Debugf("retrieving snapshot: %s", remotePath)
toCtx, cancel := context.WithTimeout(ctx, defaultS3OpTimeout) toCtx, cancel := context.WithTimeout(ctx, s.config.EtcdS3Timeout)
defer cancel() defer cancel()
r, err := s.client.GetObject(toCtx, s.config.EtcdS3BucketName, remotePath, minio.GetObjectOptions{}) r, err := s.client.GetObject(toCtx, s.config.EtcdS3BucketName, remotePath, minio.GetObjectOptions{})
...@@ -178,7 +175,7 @@ func (s *S3) snapshotPrefix() string { ...@@ -178,7 +175,7 @@ func (s *S3) snapshotPrefix() string {
func (s *S3) snapshotRetention(ctx context.Context) error { func (s *S3) snapshotRetention(ctx context.Context) error {
var snapshotFiles []minio.ObjectInfo var snapshotFiles []minio.ObjectInfo
toCtx, cancel := context.WithTimeout(ctx, defaultS3OpTimeout) toCtx, cancel := context.WithTimeout(ctx, s.config.EtcdS3Timeout)
defer cancel() defer cancel()
loo := minio.ListObjectsOptions{ loo := minio.ListObjectsOptions{
......
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