From 45409f67ba6cb47ca8fa929c2e759e8481b2bbc6 Mon Sep 17 00:00:00 2001 From: pjuarezd Date: Tue, 23 May 2023 14:52:52 -0700 Subject: [PATCH] `kubectl minio tenant expand` Setting a default name to the new pool when no explicit name is assigned Add make target to build krew plugin locally Signed-off-by: pjuarezd --- Makefile | 2 ++ kubectl-minio/cmd/resources/common.go | 6 ++++++ kubectl-minio/cmd/tenant-expand.go | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/Makefile b/Makefile index af604c4107c..b7813cd3256 100644 --- a/Makefile +++ b/Makefile @@ -82,6 +82,8 @@ plugin: regen-crd GO111MODULE=on ${GOPATH}/bin/golangci-lint cache clean && \ GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=5m --config ../.golangci.yml) +plugin-binary: plugin + @(cd $(PLUGIN_HOME) && CGO_ENABLED=0 go build -trimpath --ldflags $(LDFLAGS) -o kubectl-minio .) generate-code: @./k8s/update-codegen.sh diff --git a/kubectl-minio/cmd/resources/common.go b/kubectl-minio/cmd/resources/common.go index c5b4c909f25..2e991b62c8b 100644 --- a/kubectl-minio/cmd/resources/common.go +++ b/kubectl-minio/cmd/resources/common.go @@ -16,6 +16,7 @@ package resources import ( + "fmt" "io" "io/fs" "log" @@ -99,6 +100,11 @@ func Pool(opts *TenantOptions, volumes int32, q resource.Quantity) miniov2.Pool return p } +// GeneratePoolName Pool Name Generator +func GeneratePoolName(poolNumber int) string { + return fmt.Sprintf("pool-%d", poolNumber) +} + // GetSchemeDecoder returns a decoder for the scheme's that we use func GetSchemeDecoder() func(data []byte, defaults *schema.GroupVersionKind, into runtime.Object) (runtime.Object, *schema.GroupVersionKind, error) { sch := runtime.NewScheme() diff --git a/kubectl-minio/cmd/tenant-expand.go b/kubectl-minio/cmd/tenant-expand.go index f6dfc16089c..8894f27a97e 100644 --- a/kubectl-minio/cmd/tenant-expand.go +++ b/kubectl-minio/cmd/tenant-expand.go @@ -129,6 +129,11 @@ func (v *expandCmd) run() error { return err } + // Tenant pool id is zero based, generating pool using the count of existing pools in the tenant + if v.tenantOpts.PoolName == "" { + v.tenantOpts.PoolName = resources.GeneratePoolName(len(t.Spec.Pools)) + } + t.Spec.Pools = append(t.Spec.Pools, resources.Pool(&v.tenantOpts, volumesPerServer, *capacityPerVolume)) expandedCapacity := helpers.TotalCapacity(*t) if !v.output {