-
Notifications
You must be signed in to change notification settings - Fork 352
/
validate.go
61 lines (47 loc) · 1.38 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package v1
import (
"errors"
"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)
}
initialRedisCustomConfig := defaultRedisCustomConfig
if r.Bootstrapping() {
if r.Spec.BootstrapNode.Host == "" {
return errors.New("BootstrapNode must include a host when provided")
}
if r.Spec.BootstrapNode.Port == "" {
r.Spec.BootstrapNode.Port = defaultRedisPort
}
initialRedisCustomConfig = bootstrappingRedisCustomConfig
}
r.Spec.Redis.CustomConfig = append(initialRedisCustomConfig, r.Spec.Redis.CustomConfig...)
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
}