mirror of
https://github.com/rancher/rke.git
synced 2025-09-20 02:49:08 +00:00
Add etcd snapshot compression
This commit is contained in:
committed by
Alena Prokharchyk
parent
28d907281f
commit
bc09408581
@@ -29,6 +29,7 @@ const (
|
|||||||
EtcdDataDir = "/var/lib/rancher/etcd/"
|
EtcdDataDir = "/var/lib/rancher/etcd/"
|
||||||
EtcdInitWaitTime = 10
|
EtcdInitWaitTime = 10
|
||||||
EtcdSnapshotWaitTime = 5
|
EtcdSnapshotWaitTime = 5
|
||||||
|
EtcdSnapshotCompressedExtension = "gz"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RunEtcdPlane(
|
func RunEtcdPlane(
|
||||||
@@ -457,7 +458,7 @@ func RestoreEtcdSnapshot(ctx context.Context, etcdHost *hosts.Host, prsMap map[s
|
|||||||
|
|
||||||
func RunEtcdSnapshotRemove(ctx context.Context, etcdHost *hosts.Host, prsMap map[string]v3.PrivateRegistry, etcdSnapshotImage string, name string, once bool, es v3.ETCDService) error {
|
func RunEtcdSnapshotRemove(ctx context.Context, etcdHost *hosts.Host, prsMap map[string]v3.PrivateRegistry, etcdSnapshotImage string, name string, once bool, es v3.ETCDService) error {
|
||||||
log.Infof(ctx, "[etcd] Removing snapshot [%s] from host [%s]", name, etcdHost.Address)
|
log.Infof(ctx, "[etcd] Removing snapshot [%s] from host [%s]", name, etcdHost.Address)
|
||||||
fullPath := fmt.Sprintf("/backup/%s", name)
|
fullPath := fmt.Sprintf("/backup/%s{,.gz}", name)
|
||||||
// Make sure we have a safe path to remove
|
// Make sure we have a safe path to remove
|
||||||
safePath, err := filepath.Match("/backup/*", fullPath)
|
safePath, err := filepath.Match("/backup/*", fullPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -469,9 +470,7 @@ func RunEtcdSnapshotRemove(ctx context.Context, etcdHost *hosts.Host, prsMap map
|
|||||||
|
|
||||||
imageCfg := &container.Config{
|
imageCfg := &container.Config{
|
||||||
Cmd: []string{
|
Cmd: []string{
|
||||||
"rm",
|
"sh", "-c", fmt.Sprintf("rm -f %s", fullPath),
|
||||||
"-f",
|
|
||||||
fullPath,
|
|
||||||
},
|
},
|
||||||
Image: etcdSnapshotImage,
|
Image: etcdSnapshotImage,
|
||||||
}
|
}
|
||||||
@@ -505,13 +504,14 @@ func RunEtcdSnapshotRemove(ctx context.Context, etcdHost *hosts.Host, prsMap map
|
|||||||
func GetEtcdSnapshotChecksum(ctx context.Context, etcdHost *hosts.Host, prsMap map[string]v3.PrivateRegistry, alpineImage, snapshotName string) (string, error) {
|
func GetEtcdSnapshotChecksum(ctx context.Context, etcdHost *hosts.Host, prsMap map[string]v3.PrivateRegistry, alpineImage, snapshotName string) (string, error) {
|
||||||
var checksum string
|
var checksum string
|
||||||
var err error
|
var err error
|
||||||
|
var stderr string
|
||||||
|
|
||||||
|
// compressedSnapshotPath := fmt.Sprintf("%s%s.%s", EtcdSnapshotPath, snapshotName, EtcdSnapshotCompressedExtension)
|
||||||
snapshotPath := fmt.Sprintf("%s%s", EtcdSnapshotPath, snapshotName)
|
snapshotPath := fmt.Sprintf("%s%s", EtcdSnapshotPath, snapshotName)
|
||||||
imageCfg := &container.Config{
|
imageCfg := &container.Config{
|
||||||
Cmd: []string{
|
Cmd: []string{
|
||||||
"sh", "-c", strings.Join([]string{
|
"sh", "-c", strings.Join([]string{
|
||||||
"md5sum", snapshotPath,
|
"if [ -f ", snapshotPath, " ]; then md5sum ", snapshotPath, " | cut -f1 -d' ' | tr -d '\n'; else echo 'snapshot file does not exist' >&2; fi"}, ""),
|
||||||
"|", "cut", "-f1", "-d' '", "|", "tr", "-d", "'\n'"}, " "),
|
|
||||||
},
|
},
|
||||||
Image: alpineImage,
|
Image: alpineImage,
|
||||||
}
|
}
|
||||||
@@ -526,10 +526,14 @@ func GetEtcdSnapshotChecksum(ctx context.Context, etcdHost *hosts.Host, prsMap m
|
|||||||
if _, err := docker.WaitForContainer(ctx, etcdHost.DClient, etcdHost.Address, EtcdChecksumContainerName); err != nil {
|
if _, err := docker.WaitForContainer(ctx, etcdHost.DClient, etcdHost.Address, EtcdChecksumContainerName); err != nil {
|
||||||
return checksum, err
|
return checksum, err
|
||||||
}
|
}
|
||||||
_, checksum, err = docker.GetContainerLogsStdoutStderr(ctx, etcdHost.DClient, EtcdChecksumContainerName, "1", false)
|
stderr, checksum, err = docker.GetContainerLogsStdoutStderr(ctx, etcdHost.DClient, EtcdChecksumContainerName, "1", false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return checksum, err
|
return checksum, err
|
||||||
}
|
}
|
||||||
|
if stderr != "" {
|
||||||
|
return checksum, fmt.Errorf("Error output not nil from snapshot checksum container [%s]: %s", EtcdChecksumContainerName, stderr)
|
||||||
|
|
||||||
|
}
|
||||||
if err := docker.RemoveContainer(ctx, etcdHost.DClient, etcdHost.Address, EtcdChecksumContainerName); err != nil {
|
if err := docker.RemoveContainer(ctx, etcdHost.DClient, etcdHost.Address, EtcdChecksumContainerName); err != nil {
|
||||||
return checksum, err
|
return checksum, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user