From 581085e1a047970347a793267122d544cedf98b1 Mon Sep 17 00:00:00 2001 From: Allan Reid Date: Wed, 24 Jan 2024 08:31:13 -0800 Subject: [PATCH] Allow editing pools when multiple pools exist --- kubectl-minio/cmd/resources/common.go | 18 ++++++-- kubectl-minio/cmd/tenant-expand.go | 4 +- web-app/src/common/utils.ts | 8 +++- .../Pools/EditPool/thunks/editPoolAsync.ts | 41 +++++++++---------- 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/kubectl-minio/cmd/resources/common.go b/kubectl-minio/cmd/resources/common.go index 3e381dd96ac..56f9ac3a0f1 100644 --- a/kubectl-minio/cmd/resources/common.go +++ b/kubectl-minio/cmd/resources/common.go @@ -21,6 +21,7 @@ import ( "io/fs" "log" "path" + "slices" "strings" "sigs.k8s.io/kustomize/kyaml/filesys" @@ -94,7 +95,7 @@ func Pool(opts *TenantOptions, volumes int32, q resource.Quantity) miniov2.Pool { Key: miniov2.PoolLabel, Operator: "In", - Values: []string{opts.Name}, + Values: []string{opts.PoolName}, }, }, }, @@ -108,8 +109,19 @@ func Pool(opts *TenantOptions, volumes int32, q resource.Quantity) miniov2.Pool } // GeneratePoolName Pool Name Generator -func GeneratePoolName(poolNumber int) string { - return fmt.Sprintf("pool-%d", poolNumber) +func GeneratePoolName(pools []miniov2.Pool) string { + poolCounter := 0 + var poolNames []string + for _, pool := range pools { + poolNames = append(poolNames, pool.Name) + } + for poolCounter < len(poolNames) { + if !(slices.Contains(poolNames, fmt.Sprintf("pool-%d", poolCounter))) { + return fmt.Sprintf("pool-%d", poolCounter) + } + poolCounter++ + } + return fmt.Sprintf("pool-%d", poolCounter) } // GetSchemeDecoder returns a decoder for the scheme's that we use diff --git a/kubectl-minio/cmd/tenant-expand.go b/kubectl-minio/cmd/tenant-expand.go index ceba31e5f2c..ec403db777b 100644 --- a/kubectl-minio/cmd/tenant-expand.go +++ b/kubectl-minio/cmd/tenant-expand.go @@ -137,9 +137,9 @@ func (v *expandCmd) run() error { return err } - // Tenant pool id is zero based, generating pool using the count of existing pools in the tenant + // Generate pool name using the state of existing pools in the tenant if v.tenantOpts.PoolName == "" { - v.tenantOpts.PoolName = resources.GeneratePoolName(len(t.Spec.Pools)) + v.tenantOpts.PoolName = resources.GeneratePoolName(t.Spec.Pools) } t.Spec.Pools = append(t.Spec.Pools, resources.Pool(&v.tenantOpts, v.tenantOpts.VolumesPerServer, *capacityPerVolume)) diff --git a/web-app/src/common/utils.ts b/web-app/src/common/utils.ts index af973170308..331b9b7bb91 100644 --- a/web-app/src/common/utils.ts +++ b/web-app/src/common/utils.ts @@ -453,7 +453,13 @@ export const erasureCodeCalc = ( // Pool Name Generator export const generatePoolName = (pools: Pool[]) => { - const poolCounter = pools.length; + let poolCounter = 0; + const poolNames = pools.map((pool) => pool.name || ""); + for (; poolCounter < pools.length; poolCounter++) { + if (!poolNames.includes(`pool-${poolCounter}`)) { + return `pool-${poolCounter}`; + } + } return `pool-${poolCounter}`; }; diff --git a/web-app/src/screens/Console/Tenants/TenantDetails/Pools/EditPool/thunks/editPoolAsync.ts b/web-app/src/screens/Console/Tenants/TenantDetails/Pools/EditPool/thunks/editPoolAsync.ts index 3c9dfb64fea..e314bd5fb80 100644 --- a/web-app/src/screens/Console/Tenants/TenantDetails/Pools/EditPool/thunks/editPoolAsync.ts +++ b/web-app/src/screens/Console/Tenants/TenantDetails/Pools/EditPool/thunks/editPoolAsync.ts @@ -23,11 +23,7 @@ import { getDefaultAffinity, getNodeSelector } from "../../../utils"; import { resetEditPoolForm } from "../editPoolSlice"; import { getTenantAsync } from "../../../../thunks/tenantDetailsAsync"; import { api } from "../../../../../../../api"; -import { - Pool, - PoolUpdateRequest, - SecurityContext, -} from "../../../../../../../api/operatorApi"; +import { Pool, PoolUpdateRequest } from "../../../../../../../api/operatorApi"; export const editPoolAsync = createAsyncThunk( "editPool/editPoolAsync", @@ -64,7 +60,7 @@ export const editPoolAsync = createAsyncThunk( switch (affinityType) { case "default": affinityObject = { - affinity: getDefaultAffinity(tenant.name!, poolName), + affinity: getDefaultAffinity(tenant.name!, selectedPool!), }; break; case "nodeSelector": @@ -73,7 +69,7 @@ export const editPoolAsync = createAsyncThunk( nodeSelectorLabels, withPodAntiAffinity, tenant.name!, - poolName, + selectedPool!, ), }; break; @@ -82,28 +78,31 @@ export const editPoolAsync = createAsyncThunk( const tolerationValues = tolerations.filter( (toleration) => toleration.key.trim() !== "", ); - const cleanPools = tenant?.pools ?.filter((pool) => pool.name !== selectedPool) .map((pool) => { - let securityContextOption: SecurityContext | null = null; - - if (pool.securityContext) { + if (securityContextEnabled && pool.securityContext) { if ( - !!pool.securityContext.runAsUser || - !!pool.securityContext.runAsGroup || - !!pool.securityContext.fsGroup + pool.securityContext.runAsUser || + pool.securityContext.runAsGroup || + pool.securityContext.fsGroup ) { - securityContextOption = { ...pool.securityContext }; + return pool; } } - const request = pool; - if (securityContextOption) { - request.securityContext = securityContextOption!; - } - - return request; + return { + name: pool.name, + servers: pool.servers, + volumes_per_server: pool.volumes_per_server, + volume_configuration: pool.volume_configuration, + resources: pool.resources, + node_selector: pool.node_selector, + affinity: pool.affinity, + runtimeClassName: pool.runtimeClassName, + tolerations: pool.tolerations, + securityContext: undefined, + }; }) as Pool[]; let runtimeClass = {};