Skip to content

Commit

Permalink
Use nearest zero-based pool name for expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
allanrogerr committed Jan 24, 2024
1 parent ed454ec commit 14cb578
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
26 changes: 23 additions & 3 deletions kubectl-minio/cmd/resources/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,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},
},
},
},
Expand All @@ -107,9 +107,29 @@ func Pool(opts *TenantOptions, volumes int32, q resource.Quantity) miniov2.Pool
return p
}

func contains(s []string, t string) bool {
for _, v := range s {
if v == t {
return true
}
}
return false
}

// 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 !(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
Expand Down
4 changes: 2 additions & 2 deletions kubectl-minio/cmd/tenant-expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 7 additions & 1 deletion web-app/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
};

Expand Down

0 comments on commit 14cb578

Please sign in to comment.