Skip to content
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

Galal hussein etcd backup restore #2154

Merged
merged 57 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
3ead6fa
Add etcd snapshot and restore
galal-hussein Aug 12, 2020
78fd41f
fix error logs
galal-hussein Aug 12, 2020
d3575b6
goimports
galal-hussein Aug 12, 2020
4be58c5
fix flag describtion
galal-hussein Aug 12, 2020
6fa3b27
Add disable snapshot and retention
galal-hussein Aug 13, 2020
76216ac
use creation time for snapshot retention
galal-hussein Aug 14, 2020
c3ae60f
resolve merge conflicts
briandowns Aug 22, 2020
31a9b6f
unexport method, update var name
briandowns Aug 22, 2020
a580089
adjust snapshot flags
briandowns Aug 22, 2020
1357ac5
update var name, string concat
briandowns Aug 22, 2020
192a7ff
revert previous change, create constants
briandowns Aug 22, 2020
49668c6
update
briandowns Aug 22, 2020
97f11ce
updates
briandowns Aug 22, 2020
478bb0f
type assertion error checking
briandowns Aug 22, 2020
277ac51
update
briandowns Aug 22, 2020
e68ab7e
update
briandowns Aug 22, 2020
7b6d2c2
update
briandowns Aug 22, 2020
e55f556
pr remediation
briandowns Aug 22, 2020
0da7678
pr remediation
briandowns Aug 22, 2020
1482fa1
pr remediation
briandowns Aug 22, 2020
114ae91
pr remediation
briandowns Aug 22, 2020
f5ef1cd
pr remediation
briandowns Aug 22, 2020
cc76bdd
updates
briandowns Aug 23, 2020
2029725
updates
briandowns Aug 23, 2020
a36a8c2
simplify logic, remove unneeded function
briandowns Aug 23, 2020
1d95248
update flags
briandowns Aug 23, 2020
d5974f4
update flags
briandowns Aug 23, 2020
3c5b45b
add comment
briandowns Aug 24, 2020
d50cde8
exit on restore completion, update flag names, move retention check
briandowns Aug 24, 2020
34696c1
exit on restore completion, update flag names, move retention check
briandowns Aug 24, 2020
ce1951d
exit on restore completion, update flag names, move retention check
briandowns Aug 24, 2020
b485390
update disable snapshots flag and field names
briandowns Aug 24, 2020
0e181e7
move function
briandowns Aug 24, 2020
5e177bf
update field names
briandowns Aug 24, 2020
a073469
update var and field names
briandowns Aug 25, 2020
79ad3d4
update var and field names
briandowns Aug 26, 2020
b3a7979
update defaultSnapshotIntervalMinutes to 12 like rke
briandowns Aug 26, 2020
1fbad2d
update directory perms
briandowns Aug 26, 2020
ed06bfb
update etc-snapshot-dir usage
briandowns Aug 26, 2020
d56abbe
update interval to 12 hours
briandowns Aug 26, 2020
1286897
fix usage typo
briandowns Aug 27, 2020
a6a4d54
add cron
briandowns Aug 28, 2020
8ad24ad
add cron
briandowns Aug 28, 2020
67166b2
add cron
briandowns Aug 28, 2020
c077736
wire in cron
briandowns Aug 28, 2020
330c19d
wire in cron
briandowns Aug 28, 2020
c4a83d6
wire in cron
briandowns Aug 28, 2020
6e234dd
wire in cron
briandowns Aug 28, 2020
17a08c7
wire in cron
briandowns Aug 28, 2020
7ccc390
wire in cron
briandowns Aug 28, 2020
30da757
wire in cron
briandowns Aug 28, 2020
b877501
update deps target to work, add build/data target for creation, and g…
briandowns Aug 28, 2020
f839e08
remove dead make targets
briandowns Aug 28, 2020
a940f74
error handling, cluster reset functionality
briandowns Aug 28, 2020
969cab1
error handling, cluster reset functionality
briandowns Aug 28, 2020
4d6002d
update
briandowns Aug 28, 2020
469d100
remove intermediate dapper file
briandowns Aug 28, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@ TARGETS := $(shell ls scripts | grep -v \\.sh)
$(TARGETS): .dapper
./.dapper $@

trash: .dapper
./.dapper -m bind trash

trash-keep: .dapper
./.dapper -m bind trash -k

deps: trash
.PHONY: deps
deps:
go mod vendor
go mod tidy

release:
./scripts/release.sh

.DEFAULT_GOAL := ci

.PHONY: $(TARGETS)

.PHONY: generate
generate: build/data
./scripts/download
go generate

