Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
9c523618
Unverified
Commit
9c523618
authored
Oct 18, 2021
by
Brian Downs
Committed by
GitHub
Oct 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Release-1.20] - Add etcd s3 timeout (#4207) (#4227)
parent
2e9c9e88
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
49 additions
and
17 deletions
+49
-17
etcd_snapshot.go
pkg/cli/cmds/etcd_snapshot.go
+13
-0
server.go
pkg/cli/cmds/server.go
+14
-0
etcd_snapshot.go
pkg/cli/etcdsnapshot/etcd_snapshot.go
+2
-0
server.go
pkg/cli/server/server.go
+2
-0
types.go
pkg/daemons/config/types.go
+4
-0
etcd.go
pkg/etcd/etcd.go
+2
-2
s3.go
pkg/etcd/s3.go
+12
-15
No files found.
pkg/cli/cmds/etcd_snapshot.go
View file @
9c523618
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
{
...
...
pkg/cli/cmds/server.go
View file @
9c523618
...
...
@@ -2,6 +2,7 @@ package cmds
import
(
"context"
"time"
"github.com/rancher/k3s/pkg/version"
"github.com/urfave/cli"
...
...
@@ -77,6 +78,8 @@ type Server struct {
EtcdS3BucketName
string
EtcdS3Region
string
EtcdS3Folder
string
EtcdS3Timeout
time
.
Duration
EtcdS3Insecure
bool
}
var
ServerConfig
Server
...
...
@@ -312,6 +315,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"
,
...
...
pkg/cli/etcdsnapshot/etcd_snapshot.go
View file @
9c523618
...
...
@@ -48,6 +48,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
)
...
...
pkg/cli/server/server.go
View file @
9c523618
...
...
@@ -150,6 +150,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"
)
}
...
...
pkg/daemons/config/types.go
View file @
9c523618
...
...
@@ -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"
...
...
@@ -153,6 +154,9 @@ type Control struct {
EtcdS3BucketName
string
EtcdS3Region
string
EtcdS3Folder
string
EtcdS3Timeout
time
.
Duration
EtcdS3Insecure
bool
ServerNodeName
string
BindAddress
string
SANs
[]
string
...
...
pkg/etcd/etcd.go
View file @
9c523618
...
...
@@ -71,7 +71,7 @@ type ETCD struct {
runtime
*
config
.
ControlRuntime
address
string
cron
*
cron
.
Cron
s3
*
s
3
s3
*
S
3
}
type
learnerProgress
struct
{
...
...
@@ -1032,7 +1032,7 @@ func (e *ETCD) DeleteSnapshots(ctx context.Context, snapshots []string) error {
objectsCh
:=
make
(
chan
minio
.
ObjectInfo
)
ctx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
defaultS3Op
Timeout
)
ctx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
e
.
config
.
EtcdS3
Timeout
)
defer
cancel
()
go
func
()
{
...
...
pkg/etcd/s3.go
View file @
9c523618
...
...
@@ -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,10 +22,8 @@ import (
"github.com/sirupsen/logrus"
)
const
defaultS3OpTimeout
=
time
.
Second
*
30
// s3 maintains state for S3 functionality.
type
s3
struct
{
// S3 maintains state for S3 functionality.
type
S3
struct
{
config
*
config
.
Control
client
*
minio
.
Client
}
...
...
@@ -34,7 +31,7 @@ type s3 struct {
// newS3 creates a new value of type s3 pointer with a
// copy of the config.Control pointer and initializes
// a new Minio client.
func
newS3
(
ctx
context
.
Context
,
config
*
config
.
Control
)
(
*
s
3
,
error
)
{
func
newS3
(
ctx
context
.
Context
,
config
*
config
.
Control
)
(
*
S
3
,
error
)
{
tr
:=
http
.
DefaultTransport
switch
{
...
...
@@ -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
,
defaultS3Op
Timeout
)
ctx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
config
.
EtcdS3
Timeout
)
defer
cancel
()
exists
,
err
:=
c
.
BucketExists
(
ctx
,
config
.
EtcdS3BucketName
)
...
...
@@ -83,7 +80,7 @@ func newS3(ctx context.Context, config *config.Control) (*s3, error) {
}
logrus
.
Infof
(
"S3 bucket %s exists"
,
config
.
EtcdS3BucketName
)
return
&
s
3
{
return
&
S
3
{
config
:
config
,
client
:
c
,
},
nil
...
...
@@ -91,7 +88,7 @@ func newS3(ctx context.Context, config *config.Control) (*s3, error) {
// upload uploads the given snapshot to the configured S3
// compatible backend.
func
(
s
*
s
3
)
upload
(
ctx
context
.
Context
,
snapshot
string
)
error
{
func
(
s
*
S
3
)
upload
(
ctx
context
.
Context
,
snapshot
string
)
error
{
basename
:=
filepath
.
Base
(
snapshot
)
var
snapshotFileName
string
if
s
.
config
.
EtcdS3Folder
!=
""
{
...
...
@@ -100,7 +97,7 @@ func (s *s3) upload(ctx context.Context, snapshot string) error {
snapshotFileName
=
basename
}
toCtx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
defaultS3Op
Timeout
)
toCtx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
s
.
config
.
EtcdS3
Timeout
)
defer
cancel
()
opts
:=
minio
.
PutObjectOptions
{
ContentType
:
"application/zip"
,
...
...
@@ -115,7 +112,7 @@ func (s *s3) upload(ctx context.Context, snapshot string) error {
// download downloads the given snapshot from the configured S3
// compatible backend.
func
(
s
*
s
3
)
download
(
ctx
context
.
Context
)
error
{
func
(
s
*
S
3
)
download
(
ctx
context
.
Context
)
error
{
var
remotePath
string
if
s
.
config
.
EtcdS3Folder
!=
""
{
remotePath
=
filepath
.
Join
(
s
.
config
.
EtcdS3Folder
,
s
.
config
.
ClusterResetRestorePath
)
...
...
@@ -124,7 +121,7 @@ func (s *s3) download(ctx context.Context) error {
}
logrus
.
Debugf
(
"retrieving snapshot: %s"
,
remotePath
)
toCtx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
defaultS3Op
Timeout
)
toCtx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
s
.
config
.
EtcdS3
Timeout
)
defer
cancel
()
r
,
err
:=
s
.
client
.
GetObject
(
toCtx
,
s
.
config
.
EtcdS3BucketName
,
remotePath
,
minio
.
GetObjectOptions
{})
...
...
@@ -161,7 +158,7 @@ func (s *s3) download(ctx context.Context) error {
// snapshotPrefix returns the prefix used in the
// naming of the snapshots.
func
(
s
*
s
3
)
snapshotPrefix
()
string
{
func
(
s
*
S
3
)
snapshotPrefix
()
string
{
nodeName
:=
os
.
Getenv
(
"NODE_NAME"
)
fullSnapshotPrefix
:=
s
.
config
.
EtcdSnapshotName
+
"-"
+
nodeName
var
prefix
string
...
...
@@ -175,10 +172,10 @@ func (s *s3) snapshotPrefix() string {
// snapshotRetention deletes the given snapshot from the configured S3
// compatible backend.
func
(
s
*
s
3
)
snapshotRetention
(
ctx
context
.
Context
)
error
{
func
(
s
*
S
3
)
snapshotRetention
(
ctx
context
.
Context
)
error
{
var
snapshotFiles
[]
minio
.
ObjectInfo
toCtx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
defaultS3Op
Timeout
)
toCtx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
s
.
config
.
EtcdS3
Timeout
)
defer
cancel
()
loo
:=
minio
.
ListObjectsOptions
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment