Skip to content

Commit

Permalink
Defensive Validation to avoid NPE (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvaldivia authored Jul 20, 2020
1 parent c3a5a98 commit e651e28
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/apis/operator.min.io/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,18 @@ func (mi *MinIOInstance) CreateMCSUser(minioSecret, mcsSecret map[string][]byte)

// Validate returns an error if any configuration of the MinIO instance is invalid
func (mi *MinIOInstance) Validate() error {
// Mandate a VolumeClaimTemplate
if mi.Spec.VolumeClaimTemplate == nil {
return errors.New("volume claim must be specified")
}
// Mandate a resource request
if mi.Spec.VolumeClaimTemplate.Spec.Resources.Requests == nil {
return errors.New("volume claim must specify resource request")
}
// Mandate a request of storage
if mi.Spec.VolumeClaimTemplate.Spec.Resources.Requests.Storage() == nil {
return errors.New("volume claim must specify resource storage request")
}
// 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")
Expand Down

0 comments on commit e651e28

Please sign in to comment.