build/data:
mkdir -p $@
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ require (
github.com/rancher/spur v0.0.0-20200617165101-8702c8e4ce7a
github.com/rancher/wrangler v0.6.1
github.com/rancher/wrangler-api v0.6.0
github.com/robfig/cron/v3 v3.0.1
github.com/rootless-containers/rootlesskit v0.10.0
github.com/sirupsen/logrus v1.6.0
github.com/spf13/pflag v1.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ github.com/rancher/wrangler-api v0.6.0/go.mod h1:RbuDkPNHhxcXuwAbLVvEAhH+UPAh+MI
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/robfig/cron v1.1.0 h1:jk4/Hud3TTdcrJgUOBgsqrZBarcxl6ADIjSC2iniwLY=
github.com/robfig/cron v1.1.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down
1 change: 1 addition & 0 deletions pkg/agent/netpol/netpol_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package netpol

import (
"context"

daemonconfig "github.com/rancher/k3s/pkg/daemons/config"
)

Expand Down
35 changes: 35 additions & 0 deletions pkg/cli/cmds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (

const (
DisableItems = "coredns, servicelb, traefik, local-storage, metrics-server"

defaultSnapshotRentention = 5
defaultSnapshotIntervalHours = 12
)

type Server struct {
Expand Down Expand Up @@ -56,8 +59,13 @@ type Server struct {
DisableKubeProxy bool
ClusterInit bool
ClusterReset bool
ClusterResetRestorePath string
EncryptSecrets bool
StartupHooks []func(context.Context, config.Control) error
EtcdDisableSnapshots bool
EtcdSnapshotDir string
EtcdSnapshotCron string
EtcdSnapshotRetention int
}

var ServerConfig Server
Expand Down Expand Up @@ -210,6 +218,28 @@ func NewServerCommand(action func(*cli.Context) error) *cli.Command {
Destination: &ServerConfig.DatastoreKeyFile,
EnvVars: []string{version.ProgramUpper + "_DATASTORE_KEYFILE"},
},
&cli.BoolFlag{
Name: "etcd-disable-snapshots",
Usage: "(db) Disable automatic etcd snapshots",
Destination: &ServerConfig.EtcdDisableSnapshots,
},
&cli.StringFlag{
Name: "etcd-snapshot-schedule-cron",
Usage: "(db) Snapshot interval time in cron spec. eg. every 5 hours '* */5 * * *'",
Destination: &ServerConfig.EtcdSnapshotCron,
Value: "0 */12 * * *",
},
&cli.IntFlag{
Name: "etcd-snapshot-retention",
Usage: "(db) Number of snapshots to retain",
Destination: &ServerConfig.EtcdSnapshotRetention,
Value: defaultSnapshotRentention,
},
&cli.StringFlag{
Name: "etcd-snapshot-dir",
Usage: "(db) Directory to save db snapshots. (Default location: ${data-dir}/db/snapshots)",
Destination: &ServerConfig.EtcdSnapshotDir,
},
&cli.StringFlag{
Name: "default-local-storage-path",
Usage: "(storage) Default local storage path for local provisioner storage class",
Expand Down Expand Up @@ -293,6 +323,11 @@ func NewServerCommand(action func(*cli.Context) error) *cli.Command {
EnvVars: []string{version.ProgramUpper + "_CLUSTER_RESET"},
Destination: &ServerConfig.ClusterReset,
},
&cli.StringFlag{
Name: "cluster-reset-restore-path",
Usage: "(db) Path to snapshot file to be restored",
Destination: &ServerConfig.ClusterResetRestorePath,
},
&cli.BoolFlag{
Name: "secrets-encryption",
Usage: "(experimental) Enable Secret encryption at rest",
Expand Down
12 changes: 11 additions & 1 deletion pkg/cli/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,18 @@ func run(app *cli.Context, cfg *cmds.Server) error {
serverConfig.ControlConfig.DisableNPC = cfg.DisableNPC
serverConfig.ControlConfig.DisableKubeProxy = cfg.DisableKubeProxy
serverConfig.ControlConfig.ClusterInit = cfg.ClusterInit
serverConfig.ControlConfig.ClusterReset = cfg.ClusterReset
serverConfig.ControlConfig.EncryptSecrets = cfg.EncryptSecrets
serverConfig.ControlConfig.EtcdSnapshotCron = cfg.EtcdSnapshotCron
serverConfig.ControlConfig.EtcdSnapshotDir = cfg.EtcdSnapshotDir
serverConfig.ControlConfig.EtcdSnapshotRetention = cfg.EtcdSnapshotRetention
serverConfig.ControlConfig.EtcdDisableSnapshots = cfg.EtcdDisableSnapshots

if cfg.ClusterResetRestorePath != "" && !cfg.ClusterReset {
return errors.New("Invalid flag use. --cluster-reset required with --cluster-reset-restore-path")
}

serverConfig.ControlConfig.ClusterReset = cfg.ClusterReset
serverConfig.ControlConfig.ClusterResetRestorePath = cfg.ClusterResetRestorePath

if serverConfig.ControlConfig.SupervisorPort == 0 {
serverConfig.ControlConfig.SupervisorPort = serverConfig.ControlConfig.HTTPSPort
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import (
)

func init() {
managed.RegisterDriver(&etcd.ETCD{})
managed.RegisterDriver(etcd.NewETCD())
}
1 change: 1 addition & 0 deletions pkg/cluster/managed/drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Driver interface {
Reset(ctx context.Context, clientAccessInfo *clientaccess.Info) error
Start(ctx context.Context, clientAccessInfo *clientaccess.Info) error
Test(ctx context.Context, clientAccessInfo *clientaccess.Info) error
Restore(ctx context.Context) error
EndpointName() string
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/daemons/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,14 @@ type Control struct {
DisableKubeProxy bool
ClusterInit bool
ClusterReset bool
ClusterResetRestorePath string
EncryptSecrets bool
TLSMinVersion uint16
TLSCipherSuites []uint16
EtcdDisableSnapshots bool
EtcdSnapshotDir string
EtcdSnapshotCron string
EtcdSnapshotRetention int

BindAddress string
SANs []string
Expand Down
Loading