From 53b41fc3fb9fb03850dd2cf3944523aca6ef2b1f Mon Sep 17 00:00:00 2001 From: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> Date: Wed, 21 Sep 2022 10:04:12 -0700 Subject: [PATCH] Fix NPE on upgrades for v4.5 (#1296) Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> --- go.mod | 2 +- go.sum | 1 + pkg/controller/cluster/upgrades.go | 18 +++++++++--------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index d88bfb9325b..96067dd299b 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/minio/operator -go 1.17 +go 1.18 require ( github.com/blang/semver/v4 v4.0.0 diff --git a/go.sum b/go.sum index 2a178f3d8e6..362ea84b1bf 100644 --- a/go.sum +++ b/go.sum @@ -874,6 +874,7 @@ github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+ github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.14.1 h1:jMU0WaQrP0a/YAEq8eJmJKjBoMs+pClEr1vDMlM/Do4= github.com/onsi/ginkgo v1.14.1/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo/v2 v2.1.4 h1:GNapqRSid3zijZ9H77KrgVG4/8KqiyRsxcSxe+7ApXY= github.com/onsi/gomega v0.0.0-20151007035656-2152b45fa28a/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= diff --git a/pkg/controller/cluster/upgrades.go b/pkg/controller/cluster/upgrades.go index 1716ddb7cbe..6bbe5a53c46 100644 --- a/pkg/controller/cluster/upgrades.go +++ b/pkg/controller/cluster/upgrades.go @@ -104,7 +104,7 @@ func (c *Controller) checkForUpgrades(ctx context.Context, tenant *miniov2.Tenan func (c *Controller) upgrade420(ctx context.Context, tenant *miniov2.Tenant) (*miniov2.Tenant, error) { logSearchSecret, err := c.kubeClientSet.CoreV1().Secrets(tenant.Namespace).Get(ctx, tenant.LogSecretName(), metav1.GetOptions{}) if err != nil && !k8serrors.IsNotFound(err) { - return nil, err + return tenant, err } if k8serrors.IsNotFound(err) { @@ -126,7 +126,7 @@ func (c *Controller) upgrade420(ctx context.Context, tenant *miniov2.Tenant) (*m if secretChanged { _, err = c.kubeClientSet.CoreV1().Secrets(tenant.Namespace).Update(ctx, logSearchSecret, metav1.UpdateOptions{}) if err != nil { - return nil, err + return tenant, err } } @@ -278,7 +278,7 @@ func (c *Controller) upgrade429(ctx context.Context, tenant *miniov2.Tenant) (*m func (c *Controller) upgrade430(ctx context.Context, tenant *miniov2.Tenant) (*miniov2.Tenant, error) { logSearchSecret, err := c.kubeClientSet.CoreV1().Secrets(tenant.Namespace).Get(ctx, tenant.LogSecretName(), metav1.GetOptions{}) if err != nil && !k8serrors.IsNotFound(err) { - return nil, err + return tenant, err } if k8serrors.IsNotFound(err) { @@ -294,7 +294,7 @@ func (c *Controller) upgrade430(ctx context.Context, tenant *miniov2.Tenant) (*m if secretChanged { _, err = c.kubeClientSet.CoreV1().Secrets(tenant.Namespace).Update(ctx, logSearchSecret, metav1.UpdateOptions{}) if err != nil { - return nil, err + return tenant, err } } @@ -310,12 +310,12 @@ func (c *Controller) upgrade45(ctx context.Context, tenant *miniov2.Tenant) (*mi return c.updateTenantSyncVersion(ctx, tenant, version45) } if !tenant.HasCredsSecret() { - return nil, fmt.Errorf("'%s/%s' error migrating tenant credsSecret, credsSecret does not exist", tenant.Namespace, tenant.Name) + return tenant, fmt.Errorf("'%s/%s' error migrating tenant credsSecret, credsSecret does not exist", tenant.Namespace, tenant.Name) } // Create new configuration secret based on the existing credsSecret credsSecret, err := c.kubeClientSet.CoreV1().Secrets(tenant.Namespace).Get(ctx, tenant.Spec.CredsSecret.Name, metav1.GetOptions{}) if err != nil && !k8serrors.IsNotFound(err) { - return nil, err + return tenant, err } var accessKey string var secretKey string @@ -326,7 +326,7 @@ func (c *Controller) upgrade45(ctx context.Context, tenant *miniov2.Tenant) (*mi secretKey = string(credsSecret.Data["secretkey"]) } if accessKey == "" || secretKey == "" { - return nil, fmt.Errorf("accessKey/secretKey are empty - '%s/%s' error in migrating tenant credsSecret to newer configuration", tenant.Namespace, tenant.Name) + return tenant, fmt.Errorf("accessKey/secretKey are empty - '%s/%s' error in migrating tenant credsSecret to newer configuration", tenant.Namespace, tenant.Name) } tenantConfiguration := map[string]string{} tenantConfiguration["MINIO_ROOT_USER"] = accessKey @@ -346,7 +346,7 @@ func (c *Controller) upgrade45(ctx context.Context, tenant *miniov2.Tenant) (*mi } _, err = c.kubeClientSet.CoreV1().Secrets(tenant.Namespace).Create(ctx, configurationSecret, metav1.CreateOptions{}) if err != nil { - return nil, err + return tenant, err } // Update tenant fields tenantCopy := tenant.DeepCopy() @@ -357,7 +357,7 @@ func (c *Controller) upgrade45(ctx context.Context, tenant *miniov2.Tenant) (*mi tenantCopy.Spec.CredsSecret = nil _, err = c.minioClientSet.MinioV2().Tenants(tenant.Namespace).Update(ctx, tenantCopy, metav1.UpdateOptions{}) if err != nil { - return nil, fmt.Errorf("error updating tenant '%s/%s', could not update tenant.spec.configuration field: %v", tenant.Namespace, tenant.Name, err) + return tenant, fmt.Errorf("error updating tenant '%s/%s', could not update tenant.spec.configuration field: %v", tenant.Namespace, tenant.Name, err) } return c.updateTenantSyncVersion(ctx, tenant, version45) }