Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Need-Discussion] Separate tier add command to sub commands per tier backend #4801

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/admin-tier-deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ EXAMPLES:
Hidden: true,
OnUsageError: onUsageError,
Before: setGlobalsFromContext,
Flags: append(globalFlags, adminTierAddFlags...),
Flags: append(globalFlags, adminTierAddMinioFlags...),
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}
Expand Down
145 changes: 145 additions & 0 deletions cmd/ilm-tier-add-azure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Copyright (c) 2015-2023 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"
"github.com/minio/madmin-go/v3"
"github.com/minio/mc/pkg/probe"
)

var adminTierAddAzureFlags = []cli.Flag{
cli.StringFlag{
Name: "endpoint",
Value: "",
Usage: "remote tier endpoint. e.g https://s3.amazonaws.com",
},
cli.StringFlag{
Name: "region",
Value: "",
Usage: "remote tier region. e.g us-west-2",
},
cli.StringFlag{
Name: "account-name",
Value: "",
Usage: "Azure Blob Storage account name",
},
cli.StringFlag{
Name: "account-key",
Value: "",
Usage: "Azure Blob Storage account key",
},
cli.StringFlag{
Name: "sp-tenant-id",
Value: "",
Usage: "Directory ID for the Azure service principal account",
},
cli.StringFlag{
Name: "sp-client-id",
Value: "",
Usage: "The client ID of the Azure service principal account",
},
cli.StringFlag{
Name: "sp-client-secret",
Value: "",
Usage: "The client secret of the Azure service principal account",
},
cli.StringFlag{
Name: "bucket",
Value: "",
Usage: "remote tier bucket",
},
cli.StringFlag{
Name: "prefix",
Value: "",
Usage: "remote tier prefix",
},
}

var adminTierAddAzureCmd = cli.Command{
Name: "azure",
Usage: "add a new Azure remote tier target",
Action: mainAdminTierAddAzure,
OnUsageError: onUsageError,
Before: setGlobalsFromContext,
Flags: append(globalFlags, adminTierAddAzureFlags...),
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}

USAGE:
{{.HelpName}} ALIAS TIER-NAME [FLAGS]

TIER-NAME:
Name of the remote tier target. e.g WARM-TIER

FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Configure a new remote tier which transitions objects to a bucket in Azure Blob Storage:
{{.Prompt}} {{.HelpName}} azure myminio AZTIER --account-name ACCOUNT-NAME --account-key ACCOUNT-KEY \
--bucket myazurebucket --prefix myazureprefix/

`,
}

func fetchAzureTierConfig(ctx *cli.Context, tierName string) *madmin.TierConfig {
accountName := ctx.String("account-name")
accountKey := ctx.String("account-key")
if accountName == "" {
fatalIf(errDummy().Trace(), "Azure remote tier requires the storage account name")
}

if accountKey == "" && (ctx.String("az-sp-tenant-id") == "" || ctx.String("az-sp-client-id") == "" || ctx.String("az-sp-client-secret") == "") {
fatalIf(errDummy().Trace(), "Azure remote tier requires static credentials OR service principal credentials")
}

bucket := ctx.String("bucket")
if bucket == "" {
fatalIf(errDummy().Trace(), "Azure remote tier requires target bucket")
}

azOpts := []madmin.AzureOptions{}
endpoint := ctx.String("endpoint")
if endpoint != "" {
azOpts = append(azOpts, madmin.AzureEndpoint(endpoint))
}

region := ctx.String("region")
if region != "" {
azOpts = append(azOpts, madmin.AzureRegion(region))
}

prefix := ctx.String("prefix")
if prefix != "" {
azOpts = append(azOpts, madmin.AzurePrefix(prefix))
}

if ctx.String("sp-tenant-id") != "" || ctx.String("sp-client-id") != "" || ctx.String("sp-client-secret") != "" {
azOpts = append(azOpts, madmin.AzureServicePrincipal(ctx.String("sp-tenant-id"), ctx.String("sp-client-id"), ctx.String("sp-client-secret")))
}

azCfg, e := madmin.NewTierAzure(tierName, accountName, accountKey, bucket, azOpts...)
fatalIf(probe.NewError(e), "Invalid configuration for Azure Blob Storage remote tier")

return azCfg
}

func mainAdminTierAddAzure(ctx *cli.Context) error {
return genericTierAddCmd(ctx, madmin.Azure)
}
106 changes: 106 additions & 0 deletions cmd/ilm-tier-add-gcs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright (c) 2015-2023 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 (
"os"

"github.com/minio/cli"
"github.com/minio/madmin-go/v3"
"github.com/minio/mc/pkg/probe"
)

var adminTierAddGCSFlags = []cli.Flag{
cli.StringFlag{
Name: "region",
Value: "",
Usage: "remote tier region. e.g us-west-2",
},
cli.StringFlag{
Name: "credentials-file",
Value: "",
Usage: "path to Google Cloud Storage credentials file",
},
cli.StringFlag{
Name: "bucket",
Value: "",
Usage: "remote tier bucket",
},
cli.StringFlag{
Name: "prefix",
Value: "",
Usage: "remote tier prefix",
},
}

var adminTierAddGCSCmd = cli.Command{
Name: "gcs",
Usage: "add a new GCS remote tier target",
Action: mainAdminTierAddGCS,
OnUsageError: onUsageError,
Before: setGlobalsFromContext,
Flags: append(globalFlags, adminTierAddGCSFlags...),
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}

USAGE:
{{.HelpName}} ALIAS TIER-NAME [FLAGS]

TIER-NAME:
Name of the remote tier target. e.g WARM-TIER

FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Configure a new remote tier which transitions objects to a bucket in Google Cloud Storage:
{{.Prompt}} {{.HelpName}} gcs myminio GCSTIER --credentials-file /path/to/credentials.json \
--bucket mygcsbucket --prefix mygcsprefix/
`,
}

