Skip to content

Commit

Permalink
Fix NPE on upgrades for v4.5 (#1296)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
  • Loading branch information
dvaldivia authored Sep 21, 2022
1 parent 96b2bbf commit 53b41fc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/minio/operator

go 1.17
go 1.18

require (
github.com/blang/semver/v4 v4.0.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
18 changes: 9 additions & 9 deletions pkg/controller/cluster/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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
}
}

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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)
}

0 comments on commit 53b41fc

Please sign in to comment.