From 878068736bc5a903956d88eade54b51797c6e68b Mon Sep 17 00:00:00 2001 From: Swapnil Mhamane Date: Wed, 18 Mar 2020 16:43:36 +0530 Subject: [PATCH] :ok_hand: Addressed the review comments Signed-off-by: Swapnil Mhamane --- example/00-backup-restore-server-config.yaml | 2 +- pkg/etcdutil/init.go | 2 +- pkg/etcdutil/types.go | 2 ++ pkg/server/init.go | 2 +- pkg/server/types.go | 3 ++- pkg/snapshot/restorer/init.go | 11 +++-------- pkg/snapshot/restorer/types.go | 6 ++++++ pkg/snapshot/snapshotter/init.go | 11 +++++------ pkg/snapshot/snapshotter/types.go | 3 +++ 9 files changed, 24 insertions(+), 18 deletions(-) diff --git a/example/00-backup-restore-server-config.yaml b/example/00-backup-restore-server-config.yaml index 78a815434..e32597ef2 100644 --- a/example/00-backup-restore-server-config.yaml +++ b/example/00-backup-restore-server-config.yaml @@ -14,7 +14,7 @@ serverConfig: port: 8080 # enableProfiling: true # server-cert: "ssl/etcdbr/tls.crt" - # server-key: "ssl/etcdbr/tls.crt" + # server-key: "ssl/etcdbr/tls.key" snapshotterConfig: schedule: "0 */1 * * *" diff --git a/pkg/etcdutil/init.go b/pkg/etcdutil/init.go index abd1fa649..16b290c07 100644 --- a/pkg/etcdutil/init.go +++ b/pkg/etcdutil/init.go @@ -25,7 +25,7 @@ import ( // NewEtcdConnectionConfig returns etcd connection config. func NewEtcdConnectionConfig() *EtcdConnectionConfig { return &EtcdConnectionConfig{ - Endpoints: []string{"127.0.0.1:2379"}, + Endpoints: []string{defaultEtcdConnectionEndpoint}, ConnectionTimeout: wrappers.Duration{Duration: 30 * time.Second}, InsecureTransport: true, InsecureSkipVerify: false, diff --git a/pkg/etcdutil/types.go b/pkg/etcdutil/types.go index 246782c6a..42c82560f 100644 --- a/pkg/etcdutil/types.go +++ b/pkg/etcdutil/types.go @@ -18,6 +18,8 @@ import ( "github.com/gardener/etcd-backup-restore/pkg/wrappers" ) +const defaultEtcdConnectionEndpoint string = "127.0.0.1:2379" + // EtcdConnectionConfig holds the etcd connection config. type EtcdConnectionConfig struct { // Endpoints are the endpoints from which the backup will be take or defragmentation will be called. diff --git a/pkg/server/init.go b/pkg/server/init.go index 6f210785c..b293ef9fe 100644 --- a/pkg/server/init.go +++ b/pkg/server/init.go @@ -35,7 +35,7 @@ func NewBackupRestoreComponentConfig() *BackupRestoreComponentConfig { SnapshotterConfig: snapshotter.NewSnapshotterConfig(), SnapstoreConfig: snapstore.NewSnapstoreConfig(), RestorationConfig: restorer.NewRestorationConfig(), - DefragmentationSchedule: "0 0 */3 * *", + DefragmentationSchedule: defaultDefragmentationSchedule, } } diff --git a/pkg/server/types.go b/pkg/server/types.go index 77dd39925..48d2e5451 100644 --- a/pkg/server/types.go +++ b/pkg/server/types.go @@ -22,7 +22,8 @@ import ( ) const ( - defaultServerPort = 8080 + defaultServerPort = 8080 + defaultDefragmentationSchedule = "0 0 */3 * *" ) // BackupRestoreComponentConfig holds the component configuration. diff --git a/pkg/snapshot/restorer/init.go b/pkg/snapshot/restorer/init.go index 62db38802..97e4a8d93 100644 --- a/pkg/snapshot/restorer/init.go +++ b/pkg/snapshot/restorer/init.go @@ -22,22 +22,17 @@ import ( flag "github.com/spf13/pflag" ) -const ( - defaultName = "default" - defaultInitialAdvertisePeerURLs = "http://localhost:2380" -) - // NewRestorationConfig returns the restoration config. func NewRestorationConfig() *RestorationConfig { return &RestorationConfig{ InitialCluster: initialClusterFromName(defaultName), - InitialClusterToken: "etcd-cluster", + InitialClusterToken: defaultInitialClusterToken, RestoreDataDir: fmt.Sprintf("%s.etcd", defaultName), InitialAdvertisePeerURLs: []string{defaultInitialAdvertisePeerURLs}, Name: defaultName, SkipHashCheck: false, - MaxFetchers: 6, - EmbeddedEtcdQuotaBytes: int64(8 * 1024 * 1024 * 1024), + MaxFetchers: defaultMaxFetchers, + EmbeddedEtcdQuotaBytes: int64(defaultEmbeddedEtcdQuotaBytes), } } diff --git a/pkg/snapshot/restorer/types.go b/pkg/snapshot/restorer/types.go index 04d18c0a3..4cf272cfc 100755 --- a/pkg/snapshot/restorer/types.go +++ b/pkg/snapshot/restorer/types.go @@ -26,6 +26,12 @@ import ( const ( tmpDir = "/tmp" tmpEventsDataFilePrefix = "etcd-restore-" + + defaultName = "default" + defaultInitialAdvertisePeerURLs = "http://localhost:2380" + defaultInitialClusterToken = "etcd-cluster" + defaultMaxFetchers = 6 + defaultEmbeddedEtcdQuotaBytes = 8 * 1024 * 1024 * 1024 //8Gib ) // Restorer is a struct for etcd data directory restorer diff --git a/pkg/snapshot/snapshotter/init.go b/pkg/snapshot/snapshotter/init.go index 610db54f3..8f268d56a 100644 --- a/pkg/snapshot/snapshotter/init.go +++ b/pkg/snapshot/snapshotter/init.go @@ -16,7 +16,6 @@ package snapshotter import ( "fmt" - "time" "github.com/gardener/etcd-backup-restore/pkg/wrappers" cron "github.com/robfig/cron/v3" @@ -27,12 +26,12 @@ import ( // NewSnapshotterConfig returns the snapshotter config. func NewSnapshotterConfig() *Config { return &Config{ - FullSnapshotSchedule: "0 */1 * * *", - DeltaSnapshotPeriod: wrappers.Duration{Duration: 20 * time.Second}, - DeltaSnapshotMemoryLimit: 10 * 1024 * 1024, //10Mib - GarbageCollectionPeriod: wrappers.Duration{Duration: time.Minute}, + FullSnapshotSchedule: defaultFullSnapshotSchedule, + DeltaSnapshotPeriod: wrappers.Duration{Duration: DefaultDeltaSnapshotInterval}, + DeltaSnapshotMemoryLimit: DefaultDeltaSnapMemoryLimit, + GarbageCollectionPeriod: wrappers.Duration{Duration: defaultGarbageCollectionPeriod}, GarbageCollectionPolicy: GarbageCollectionPolicyExponential, - MaxBackups: 7, + MaxBackups: DefaultMaxBackups, } } diff --git a/pkg/snapshot/snapshotter/types.go b/pkg/snapshot/snapshotter/types.go index 0ed343cf5..96f5dccdd 100644 --- a/pkg/snapshot/snapshotter/types.go +++ b/pkg/snapshot/snapshotter/types.go @@ -34,6 +34,7 @@ const ( GarbageCollectionPolicyExponential = "Exponential" // GarbageCollectionPolicyLimitBased defines the limit based policy for garbage collecting old backups GarbageCollectionPolicyLimitBased = "LimitBased" + defaultGarbageCollectionPeriod = time.Minute // DefaultMaxBackups is default number of maximum backups for limit based garbage collection policy. DefaultMaxBackups = 7 @@ -41,6 +42,8 @@ const ( SnapshotterInactive State = 0 // SnapshotterActive is set when the snapshotter has started taking snapshots. SnapshotterActive State = 1 + + defaultFullSnapshotSchedule string = "0 */1 * * *" // DefaultDeltaSnapMemoryLimit is default memory limit for delta snapshots. DefaultDeltaSnapMemoryLimit = 10 * 1024 * 1024 //10Mib // DefaultDeltaSnapshotInterval is the default interval for delta snapshots.