From ba62beba82784d8902cbfd2d5b4dfc77b7f2ef72 Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Fri, 30 Jun 2023 16:14:25 +0800 Subject: [PATCH] duplicate status.pools (#1634) * remove useless status first --------- Co-authored-by: guozhi.li Co-authored-by: Pedro Juarez --- pkg/controller/decomission.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkg/controller/decomission.go b/pkg/controller/decomission.go index c883c9289ec..bbcde372e77 100644 --- a/pkg/controller/decomission.go +++ b/pkg/controller/decomission.go @@ -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