From 0c77cc5849e58e52822047ee23e949ef5ae48d1a Mon Sep 17 00:00:00 2001 From: Pedro Juarez Date: Wed, 12 Jun 2024 01:54:00 -0700 Subject: [PATCH] bugfix: set pool status based on name rather than index based (#2161) Fixes https://github.com/minio/operator/issues/2160 Signed-off-by: pjuarezd --- pkg/controller/main-controller.go | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/pkg/controller/main-controller.go b/pkg/controller/main-controller.go index 1b036ff79ca..7466d1de14c 100644 --- a/pkg/controller/main-controller.go +++ b/pkg/controller/main-controller.go @@ -960,11 +960,17 @@ func (c *Controller) syncHandler(key string) (Result, error) { // Get the StatefulSet with the name specified in Tenant.status.pools[i].SSName // if this index is in the status of pools use it, else capture the desired name in the status and store it - var ssName string - if len(tenant.Status.Pools) > i { - ssName = tenant.Status.Pools[i].SSName - } else { - ssName = tenant.PoolStatefulsetName(&pool) + ssName := tenant.PoolStatefulsetName(&pool) + + poolInStatus := false + for _, poolStatus := range tenant.Status.Pools { + if poolStatus.SSName == ssName { + poolInStatus = true + break + } + } + + if !poolInStatus { tenant.Status.Pools = append(tenant.Status.Pools, miniov2.PoolStatus{ SSName: ssName, State: miniov2.PoolNotCreated, @@ -1209,10 +1215,17 @@ func (c *Controller) syncHandler(key string) (Result, error) { for i, pool := range tenant.Spec.Pools { // Get the StatefulSet with the name specified in Tenant.status.pools[i].SSName // if this index is in the status of pools use it, else capture the desired name in the status and store it - var ssName string - if len(tenant.Status.Pools) > i { - ssName = tenant.Status.Pools[i].SSName - } else { + ssName := tenant.PoolStatefulsetName(&pool) + + poolInStatus := false + for _, poolStatus := range tenant.Status.Pools { + if poolStatus.SSName == ssName { + poolInStatus = true + break + } + } + + if !poolInStatus { ssName = tenant.PoolStatefulsetName(&pool) tenant.Status.Pools = append(tenant.Status.Pools, miniov2.PoolStatus{ SSName: ssName,