From 25a965b399703725e16f64f8c0a30e1563b07fa6 Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Tue, 24 May 2022 12:30:45 +0800 Subject: [PATCH] optimize compareImage into one loop (#1130) --- pkg/controller/cluster/main-controller.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/controller/cluster/main-controller.go b/pkg/controller/cluster/main-controller.go index 32c52961465..e5e7e48d7cf 100644 --- a/pkg/controller/cluster/main-controller.go +++ b/pkg/controller/cluster/main-controller.go @@ -938,15 +938,17 @@ func (c *Controller) syncHandler(key string) error { } // compare all the images across all pools, they should always be the same. - for _, image := range images { - for i := 0; i < len(images); i++ { - if image != images[i] { - if _, err = c.updateTenantStatus(ctx, tenant, StatusInconsistentMinIOVersions, totalReplicas); err != nil { - return err - } - return fmt.Errorf("Pool %d is running incorrect image version, all pools are required to be on the same MinIO version. Attempting update of the inconsistent pool", - i+1) + compareImage := "" + for i, image := range images { + if compareImage == "" { + compareImage = image + } + if compareImage != image { + if _, err = c.updateTenantStatus(ctx, tenant, StatusInconsistentMinIOVersions, totalReplicas); err != nil { + return err } + return fmt.Errorf("Pool %d is running incorrect image version, all pools are required to be on the same MinIO version. Attempting update of the inconsistent pool", + i+1) } }