mirror of
https://github.com/rancher/rke.git
synced 2025-08-01 23:33:39 +00:00
always use DefaultRKETools for etcd snapshot
This commit is contained in:
parent
bc09408581
commit
1a1080a234
@ -20,9 +20,6 @@ const (
|
|||||||
|
|
||||||
func (c *Cluster) SnapshotEtcd(ctx context.Context, snapshotName string) error {
|
func (c *Cluster) SnapshotEtcd(ctx context.Context, snapshotName string) error {
|
||||||
backupImage := c.getBackupImage()
|
backupImage := c.getBackupImage()
|
||||||
if !util.IsRancherBackupSupported(c.SystemImages.Alpine) {
|
|
||||||
log.Warnf(ctx, "Auto local backup sync is not supported in `%s`. Using `%s` instead.", c.SystemImages.Alpine, backupImage)
|
|
||||||
}
|
|
||||||
for _, host := range c.EtcdHosts {
|
for _, host := range c.EtcdHosts {
|
||||||
if err := services.RunEtcdSnapshotSave(ctx, host, c.PrivateRegistriesMap, backupImage, snapshotName, true, c.Services.Etcd); err != nil {
|
if err := services.RunEtcdSnapshotSave(ctx, host, c.PrivateRegistriesMap, backupImage, snapshotName, true, c.Services.Etcd); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -62,9 +59,6 @@ func (c *Cluster) PrepareBackup(ctx context.Context, snapshotPath string) error
|
|||||||
var backupServer *hosts.Host
|
var backupServer *hosts.Host
|
||||||
backupImage := c.getBackupImage()
|
backupImage := c.getBackupImage()
|
||||||
var errors []error
|
var errors []error
|
||||||
if !util.IsRancherBackupSupported(c.SystemImages.Alpine) {
|
|
||||||
log.Warnf(ctx, "Auto local backup sync is not supported in `%s`. Using `%s` instead.", c.SystemImages.Alpine, backupImage)
|
|
||||||
}
|
|
||||||
if c.Services.Etcd.BackupConfig == nil || // legacy rke local backup
|
if c.Services.Etcd.BackupConfig == nil || // legacy rke local backup
|
||||||
(c.Services.Etcd.BackupConfig != nil && IsLocalSnapshot(snapshotPath)) { // rancher local backup and snapshot name indicates a local snapshot
|
(c.Services.Etcd.BackupConfig != nil && IsLocalSnapshot(snapshotPath)) { // rancher local backup and snapshot name indicates a local snapshot
|
||||||
// stop etcd on all etcd nodes, we need this because we start the backup server on the same port
|
// stop etcd on all etcd nodes, we need this because we start the backup server on the same port
|
||||||
@ -145,9 +139,6 @@ func (c *Cluster) RestoreEtcdSnapshot(ctx context.Context, snapshotPath string)
|
|||||||
|
|
||||||
func (c *Cluster) RemoveEtcdSnapshot(ctx context.Context, snapshotName string) error {
|
func (c *Cluster) RemoveEtcdSnapshot(ctx context.Context, snapshotName string) error {
|
||||||
backupImage := c.getBackupImage()
|
backupImage := c.getBackupImage()
|
||||||
if !util.IsRancherBackupSupported(c.SystemImages.Alpine) {
|
|
||||||
log.Warnf(ctx, "Auto local backup sync is not supported in `%s`. Using `%s` instead.", c.SystemImages.Alpine, backupImage)
|
|
||||||
}
|
|
||||||
for _, host := range c.EtcdHosts {
|
for _, host := range c.EtcdHosts {
|
||||||
if err := services.RunEtcdSnapshotRemove(ctx, host, c.PrivateRegistriesMap, backupImage, snapshotName, true, c.Services.Etcd); err != nil {
|
if err := services.RunEtcdSnapshotRemove(ctx, host, c.PrivateRegistriesMap, backupImage, snapshotName, true, c.Services.Etcd); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -179,10 +170,7 @@ func (c *Cluster) etcdSnapshotChecksum(ctx context.Context, snapshotPath string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cluster) getBackupImage() string {
|
func (c *Cluster) getBackupImage() string {
|
||||||
if util.IsRancherBackupSupported(c.SystemImages.Alpine) {
|
return util.DefaultRKETools
|
||||||
return c.SystemImages.Alpine
|
|
||||||
}
|
|
||||||
return util.GetDefaultRKETools()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsLocalSnapshot(name string) bool {
|
func IsLocalSnapshot(name string) bool {
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
"github.com/rancher/rke/log"
|
"github.com/rancher/rke/log"
|
||||||
"github.com/rancher/rke/pki"
|
"github.com/rancher/rke/pki"
|
||||||
"github.com/rancher/rke/util"
|
"github.com/rancher/rke/util"
|
||||||
v3 "github.com/rancher/types/apis/management.cattle.io/v3"
|
"github.com/rancher/types/apis/management.cattle.io/v3"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
"k8s.io/client-go/util/cert"
|
"k8s.io/client-go/util/cert"
|
||||||
@ -53,10 +53,10 @@ func RunEtcdPlane(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if *es.Snapshot == true {
|
if *es.Snapshot == true {
|
||||||
if err := RunEtcdSnapshotSave(ctx, host, prsMap, alpineImage, EtcdSnapshotContainerName, false, es); err != nil {
|
if err := RunEtcdSnapshotSave(ctx, host, prsMap, util.DefaultRKETools, EtcdSnapshotContainerName, false, es); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := pki.SaveBackupBundleOnHost(ctx, host, alpineImage, EtcdSnapshotPath, prsMap); err != nil {
|
if err := pki.SaveBackupBundleOnHost(ctx, host, util.DefaultRKETools, EtcdSnapshotPath, prsMap); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -273,9 +273,6 @@ func RunEtcdSnapshotSave(ctx context.Context, etcdHost *hosts.Host, prsMap map[s
|
|||||||
log.Infof(ctx, "[etcd] Saving snapshot [%s] on host [%s]", name, etcdHost.Address)
|
log.Infof(ctx, "[etcd] Saving snapshot [%s] on host [%s]", name, etcdHost.Address)
|
||||||
backupCmd := "etcd-backup"
|
backupCmd := "etcd-backup"
|
||||||
restartPolicy := "always"
|
restartPolicy := "always"
|
||||||
if !util.IsRancherBackupSupported(etcdSnapshotImage) {
|
|
||||||
backupCmd = "rolling-backup"
|
|
||||||
}
|
|
||||||
imageCfg := &container.Config{
|
imageCfg := &container.Config{
|
||||||
Cmd: []string{
|
Cmd: []string{
|
||||||
"/opt/rke-tools/rke-etcd-backup",
|
"/opt/rke-tools/rke-etcd-backup",
|
||||||
|
34
util/util.go
34
util/util.go
@ -8,15 +8,13 @@ import (
|
|||||||
|
|
||||||
"github.com/coreos/go-semver/semver"
|
"github.com/coreos/go-semver/semver"
|
||||||
ref "github.com/docker/distribution/reference"
|
ref "github.com/docker/distribution/reference"
|
||||||
v3 "github.com/rancher/types/apis/management.cattle.io/v3"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
WorkerThreads = 50
|
WorkerThreads = 50
|
||||||
// SupportedSyncToolsVersion this should be kept at the latest version of rke released with
|
|
||||||
// rancher 2.2.0.
|
DefaultRKETools = "rancher/rke-tools:v0.1.30"
|
||||||
SupportedSyncToolsVersion = "0.1.25"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func StrToSemVer(version string) (*semver.Version, error) {
|
func StrToSemVer(version string) (*semver.Version, error) {
|
||||||
@ -70,34 +68,6 @@ func IsSymlink(file string) (bool, error) {
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDefaultRKETools() string {
|
|
||||||
return v3.AllK8sVersions[v3.DefaultK8s].Alpine
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsRancherBackupSupported with rancher 2.2.0 and rke 0.2.0, etcdbackup was completely refactored
|
|
||||||
// and the interface for the rke-tools backup command changed significantly.
|
|
||||||
// This function is used to check the the release rke-tools version to choose
|
|
||||||
// between the new backup or the legacy backup code paths.
|
|
||||||
// The released version of rke-tools should be set in the const SupportedSyncToolsVersion
|
|
||||||
func IsRancherBackupSupported(image string) bool {
|
|
||||||
v := strings.Split(image, ":")
|
|
||||||
last := v[len(v)-1]
|
|
||||||
|
|
||||||
sv, err := StrToSemVer(last)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
supported, err := StrToSemVer(SupportedSyncToolsVersion)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if sv.LessThan(*supported) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetTagMajorVersion(tag string) string {
|
func GetTagMajorVersion(tag string) string {
|
||||||
splitTag := strings.Split(tag, ".")
|
splitTag := strings.Split(tag, ".")
|
||||||
if len(splitTag) < 2 {
|
if len(splitTag) < 2 {
|
||||||
|
Loading…
Reference in New Issue
Block a user