forked from spotahome/redis-operator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
validate.go
46 lines (35 loc) · 964 Bytes
/
validate.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
package v1
import (
"fmt"
)
const (
maxNameLength = 48
)
// Validate set the values by default if not defined and checks if the values given are valid
func (r *RedisFailover) Validate() error {
if len(r.Name) > maxNameLength {
return fmt.Errorf("name length can't be higher than %d", maxNameLength)
}
if r.Spec.Redis.Image == "" {
r.Spec.Redis.Image = defaultImage
}
if r.Spec.Sentinel.Image == "" {
r.Spec.Sentinel.Image = defaultImage
}
if r.Spec.Redis.Replicas <= 0 {
r.Spec.Redis.Replicas = defaultRedisNumber
}
if r.Spec.Sentinel.Replicas <= 0 {
r.Spec.Sentinel.Replicas = defaultSentinelNumber
}
if r.Spec.Redis.Exporter.Image == "" {
r.Spec.Redis.Exporter.Image = defaultExporterImage
}
if r.Spec.Sentinel.Exporter.Image == "" {
r.Spec.Sentinel.Exporter.Image = defaultSentinelExporterImage
}
if len(r.Spec.Sentinel.CustomConfig) == 0 {
r.Spec.Sentinel.CustomConfig = defaultSentinelCustomConfig
}
return nil
}