mirror of
https://github.com/rancher/rke.git
synced 2025-09-16 15:10:12 +00:00
add etcd s3 uploading and downloading snapshot feature
This commit is contained in:
committed by
Alena Prokharchyk
parent
9db25ef841
commit
9cfe5661d8
@@ -3,14 +3,15 @@ package cmd
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/rancher/rke/cluster"
|
||||
"github.com/rancher/rke/hosts"
|
||||
"github.com/rancher/rke/log"
|
||||
"github.com/rancher/types/apis/management.cattle.io/v3"
|
||||
"github.com/urfave/cli"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var commonFlags = []cli.Flag{
|
||||
@@ -32,7 +33,7 @@ func resolveClusterFile(ctx *cli.Context) (string, string, error) {
|
||||
}
|
||||
file, err := os.Open(fp)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("Can not find cluster configuration file: %v", err)
|
||||
return "", "", fmt.Errorf("can not find cluster configuration file: %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
buf, err := ioutil.ReadAll(file)
|
||||
@@ -53,6 +54,12 @@ func setOptionsFromCLI(c *cli.Context, rkeConfig *v3.RancherKubernetesEngineConf
|
||||
rkeConfig.IgnoreDockerVersion = c.Bool("ignore-docker-version")
|
||||
}
|
||||
|
||||
if c.Bool("s3") {
|
||||
if rkeConfig.Services.Etcd.BackupConfig == nil {
|
||||
rkeConfig.Services.Etcd.BackupConfig = &v3.BackupConfig{}
|
||||
}
|
||||
rkeConfig.Services.Etcd.BackupConfig.S3BackupConfig = setS3OptionsFromCLI(c)
|
||||
}
|
||||
return rkeConfig, nil
|
||||
}
|
||||
|
||||
@@ -91,3 +98,28 @@ func ClusterInit(ctx context.Context, rkeConfig *v3.RancherKubernetesEngineConfi
|
||||
}
|
||||
return rkeState.WriteStateFile(ctx, stateFilePath)
|
||||
}
|
||||
|
||||
func setS3OptionsFromCLI(c *cli.Context) *v3.S3BackupConfig {
|
||||
endpoint := c.String("s3-endpoint")
|
||||
bucketName := c.String("bucket-name")
|
||||
region := c.String("region")
|
||||
accessKey := c.String("access-key")
|
||||
secretKey := c.String("secret-key")
|
||||
var s3BackupBackend = &v3.S3BackupConfig{}
|
||||
if len(endpoint) != 0 {
|
||||
s3BackupBackend.Endpoint = endpoint
|
||||
}
|
||||
if len(bucketName) != 0 {
|
||||
s3BackupBackend.BucketName = bucketName
|
||||
}
|
||||
if len(region) != 0 {
|
||||
s3BackupBackend.Region = region
|
||||
}
|
||||
if len(accessKey) != 0 {
|
||||
s3BackupBackend.AccessKey = accessKey
|
||||
}
|
||||
if len(secretKey) != 0 {
|
||||
s3BackupBackend.SecretKey = secretKey
|
||||
}
|
||||
return s3BackupBackend
|
||||
}
|
||||
|
Reference in New Issue
Block a user