Skip to content

Commit

Permalink
fix: migrate to madmin-go package, remove dependency on minio (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana authored May 13, 2021
1 parent dd5c9a4 commit 35dabd3
Show file tree
Hide file tree
Showing 16 changed files with 326 additions and 1,178 deletions.
10 changes: 7 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ go 1.16
require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/go-cmp v0.5.4 // indirect
github.com/google/go-containerregistry v0.1.2
github.com/gorilla/mux v1.8.0
github.com/minio/minio v0.0.0-20210128013121-e79829b5b368
github.com/minio/minio-go/v7 v7.0.8-0.20210127003153-c40722862654
github.com/minio/controller-tools v0.4.7 // indirect
github.com/minio/madmin-go v1.0.5
github.com/minio/minio-go/v7 v7.0.11-0.20210302210017-6ae69c73ce78
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.46.0
github.com/prometheus-operator/prometheus-operator/pkg/client v0.46.0
github.com/secure-io/sio-go v0.3.1 // indirect
github.com/stretchr/testify v1.6.1
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
gopkg.in/yaml.v2 v2.3.0
k8s.io/api v0.20.2
k8s.io/apiextensions-apiserver v0.20.2
Expand Down
828 changes: 54 additions & 774 deletions go.sum

Large diffs are not rendered by default.

139 changes: 139 additions & 0 deletions kubectl-minio/cmd/color.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* This file is part of MinIO Operator
* Copyright (C) 2021, MinIO, Inc.
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

package cmd

import (
"fmt"

"github.com/fatih/color"
)

// global colors.
var (
// Check if we stderr, stdout are dumb terminals, we do not apply
// ansi coloring on dumb terminals.
IsTerminal = func() bool {
return !color.NoColor
}

Bold = func() func(a ...interface{}) string {
if IsTerminal() {
return color.New(color.Bold).SprintFunc()
}
return fmt.Sprint
}()

RedBold = func() func(format string, a ...interface{}) string {
if IsTerminal() {
return color.New(color.FgRed, color.Bold).SprintfFunc()
}
return fmt.Sprintf
}()

Red = func() func(format string, a ...interface{}) string {
if IsTerminal() {
return color.New(color.FgRed).SprintfFunc()
}
return fmt.Sprintf
}()

Blue = func() func(format string, a ...interface{}) string {
if IsTerminal() {
return color.New(color.FgBlue).SprintfFunc()
}
return fmt.Sprintf
}()

Yellow = func() func(format string, a ...interface{}) string {
if IsTerminal() {
return color.New(color.FgYellow).SprintfFunc()
}
return fmt.Sprintf
}()

Green = func() func(a ...interface{}) string {
if IsTerminal() {
return color.New(color.FgGreen).SprintFunc()
}
return fmt.Sprint
}()

GreenBold = func() func(a ...interface{}) string {
if IsTerminal() {
return color.New(color.FgGreen, color.Bold).SprintFunc()
}
return fmt.Sprint
}()

CyanBold = func() func(a ...interface{}) string {
if IsTerminal() {
return color.New(color.FgCyan, color.Bold).SprintFunc()
}
return fmt.Sprint
}()

YellowBold = func() func(format string, a ...interface{}) string {
if IsTerminal() {
return color.New(color.FgYellow, color.Bold).SprintfFunc()
}
return fmt.Sprintf
}()

BlueBold = func() func(format string, a ...interface{}) string {
if IsTerminal() {
return color.New(color.FgBlue, color.Bold).SprintfFunc()
}
return fmt.Sprintf
}()

BgYellow = func() func(format string, a ...interface{}) string {
if IsTerminal() {
return color.New(color.BgYellow).SprintfFunc()
}
return fmt.Sprintf
}()

Black = func() func(format string, a ...interface{}) string {
if IsTerminal() {
return color.New(color.FgBlack).SprintfFunc()
}
return fmt.Sprintf
}()

FgRed = func() func(a ...interface{}) string {
if IsTerminal() {
return color.New(color.FgRed).SprintFunc()
}
return fmt.Sprint
}()

BgRed = func() func(format string, a ...interface{}) string {
if IsTerminal() {
return color.New(color.BgRed).SprintfFunc()
}
return fmt.Sprintf
}()

FgWhite = func() func(format string, a ...interface{}) string {
if IsTerminal() {
return color.New(color.FgWhite).SprintfFunc()
}
return fmt.Sprintf
}()
)
3 changes: 1 addition & 2 deletions kubectl-minio/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import (

"github.com/minio/kubectl-minio/cmd/helpers"
"github.com/minio/kubectl-minio/cmd/resources"
"github.com/minio/minio/pkg/color"
"github.com/spf13/cobra"

"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -75,7 +74,7 @@ func newDeleteCmd(out io.Writer, errOut io.Writer) *cobra.Command {
Example: deleteExample,
PreRunE: func(cmd *cobra.Command, args []string) error {
if !helpers.Ask(fmt.Sprintf("Are you sure you want to delete ALL the MinIO Tenants and MinIO Operator?")) {
return fmt.Errorf(color.Bold("Aborting Operator deletion\n"))
return fmt.Errorf(Bold("Aborting Operator deletion\n"))
}
return nil
},
Expand Down
26 changes: 13 additions & 13 deletions kubectl-minio/cmd/resources/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ import (

// TenantOptions encapsulates the CLI options for a MinIO Tenant
type TenantOptions struct {
Name string
SecretName string
Servers int32
Volumes int32
Capacity string
NS string
Image string
StorageClass string
KmsSecret string
ConsoleSecret string
DisableTLS bool
ImagePullSecret string
DisableAntiAffinity bool
Name string
SecretName string
Servers int32
Volumes int32
Capacity string
NS string
Image string
StorageClass string
KmsSecret string
ConsoleSecret string
DisableTLS bool
ImagePullSecret string
DisableAntiAffinity bool
}

// Validate Tenant Options
Expand Down
11 changes: 5 additions & 6 deletions kubectl-minio/cmd/tenant-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (

"github.com/minio/kubectl-minio/cmd/helpers"
"github.com/minio/kubectl-minio/cmd/resources"
"github.com/minio/minio/pkg/color"
miniov2 "github.com/minio/operator/pkg/apis/minio.min.io/v2"
operatorv1 "github.com/minio/operator/pkg/client/clientset/versioned"
"github.com/minio/operator/pkg/resources/services"
Expand Down Expand Up @@ -172,18 +171,18 @@ func createTenant(oclient *operatorv1.Clientset, kclient *kubernetes.Clientset,
}
minSvc := services.NewClusterIPForMinIO(to)
conSvc := services.NewClusterIPForConsole(to)
if color.IsTerminal() {
if IsTerminal() {
printBanner(to.ObjectMeta.Name, to.ObjectMeta.Namespace, string(console.Data["CONSOLE_ACCESS_KEY"]), string(console.Data["CONSOLE_SECRET_KEY"]),
minSvc, conSvc)
}
return nil
}

func printBanner(tenantName, ns, user, pwd string, s, c *corev1.Service) {
fmt.Printf(color.Bold(fmt.Sprintf("\nTenant '%s' created in '%s' Namespace\n\n", tenantName, ns)))
fmt.Printf(color.Blue(" Username: %s \n", user))
fmt.Printf(color.Blue(" Password: %s \n", pwd))
fmt.Printf(color.Blue(" Note: Copy the credentials to a secure location. MinIO will not display these again.\n\n"))
fmt.Printf(Bold(fmt.Sprintf("\nTenant '%s' created in '%s' Namespace\n\n", tenantName, ns)))
fmt.Printf(Blue(" Username: %s \n", user))
fmt.Printf(Blue(" Password: %s \n", pwd))
fmt.Printf(Blue(" Note: Copy the credentials to a secure location. MinIO will not display these again.\n\n"))
var minPorts, consolePorts string
for _, p := range s.Spec.Ports {
minPorts = minPorts + strconv.Itoa(int(p.Port)) + ","
Expand Down
3 changes: 1 addition & 2 deletions kubectl-minio/cmd/tenant-delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"io"

"github.com/minio/kubectl-minio/cmd/helpers"
"github.com/minio/minio/pkg/color"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -60,7 +59,7 @@ func newTenantDeleteCmd(out io.Writer, errOut io.Writer) *cobra.Command {
return err
}
if !helpers.Ask(fmt.Sprintf("This will delete the Tenant %s and ALL its data. Do you want to proceed?", args[0])) {
return fmt.Errorf(color.Bold("Aborting Tenant deletion\n"))
return fmt.Errorf(Bold("Aborting Tenant deletion\n"))
}
return nil
},
Expand Down
3 changes: 1 addition & 2 deletions kubectl-minio/cmd/tenant-expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"github.com/minio/kubectl-minio/cmd/helpers"
"github.com/minio/kubectl-minio/cmd/resources"
"github.com/minio/minio/pkg/color"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -123,7 +122,7 @@ func (v *expandCmd) run() error {
t.Spec.Pools = append(t.Spec.Pools, resources.Pool(&v.tenantOpts, volumesPerServer, *capacityPerVolume))
expandedCapacity := helpers.TotalCapacity(*t)
if !v.output {
fmt.Printf(color.Bold(fmt.Sprintf("\nExpanding Tenant '%s/%s' from %s to %s\n\n", t.ObjectMeta.Name, t.ObjectMeta.Namespace, currentCapacity, expandedCapacity)))
fmt.Printf(Bold(fmt.Sprintf("\nExpanding Tenant '%s/%s' from %s to %s\n\n", t.ObjectMeta.Name, t.ObjectMeta.Namespace, currentCapacity, expandedCapacity)))
return addPoolToTenant(client, t)
}

Expand Down
15 changes: 7 additions & 8 deletions kubectl-minio/cmd/tenant-info.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"strings"

"github.com/minio/kubectl-minio/cmd/helpers"
"github.com/minio/minio/pkg/color"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"

Expand Down Expand Up @@ -114,14 +113,14 @@ func printTenantInfo(tenant miniov2.Tenant) {
for _, p := range conSvc.Spec.Ports {
consolePorts = consolePorts + strconv.Itoa(int(p.Port)) + ","
}
fmt.Printf(color.Bold(fmt.Sprintf("\nTenant '%s/%s', total capacity %s\n\n", tenant.Name, tenant.ObjectMeta.Namespace, helpers.TotalCapacity(tenant))))
fmt.Printf(color.Blue(" Current status: %s \n", tenant.Status.CurrentState))
fmt.Printf(color.Blue(" MinIO version: %s \n", tenant.Spec.Image))
fmt.Printf(color.Blue(" MinIO service: %s/ClusterIP (port %s)\n\n", minSvc.Name, strings.TrimSuffix(minPorts, ",")))
fmt.Printf(color.Blue(" Console version: %s \n", tenant.Spec.Console.Image))
fmt.Printf(color.Blue(" Console service: %s/ClusterIP (port %s)\n\n", conSvc.Name, strings.TrimSuffix(consolePorts, ",")))
fmt.Printf(Bold(fmt.Sprintf("\nTenant '%s/%s', total capacity %s\n\n", tenant.Name, tenant.ObjectMeta.Namespace, helpers.TotalCapacity(tenant))))
fmt.Printf(Blue(" Current status: %s \n", tenant.Status.CurrentState))
fmt.Printf(Blue(" MinIO version: %s \n", tenant.Spec.Image))
fmt.Printf(Blue(" MinIO service: %s/ClusterIP (port %s)\n\n", minSvc.Name, strings.TrimSuffix(minPorts, ",")))
fmt.Printf(Blue(" Console version: %s \n", tenant.Spec.Console.Image))
fmt.Printf(Blue(" Console service: %s/ClusterIP (port %s)\n\n", conSvc.Name, strings.TrimSuffix(consolePorts, ",")))
if tenant.Spec.KES != nil && tenant.Spec.KES.Image != "" {
fmt.Printf(color.Blue(" KES version: %s \n\n", tenant.Spec.KES.Image))
fmt.Printf(Blue(" KES version: %s \n\n", tenant.Spec.KES.Image))
}

t := helpers.GetTable()
Expand Down
5 changes: 2 additions & 3 deletions kubectl-minio/cmd/tenant-upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"github.com/minio/kubectl-minio/cmd/helpers"
"github.com/minio/kubectl-minio/cmd/resources"
"github.com/minio/minio/pkg/color"
miniov2 "github.com/minio/operator/pkg/apis/minio.min.io/v2"
operatorv1 "github.com/minio/operator/pkg/client/clientset/versioned"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -152,14 +151,14 @@ func (u *upgradeCmd) run() error {

func (u *upgradeCmd) upgradeTenant(client *operatorv1.Clientset, t *miniov2.Tenant, c, p string) error {
if helpers.Ask(fmt.Sprintf("Upgrade is a one way process. Are you sure to upgrade Tenant '%s/%s' from version %s to %s?", t.ObjectMeta.Name, t.ObjectMeta.Namespace, c, p)) {
fmt.Printf(color.Bold(fmt.Sprintf("\nUpgrading Tenant '%s/%s'\n\n", t.ObjectMeta.Name, t.ObjectMeta.Namespace)))
fmt.Printf(Bold(fmt.Sprintf("\nUpgrading Tenant '%s/%s'\n\n", t.ObjectMeta.Name, t.ObjectMeta.Namespace)))
// update the image
t.Spec.Image = u.tenantOpts.Image
if _, err := client.MinioV2().Tenants(t.Namespace).Update(context.Background(), t, v1.UpdateOptions{}); err != nil {
return err
}
} else {
fmt.Printf(color.Bold(fmt.Sprintf("\nAborting Tenant upgrade\n\n")))
fmt.Printf(Bold(fmt.Sprintf("\nAborting Tenant upgrade\n\n")))
}
return nil
}
5 changes: 1 addition & 4 deletions kubectl-minio/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ require (
github.com/google/uuid v1.1.2
github.com/manifoldco/promptui v0.8.0
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/minio/controller-tools v0.4.7 // indirect
github.com/minio/minio v0.0.0-20210128013121-e79829b5b368
github.com/minio/operator v0.3.23
github.com/montanaflynn/stats v0.6.3 // indirect
github.com/minio/operator v0.0.0-00010101000000-000000000000
github.com/olekukonko/tablewriter v0.0.4
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.1.1
Expand Down
Loading

0 comments on commit 35dabd3

Please sign in to comment.