mirror of
https://github.com/minio/minio.git
synced 2025-11-07 04:42:56 -05:00
Update federation target to etcd/clientv3 (#6119)
With CoreDNS now supporting etcdv3 as the DNS backend, we can update our federation target to etcdv3. Users will now be able to use etcdv3 server as the federation backbone. Minio will update bucket data to etcdv3 and CoreDNS can pick that data up and serve it as bucket style DNS path.
This commit is contained in:
committed by
kannappanr
parent
adf7340394
commit
2aa18cafc6
@@ -30,7 +30,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
etcd "github.com/coreos/etcd/client"
|
||||
etcd "github.com/coreos/etcd/clientv3"
|
||||
dns "github.com/minio/minio/pkg/dns"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
@@ -125,7 +126,7 @@ func saveFileConfig(filename string, v interface{}) error {
|
||||
|
||||
}
|
||||
|
||||
func saveFileConfigEtcd(filename string, clnt etcd.Client, v interface{}) error {
|
||||
func saveFileConfigEtcd(filename string, clnt *etcd.Client, v interface{}) error {
|
||||
// Fetch filename's extension
|
||||
ext := filepath.Ext(filename)
|
||||
// Marshal data
|
||||
@@ -137,44 +138,34 @@ func saveFileConfigEtcd(filename string, clnt etcd.Client, v interface{}) error
|
||||
dataBytes = []byte(strings.Replace(string(dataBytes), "\n", "\r\n", -1))
|
||||
}
|
||||
|
||||
kapi := etcd.NewKeysAPI(clnt)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
||||
_, err = kapi.Update(ctx, filename, string(dataBytes))
|
||||
if etcd.IsKeyNotFound(err) {
|
||||
_, err = kapi.Create(ctx, filename, string(dataBytes))
|
||||
}
|
||||
cancel()
|
||||
_, err = clnt.Put(ctx, filename, string(dataBytes))
|
||||
defer cancel()
|
||||
return err
|
||||
}
|
||||
|
||||
func loadFileConfigEtcd(filename string, clnt etcd.Client, v interface{}) error {
|
||||
kapi := etcd.NewKeysAPI(clnt)
|
||||
func loadFileConfigEtcd(filename string, clnt *etcd.Client, v interface{}) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
||||
resp, err := kapi.Get(ctx, filename, nil)
|
||||
cancel()
|
||||
resp, err := clnt.Get(ctx, filename)
|
||||
defer cancel()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.Count == 0 {
|
||||
return dns.ErrNoEntriesFound
|
||||
}
|
||||
|
||||
var ev *etcd.Node
|
||||
switch {
|
||||
case resp.Node.Dir:
|
||||
for _, ev = range resp.Node.Nodes {
|
||||
if string(ev.Key) == filename {
|
||||
break
|
||||
for _, ev := range resp.Kvs {
|
||||
if string(ev.Key) == filename {
|
||||
fileData := ev.Value
|
||||
if runtime.GOOS == "windows" {
|
||||
fileData = bytes.Replace(fileData, []byte("\r\n"), []byte("\n"), -1)
|
||||
}
|
||||
// Unmarshal file's content
|
||||
return toUnmarshaller(filepath.Ext(filename))(fileData, v)
|
||||
}
|
||||
default:
|
||||
ev = resp.Node
|
||||
}
|
||||
|
||||
fileData := ev.Value
|
||||
if runtime.GOOS == "windows" {
|
||||
fileData = strings.Replace(ev.Value, "\r\n", "\n", -1)
|
||||
}
|
||||
|
||||
// Unmarshal file's content
|
||||
return toUnmarshaller(filepath.Ext(filename))([]byte(fileData), v)
|
||||
return dns.ErrNoEntriesFound
|
||||
}
|
||||
|
||||
// loadFileConfig unmarshals the file's content with the right
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
etcd "github.com/coreos/etcd/client"
|
||||
etcd "github.com/coreos/etcd/clientv3"
|
||||
"github.com/fatih/structs"
|
||||
"github.com/minio/minio/pkg/safe"
|
||||
)
|
||||
@@ -45,7 +45,7 @@ type Config interface {
|
||||
// config - implements quick.Config interface
|
||||
type config struct {
|
||||
data interface{}
|
||||
clnt etcd.Client
|
||||
clnt *etcd.Client
|
||||
lock *sync.RWMutex
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ func writeFile(filename string, data []byte) error {
|
||||
}
|
||||
|
||||
// GetVersion - extracts the version information.
|
||||
func GetVersion(filename string, clnt etcd.Client) (version string, err error) {
|
||||
func GetVersion(filename string, clnt *etcd.Client) (version string, err error) {
|
||||
var qc Config
|
||||
qc, err = LoadConfig(filename, clnt, &struct {
|
||||
Version string
|
||||
@@ -201,7 +201,7 @@ func GetVersion(filename string, clnt etcd.Client) (version string, err error) {
|
||||
}
|
||||
|
||||
// LoadConfig - loads json config from filename for the a given struct data
|
||||
func LoadConfig(filename string, clnt etcd.Client, data interface{}) (qc Config, err error) {
|
||||
func LoadConfig(filename string, clnt *etcd.Client, data interface{}) (qc Config, err error) {
|
||||
qc, err = NewConfig(data, clnt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -210,7 +210,7 @@ func LoadConfig(filename string, clnt etcd.Client, data interface{}) (qc Config,
|
||||
}
|
||||
|
||||
// SaveConfig - saves given configuration data into given file as JSON.
|
||||
func SaveConfig(data interface{}, filename string, clnt etcd.Client) (err error) {
|
||||
func SaveConfig(data interface{}, filename string, clnt *etcd.Client) (err error) {
|
||||
if err = checkData(data); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -224,7 +224,7 @@ func SaveConfig(data interface{}, filename string, clnt etcd.Client) (err error)
|
||||
|
||||
// NewConfig loads config from etcd client if provided, otherwise loads from a local filename.
|
||||
// fails when all else fails.
|
||||
func NewConfig(data interface{}, clnt etcd.Client) (cfg Config, err error) {
|
||||
func NewConfig(data interface{}, clnt *etcd.Client) (cfg Config, err error) {
|
||||
if err := checkData(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user