Skip to content

Commit

Permalink
Add validations to the sync process (#142)
Browse files Browse the repository at this point in the history
* Add validations to the sync process

* Address commnets
  • Loading branch information
dvaldivia committed Jun 9, 2020
1 parent badb55b commit b7ca5dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/apis/operator.min.io/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions pkg/controller/cluster/main-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit b7ca5dc

Please sign in to comment.