github.com/jlmeeker/kismatic@v1.10.1-0.20180612190640-57f9005a1f1a/pkg/inspector/rule/free_space.go (about) 1 package rule 2 3 import ( 4 "errors" 5 "fmt" 6 "strconv" 7 "strings" 8 ) 9 10 // The FreeSpace rule declares that the given path must have enough free space 11 type FreeSpace struct { 12 Meta 13 MinimumBytes string 14 Path string 15 } 16 17 // Name is the name of the rule 18 func (f FreeSpace) Name() string { 19 return fmt.Sprintf("Path %s has at least %s bytes", f.Path, f.MinimumBytes) 20 } 21 22 // IsRemoteRule returns true if the rule is to be run from outside of the node 23 func (f FreeSpace) IsRemoteRule() bool { return false } 24 25 // Validate the rule 26 func (f FreeSpace) Validate() []error { 27 errs := []error{} 28 if f.Path == "" { 29 errs = append(errs, errors.New("Path cannot be empty")) 30 } else if !strings.HasPrefix(f.Path, "/") { 31 errs = append(errs, errors.New("Path must start with /")) 32 } 33 34 if f.MinimumBytes == "" { 35 errs = append(errs, errors.New("MinimumBytes cannot be empty")) 36 } else { 37 if _, err := f.minimumBytesAsUint64(); err != nil { 38 errs = append(errs, fmt.Errorf("MinimumBytes contains an invalid unsigned integer: %v", err)) 39 } 40 } 41 if len(errs) > 0 { 42 return errs 43 } 44 return nil 45 } 46 47 func (f FreeSpace) minimumBytesAsUint64() (uint64, error) { 48 return strconv.ParseUint(f.MinimumBytes, 10, 0) 49 }