func fetchGCSTierConfig(ctx *cli.Context, tierName string) *madmin.TierConfig {
bucket := ctx.String("bucket")
if bucket == "" {
fatalIf(errInvalidArgument().Trace(), "GCS remote requires target bucket")
}

gcsOpts := []madmin.GCSOptions{}
prefix := ctx.String("prefix")
if prefix != "" {
gcsOpts = append(gcsOpts, madmin.GCSPrefix(prefix))
}

region := ctx.String("region")
if region != "" {
gcsOpts = append(gcsOpts, madmin.GCSRegion(region))
}

credsPath := ctx.String("credentials-file")
credsBytes, e := os.ReadFile(credsPath)
fatalIf(probe.NewError(e), "Failed to read credentials file")

gcsCfg, e := madmin.NewTierGCS(tierName, credsBytes, bucket, gcsOpts...)
fatalIf(probe.NewError(e), "Invalid configuration for Google Cloud Storage remote tier")

return gcsCfg
}

func mainAdminTierAddGCS(ctx *cli.Context) error {
return genericTierAddCmd(ctx, madmin.GCS)
}
120 changes: 120 additions & 0 deletions cmd/ilm-tier-add-minio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Copyright (c) 2015-2023 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"
"github.com/minio/madmin-go/v3"
"github.com/minio/mc/pkg/probe"
)

var adminTierAddMinioFlags = []cli.Flag{
cli.StringFlag{
Name: "endpoint",
Value: "",
Usage: "remote tier endpoint. e.g https://s3.amazonaws.com",
},
cli.StringFlag{
Name: "region",
Value: "",
Usage: "remote tier region. e.g us-west-2",
},
cli.StringFlag{
Name: "access-key",
Value: "",
Usage: "MinIO object storage access-key",
},
cli.StringFlag{
Name: "secret-key",
Value: "",
Usage: "MinIO object storage secret-key",
},
cli.StringFlag{
Name: "bucket",
Value: "",
Usage: "remote tier bucket",
},
cli.StringFlag{
Name: "prefix",
Value: "",
Usage: "remote tier prefix",
},
}

var adminTierAddMinioCmd = cli.Command{
Name: "minio",
Usage: "add a new MinIO remote tier target",
Action: mainAdminTierAddMinio,
OnUsageError: onUsageError,
Before: setGlobalsFromContext,
Flags: append(globalFlags, adminTierAddMinioFlags...),
CustomHelpTemplate: `NAME:
{{.HelpName}} - {{.Usage}}

USAGE:
{{.HelpName}} ALIAS TIER-NAME [FLAGS]

TIER-NAME:
Name of the remote tier target. e.g WARM-TIER

FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Configure a new remote tier which transitions objects to a bucket in a MinIO deployment:
{{.Prompt}} {{.HelpName}} minio myminio WARM-MINIO-TIER --endpoint https://warm-minio.com \
--access-key ACCESSKEY --secret-key SECRETKEY --bucket mybucket --prefix myprefix/
`,
}

func fetchMinioTierConfig(ctx *cli.Context, tierName string) *madmin.TierConfig {
accessKey := ctx.String("access-key")
secretKey := ctx.String("secret-key")
if accessKey == "" || secretKey == "" {
fatalIf(errInvalidArgument().Trace(), "MinIO remote tier requires access credentials")
}
bucket := ctx.String("bucket")
if bucket == "" {
fatalIf(errInvalidArgument().Trace(), "MinIO remote tier requires target bucket")
}

endpoint := ctx.String("endpoint")
if endpoint == "" {
fatalIf(errInvalidArgument().Trace(), "MinIO remote tier requires target endpoint")
}

minioOpts := []madmin.MinIOOptions{}
prefix := ctx.String("prefix")
if prefix != "" {
minioOpts = append(minioOpts, madmin.MinIOPrefix(prefix))
}

region := ctx.String("region")
if region != "" {
minioOpts = append(minioOpts, madmin.MinIORegion(region))
}

minioCfg, e := madmin.NewTierMinIO(tierName, endpoint, accessKey, secretKey, bucket, minioOpts...)
fatalIf(probe.NewError(e), "Invalid configuration for MinIO tier")

return minioCfg
}

func mainAdminTierAddMinio(ctx *cli.Context) error {
return genericTierAddCmd(ctx, madmin.MinIO)
}
Loading
Loading