Add new admin replicate subcommand (#3810)
This change adds support for enabling site replication
This commit is contained in:
@@ -38,6 +38,7 @@ var adminCmdSubcommands = []cli.Command{
|
||||
adminUserCmd,
|
||||
adminGroupCmd,
|
||||
adminPolicyCmd,
|
||||
adminReplicateCmd,
|
||||
adminConfigCmd,
|
||||
adminHealCmd,
|
||||
adminProfileCmd,
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminReplicateAddCmd = cli.Command{
|
||||
Name: "add",
|
||||
Usage: "add one or more sites for replication",
|
||||
Action: mainAdminReplicateAdd,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} ALIAS1 ALIAS2 [ALIAS3...]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
|
||||
EXAMPLES:
|
||||
1. Add a site for cluster-level replication:
|
||||
{{.Prompt}} {{.HelpName}} minio1 minio2
|
||||
`,
|
||||
}
|
||||
|
||||
type successMessage madmin.ReplicateAddStatus
|
||||
|
||||
func (m successMessage) JSON() string {
|
||||
bs, e := json.MarshalIndent(madmin.ReplicateAddStatus(m), "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
return string(bs)
|
||||
}
|
||||
|
||||
func (m successMessage) String() string {
|
||||
v := madmin.ReplicateAddStatus(m)
|
||||
messages := []string{v.Status}
|
||||
|
||||
if v.ErrDetail != "" {
|
||||
messages = append(messages, v.ErrDetail)
|
||||
}
|
||||
if v.InitialSyncErrorMessage != "" {
|
||||
messages = append(messages, v.InitialSyncErrorMessage)
|
||||
}
|
||||
return console.Colorize("UserMessage", strings.Join(messages, "\n"))
|
||||
}
|
||||
|
||||
func mainAdminReplicateAdd(ctx *cli.Context) error {
|
||||
{
|
||||
// Check argument count
|
||||
argsNr := len(ctx.Args())
|
||||
if argsNr < 2 {
|
||||
fatalIf(errInvalidArgument().Trace(ctx.Args().Tail()...),
|
||||
"Need at least two arguments to add command.")
|
||||
}
|
||||
}
|
||||
|
||||
console.SetColor("UserMessage", color.New(color.FgGreen))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
ps := make([]madmin.PeerSite, 0, len(ctx.Args()))
|
||||
for _, clusterName := range ctx.Args() {
|
||||
admClient, err := newAdminClient(clusterName)
|
||||
fatalIf(err, "unable to initialize admin connection")
|
||||
|
||||
ak, sk := admClient.GetAccessAndSecretKey()
|
||||
ps = append(ps, madmin.PeerSite{
|
||||
Name: clusterName,
|
||||
Endpoint: admClient.GetEndpointURL().String(),
|
||||
AccessKey: ak,
|
||||
SecretKey: sk,
|
||||
})
|
||||
}
|
||||
|
||||
res, e := client.SiteReplicationAdd(globalContext, ps)
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to add sites for replication")
|
||||
|
||||
printMsg(successMessage(res))
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminReplicateInfoCmd = cli.Command{
|
||||
Name: "info",
|
||||
Usage: "get site replication information",
|
||||
Action: mainAdminReplicationInfo,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} ALIAS1
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
|
||||
EXAMPLES:
|
||||
1. Get Site Replication information:
|
||||
{{.Prompt}} {{.HelpName}} minio1
|
||||
`,
|
||||
}
|
||||
|
||||
type srInfo madmin.SiteReplicationInfo
|
||||
|
||||
func (i srInfo) JSON() string {
|
||||
bs, e := json.MarshalIndent(madmin.SiteReplicationInfo(i), "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
return string(bs)
|
||||
}
|
||||
|
||||
func (i srInfo) String() string {
|
||||
var messages []string
|
||||
info := madmin.SiteReplicationInfo(i)
|
||||
if info.Enabled {
|
||||
messages = []string{
|
||||
"SiteReplication: on",
|
||||
fmt.Sprintf("ServiceAccountAccessKey: %s", info.ServiceAccountAccessKey),
|
||||
"SiteReplicationMembers:",
|
||||
}
|
||||
for _, peer := range info.Sites {
|
||||
messages = append(messages, fmt.Sprintf(" Name: %s, Endpoint: %s, DeploymentID: %s", peer.Name, peer.Endpoint, peer.DeploymentID))
|
||||
}
|
||||
} else {
|
||||
messages = []string{"SiteReplication: off"}
|
||||
}
|
||||
|
||||
return console.Colorize("UserMessage", strings.Join(messages, "\n"))
|
||||
}
|
||||
|
||||
func mainAdminReplicationInfo(ctx *cli.Context) error {
|
||||
{
|
||||
// Check argument count
|
||||
argsNr := len(ctx.Args())
|
||||
if argsNr != 1 {
|
||||
fatalIf(errInvalidArgument().Trace(ctx.Args().Tail()...),
|
||||
"Need exactly one alias argument.")
|
||||
}
|
||||
}
|
||||
|
||||
console.SetColor("UserMessage", color.New(color.FgGreen))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
info, e := client.SiteReplicationInfo(globalContext)
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to get cluster replication information")
|
||||
|
||||
printMsg(srInfo(info))
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import "github.com/minio/cli"
|
||||
|
||||
var adminReplicateSubcommands = []cli.Command{
|
||||
adminReplicateAddCmd,
|
||||
// adminReplicateDisableCmd,
|
||||
adminReplicateInfoCmd,
|
||||
}
|
||||
|
||||
var adminReplicateCmd = cli.Command{
|
||||
Name: "replicate",
|
||||
Usage: "manage MinIO site replication",
|
||||
Action: mainAdminReplicate,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
Subcommands: adminReplicateSubcommands,
|
||||
HideHelpCommand: true,
|
||||
}
|
||||
|
||||
func mainAdminReplicate(ctx *cli.Context) error {
|
||||
commandNotFound(ctx, adminReplicateSubcommands)
|
||||
return nil
|
||||
}
|
||||
@@ -376,6 +376,9 @@ var completeCmds = map[string]complete.Predictor{
|
||||
"/admin/tier/edit": nil,
|
||||
"/admin/tier/ls": nil,
|
||||
|
||||
"/admin/replicate/add": aliasCompleter,
|
||||
"/admin/replicate/info": aliasCompleter,
|
||||
|
||||
"/alias/set": nil,
|
||||
"/alias/list": aliasCompleter,
|
||||
"/alias/remove": aliasCompleter,
|
||||
|
||||
@@ -26,7 +26,7 @@ require (
|
||||
github.com/minio/cli v1.22.0
|
||||
github.com/minio/colorjson v1.0.1
|
||||
github.com/minio/filepath v1.0.0
|
||||
github.com/minio/madmin-go v1.1.7-0.20211001214410-8c928b2b7bda
|
||||
github.com/minio/madmin-go v1.1.7
|
||||
github.com/minio/md5-simd v1.1.2 // indirect
|
||||
github.com/minio/minio-go/v7 v7.0.15-0.20211004160302-3b57c1e369ca
|
||||
github.com/minio/pkg v1.1.3
|
||||
|
||||
@@ -273,8 +273,8 @@ github.com/minio/colorjson v1.0.1/go.mod h1:oPM3zQQY8Gz9NGtgvuBEjQ+gPZLKAGc7T+kj
|
||||
github.com/minio/filepath v1.0.0 h1:fvkJu1+6X+ECRA6G3+JJETj4QeAYO9sV43I79H8ubDY=
|
||||
github.com/minio/filepath v1.0.0/go.mod h1:/nRZA2ldl5z6jT9/KQuvZcQlxZIMQoFFQPvEXx9T/Bw=
|
||||
github.com/minio/madmin-go v1.0.12/go.mod h1:BK+z4XRx7Y1v8SFWXsuLNqQqnq5BO/axJ8IDJfgyvfs=
|
||||
github.com/minio/madmin-go v1.1.7-0.20211001214410-8c928b2b7bda h1:nf1WPnmVKpfjFCOdX5yDwOi9tdqzJvh7hD2gMmOBM+A=
|
||||
github.com/minio/madmin-go v1.1.7-0.20211001214410-8c928b2b7bda/go.mod h1:vw+c3/u+DeVKqReEavo///Cl2OO8nt5s4ee843hJeLs=
|
||||
github.com/minio/madmin-go v1.1.7 h1:vZCnIfPlb40sBap+bmwvxG4/dSfkwF8QCRUHZL16Ylg=
|
||||
github.com/minio/madmin-go v1.1.7/go.mod h1:Iu0OnrMWNBYx1lqJTW+BFjBMx0Hi0wjw8VmqhiOs2Jo=
|
||||
github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw=
|
||||
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
|
||||
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
|
||||
|
||||
Reference in New Issue
Block a user