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

Fixed the issue with consecutive restoration. #259

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 10 additions & 4 deletions .ci/build
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,22 @@ set -e
# For the build step concourse will set the following environment variables:
# SOURCE_PATH - path to component repository root directory.
# BINARY_PATH - path to an existing (empty) directory to place build results into.
if [[ $(uname) == 'Darwin' ]]; then
READLINK_BIN="greadlink"
else
READLINK_BIN="readlink"
fi

if [[ -z "${SOURCE_PATH}" ]]; then
export SOURCE_PATH="$(readlink -f $(dirname ${0})/..)"
export SOURCE_PATH="$(${READLINK_BIN} -f $(dirname ${0})/..)"
else
export SOURCE_PATH="$(readlink -f "${SOURCE_PATH}")"
export SOURCE_PATH="$(${READLINK_BIN} -f "${SOURCE_PATH}")"
fi

if [[ -z "${BINARY_PATH}" ]]; then
export BINARY_PATH="${SOURCE_PATH}/bin"
else
export BINARY_PATH="$(readlink -f "${BINARY_PATH}")/bin"
export BINARY_PATH="$(${READLINK_BIN} -f "${BINARY_PATH}")/bin"
fi

VCS="github.com"
Expand All @@ -40,7 +46,7 @@ cd "${SOURCE_PATH}"

###############################################################################

VERSION_FILE="$(readlink -f "${SOURCE_PATH}/VERSION")"
VERSION_FILE="$(${READLINK_BIN} -f "${SOURCE_PATH}/VERSION")"
VERSION="$(cat "${VERSION_FILE}")"
GIT_SHA=$(git rev-parse --short HEAD || echo "GitNotFound")

Expand Down
11 changes: 8 additions & 3 deletions .ci/integration_test
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,24 @@ set -e

# For the test step concourse will set the following environment variables:
# SOURCE_PATH - path to component repository root directory.
if [[ $(uname) == 'Darwin' ]]; then
READLINK_BIN="greadlink"
else
READLINK_BIN="readlink"
fi

if [[ -z "${SOURCE_PATH}" ]]; then
export SOURCE_PATH="$(readlink -f "$(dirname ${0})/..")"
export SOURCE_PATH="$(${READLINK_BIN} -f "$(dirname ${0})/..")"
else
export SOURCE_PATH="$(readlink -f "${SOURCE_PATH}")"
export SOURCE_PATH="$(${READLINK_BIN} -f "${SOURCE_PATH}")"
fi

VCS="github.com"
ORGANIZATION="gardener"
PROJECT="etcd-backup-restore"
REPOSITORY=${VCS}/${ORGANIZATION}/${PROJECT}
URL=https://${REPOSITORY}.git
VERSION_FILE="$(readlink -f "${SOURCE_PATH}/VERSION")"
VERSION_FILE="$(${READLINK_BIN} -f "${SOURCE_PATH}/VERSION")"
VERSION="$(cat "${VERSION_FILE}")"
TEST_ID_PREFIX="etcdbr-test"
TM_TEST_ID_PREFIX="etcdbr-tm-test"
Expand Down
10 changes: 8 additions & 2 deletions .ci/unit_test
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ set -e

# For the test step concourse will set the following environment variables:
# SOURCE_PATH - path to component repository root directory.
if [[ $(uname) == 'Darwin' ]]; then
READLINK_BIN="greadlink"
else
READLINK_BIN="readlink"
fi

if [[ -z "${SOURCE_PATH}" ]]; then
export SOURCE_PATH="$(readlink -f "$(dirname ${0})/..")"
export SOURCE_PATH="$(${READLINK_BIN} -f "$(dirname ${0})/..")"
else
export SOURCE_PATH="$(readlink -f "${SOURCE_PATH}")"
export SOURCE_PATH="$(${READLINK_BIN} -f "${SOURCE_PATH}")"
fi

