-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfig.go
47 lines (37 loc) · 875 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package limits
import (
"reflect"
"github.com/jasonrichardsmith/sentry/config"
"github.com/jasonrichardsmith/sentry/sentry"
"k8s.io/apimachinery/pkg/api/resource"
)
const (
NAME = "limits"
)
func init() {
config.Decoder(NAME, QtyHookFunc)
config.Register(&Config{})
}
type Config struct {
CPU MinMax `mapstructure:"cpu"`
Memory MinMax `mapstructure:"memory"`
}
type MinMax struct {
Min resource.Quantity `mapstructure:"min"`
Max resource.Quantity `mapstructure:"max"`
}
func (c *Config) Name() string {
return NAME
}
func (c *Config) LoadSentry() sentry.Sentry {
return LimitSentry{c}
}
func QtyHookFunc(f reflect.Type, t reflect.Type, data interface{}) (interface{}, error) {
if f.Kind() != reflect.String {
return data, nil
}
if t != reflect.TypeOf(resource.Quantity{}) {
return data, nil
}
return resource.ParseQuantity(data.(string))
}