Skip to content

Commit

Permalink
duplicate status.pools (#1634)
Browse files Browse the repository at this point in the history
* remove useless status first

---------

Co-authored-by: guozhi.li <guozhi.li@daocloud.io>
Co-authored-by: Pedro Juarez <pjuarezd@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 30, 2023
1 parent 8876ba6 commit ba62beb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/controller/decomission.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ import (
// checkForPoolDecommission validates the spec of the tenant and it's status to detect a pool being removed
func (c *Controller) checkForPoolDecommission(ctx context.Context, key string, tenant *miniov2.Tenant, tenantConfiguration map[string][]byte) (*miniov2.Tenant, error) {
var err error
// duplicate status.pools first
haveDuplicateStatusPools := false
distinctStatusPoolsMap := map[string]struct{}{}
distinctStatusPools := []miniov2.PoolStatus{}
for _, pool := range tenant.Status.Pools {
if _, ok := distinctStatusPoolsMap[pool.SSName]; !ok {
distinctStatusPoolsMap[pool.SSName] = struct{}{}
distinctStatusPools = append(distinctStatusPools, *pool.DeepCopy())
} else {
haveDuplicateStatusPools = true
}
}
tenant.Status.Pools = distinctStatusPools
if haveDuplicateStatusPools {
if tenant, err = c.updateTenantStatus(ctx, tenant, StatusNotOwned, 0); err != nil {
return nil, err
}
}

// if the number of pools in the spec is less that what we know in the status, a decomission is taking place
if len(tenant.Status.Pools) > len(tenant.Spec.Pools) {
// check for empty pool names
Expand Down

0 comments on commit ba62beb

Please sign in to comment.