From b7ca5dce0cbf1dda01b491e372b4edc0f913c373 Mon Sep 17 00:00:00 2001 From: Daniel Valdivia Date: Mon, 8 Jun 2020 19:51:50 -0700 Subject: [PATCH] Add validations to the sync process (#142) * Add validations to the sync process * Address commnets --- pkg/apis/operator.min.io/v1/helper.go | 16 ++++++++++++++++ pkg/controller/cluster/main-controller.go | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/pkg/apis/operator.min.io/v1/helper.go b/pkg/apis/operator.min.io/v1/helper.go index c3981531169..6b1a135c3c6 100644 --- a/pkg/apis/operator.min.io/v1/helper.go +++ b/pkg/apis/operator.min.io/v1/helper.go @@ -415,6 +415,22 @@ func (mi *MinIOInstance) CreateMCSUser(minioSecret, mcsSecret map[string][]byte) return nil } +// Validate returns an error if any configuration of the MinIO instance is invalid +func (mi *MinIOInstance) Validate() error { + // Make sure the storage request is not 0 + if mi.Spec.VolumeClaimTemplate.Spec.Resources.Requests.Storage().Value() <= 0 { + return errors.New("volume size must be greater than 0") + } + // Make sure the replicas are not 0 on any zone + for _, z := range mi.Spec.Zones { + if z.Servers == 0 { + return fmt.Errorf("zone '%s' cannot have 0 servers", z.Name) + } + } + + return nil +} + // Set up admin client to use self certificates func setUpInsecureTLS(api *madmin.AdminClient) *madmin.AdminClient { // Keep TLS config. diff --git a/pkg/controller/cluster/main-controller.go b/pkg/controller/cluster/main-controller.go index 7206106589a..12b69fc155d 100644 --- a/pkg/controller/cluster/main-controller.go +++ b/pkg/controller/cluster/main-controller.go @@ -342,6 +342,13 @@ func (c *Controller) syncHandler(key string) error { mi.EnsureDefaults() miniov1.InitGlobals(mi) + // Validate the MinIO Instance + if err = mi.Validate(); err != nil { + mi, err = c.updateMinIOInstanceStatus(ctx, mi, err.Error(), 0) + klog.V(2).Infof(err.Error()) + return err + } + // check if both auto certificate creation and external secret with certificate is passed, // this is an error as only one of this is allowed in one MinIOInstance if mi.RequiresAutoCertSetup() && mi.RequiresExternalCertSetup() {