Skip to content

Commit

Permalink
Allow single MinIO tenant in a namespace (#181)
Browse files Browse the repository at this point in the history
* Allow single MinIO tenant in a namespace

This PR blocks attempts to create a new MinIO tenant in a namespace
that already has another MinIO tenant.

* Update pkg/controller/cluster/main-controller.go

Co-authored-by: Ritesh H Shukla <kerneltime@gmail.com>

Co-authored-by: Ritesh H Shukla <kerneltime@gmail.com>
Co-authored-by: Daniel Valdivia <hola@danielvaldivia.com>
  • Loading branch information
3 people committed Jul 24, 2020
1 parent 26762d6 commit e5f7fd3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/controller/cluster/main-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -91,6 +92,7 @@ const (
statusUpdatingContainerArguments = "Updating Container Arguments"
statusUpdatingConsoleVersion = "Updating Console Version"
statusNotOwned = "Statefulset not controlled by operator"
statusFailedAlreadyExists = "Failed: Another MinIO Tenant already exists in the namespace"
)

// Controller struct watches the Kubernetes API for changes to Tenant resources
Expand Down Expand Up @@ -436,6 +438,19 @@ func (c *Controller) syncHandler(key string) error {
}
}

// List all MinIO instances in this namespace.
li, err := c.tenantsLister.Tenants(mi.Namespace).List(labels.NewSelector())
if err != nil {
return err
}
// Only 1 minio tenant per namespace allowed.
if len(li) > 1 {
if _, err = c.updateTenantStatus(ctx, mi, statusFailedAlreadyExists, 0); err != nil {
return err
}
return fmt.Errorf("Failed creating MinIO Tenant '%s' because another MinIO Tenant '%s' already exists in the namespace '%s'", mi.Name, li[0].Name, mi.Namespace)
}

// For each zone check it's stateful set
var totalReplicas int32
for _, zone := range mi.Spec.Zones {
Expand Down

0 comments on commit e5f7fd3

Please sign in to comment.