VCS="github.com"
Expand Down
8 changes: 4 additions & 4 deletions pkg/initializer/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ func NewInitializer(options *restorer.RestoreOptions, snapstoreConfig *snapstore
// bootstrapping a new data directory or if restoration failed
func (e *EtcdInitializer) restoreCorruptData() (bool, error) {
logger := e.Logger
dataDir := e.Config.RestoreOptions.Config.RestoreDataDir
tempRestoreOptions := *(e.Config.RestoreOptions.DeepCopy())
dataDir := tempRestoreOptions.Config.RestoreDataDir

if e.Config.SnapstoreConfig == nil || len(e.Config.SnapstoreConfig.Provider) == 0 {
logger.Warnf("No snapstore storage provider configured.")
Expand All @@ -116,9 +117,8 @@ func (e *EtcdInitializer) restoreCorruptData() (bool, error) {
return e.restoreWithEmptySnapstore()
}

e.Config.RestoreOptions.BaseSnapshot = *baseSnap
e.Config.RestoreOptions.DeltaSnapList = deltaSnapList
tempRestoreOptions := *e.Config.RestoreOptions
tempRestoreOptions.BaseSnapshot = *baseSnap
tempRestoreOptions.DeltaSnapList = deltaSnapList
tempRestoreOptions.Config.RestoreDataDir = fmt.Sprintf("%s.%s", tempRestoreOptions.Config.RestoreDataDir, "part")

if err := e.removeDir(tempRestoreOptions.Config.RestoreDataDir); err != nil {
Expand Down
95 changes: 95 additions & 0 deletions pkg/snapshot/restorer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package restorer

import (
"net/url"
"time"

"github.com/coreos/etcd/clientv3"
Expand All @@ -41,6 +42,7 @@ type Restorer struct {
}

// RestoreOptions hold all snapshot restore related fields
// Note: Please ensure DeepCopy and DeepCopyInto are properly implemented.
type RestoreOptions struct {
Config *RestorationConfig
ClusterURLs types.URLsMap
Expand All @@ -51,6 +53,7 @@ type RestoreOptions struct {
}

// RestorationConfig holds the restoration configuration.
// Note: Please ensure DeepCopy and DeepCopyInto are properly implemented.
type RestorationConfig struct {
InitialCluster string `json:"initialCluster"`
InitialClusterToken string `json:"initialClusterToken,omitempty"`
Expand Down Expand Up @@ -83,3 +86,95 @@ type applierInfo struct {
EventsFilePath string
SnapIndex int
}

// DeepCopyInto copies the structure deeply from in to out.
func (in *RestoreOptions) DeepCopyInto(out *RestoreOptions) {
*out = *in
if in.Config != nil {
in, out := &in.Config, &out.Config
*out = new(RestorationConfig)
(*in).DeepCopyInto(*out)
}
if in.ClusterURLs != nil {
in, out := &in.ClusterURLs, &out.ClusterURLs
*out = make(types.URLsMap)
for k := range *in {
if (*in)[k] != nil {
(*out)[k] = DeepCopyURLs((*in)[k])
}
}
}
if in.PeerURLs != nil {
out.PeerURLs = DeepCopyURLs(in.PeerURLs)
}
if in.DeltaSnapList != nil {
out.DeltaSnapList = DeepCopySnapList(in.DeltaSnapList)
}
}

// DeepCopyURLs returns a deeply copy
func DeepCopyURLs(in types.URLs) types.URLs {
out := make(types.URLs, len(in))
for i, u := range in {
out[i] = *(DeepCopyURL(&u))
}
return out
}

// DeepCopyURL returns a deeply copy
func DeepCopyURL(in *url.URL) *url.URL {
var out = new(url.URL)
*out = *in
if in.User != nil {
in, out := &in.User, &out.User
*out = new (url.Userinfo)
*out = *in
}
return out
}

// DeepCopySnapList returns a deep copy
func DeepCopySnapList(in snapstore.SnapList) snapstore.SnapList {
out := make(snapstore.SnapList, len(in))
for i, v := range in {
if v != nil {
var cpv = *v
out[i] = &cpv
}
}
return out
}

// DeepCopy returns a deeply copied structure.
func (in *RestoreOptions) DeepCopy() *RestoreOptions {
if in == nil {
return nil
}

out := new(RestoreOptions)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto copies the structure deeply from in to out.
func (in *RestorationConfig) DeepCopyInto(out *RestorationConfig) {
*out = *in
if in.InitialAdvertisePeerURLs != nil {
in, out := &in.InitialAdvertisePeerURLs, &out.InitialAdvertisePeerURLs
*out = make([]string, len(*in))
for i, v := range *in {
(*out)[i] = v
}
}
}

// DeepCopy returns a deeply copied structure.
func (in *RestorationConfig) DeepCopy() *RestorationConfig {
if in == nil {
return nil
}

out := new(RestorationConfig)
in.DeepCopyInto(out)
return out
}
Loading