-
Notifications
You must be signed in to change notification settings - Fork 70
/
validation.go
82 lines (74 loc) · 1.88 KB
/
validation.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package interfaces
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"time"
)
var (
DefaultValidationFreqSeconds = intstr.IntOrString{Type: intstr.Int, IntVal: 30}
)
func (v *ValidationSetting) NeedsValidation(lastValid metav1.Time) bool {
if lastValid.IsZero() {
return true
}
secs := v.FrequencySeconds.IntValue()
if secs == 0 {
secs = DefaultValidationFreqSeconds.IntValue()
}
n := lastValid.Time.Add(time.Duration(secs) * time.Second)
return time.Now().After(n)
}
func (v *ValidationSetting) IsFatal() bool {
if v.FailOnError == nil {
return true
}
return *v.FailOnError
}
// UpdateHashIfNotExist updates the hash at key `key` and returns the prior copy if one existed
// LastDeployed should then contain the hash and the time if updateTime is true or if there was no hash
func (s *SpinnakerServiceStatus) UpdateHashIfNotExist(key, hash string, t time.Time) *HashStatus {
if s.LastDeployed == nil {
s.LastDeployed = make(map[string]HashStatus)
}
res := &HashStatus{}
ld, ok := s.LastDeployed[key]
if ok {
ld.DeepCopyInto(res)
ld.Hash = hash
ld.LastUpdatedAt = metav1.NewTime(t)
} else {
ld = HashStatus{
Hash: hash,
LastUpdatedAt: metav1.NewTime(t),
}
}
s.LastDeployed[key] = ld
return res
}
func (s *SpinnakerServiceStatus) GetHash(key string) *HashStatus {
if s.LastDeployed == nil {
return nil
}
hs, ok := s.LastDeployed[key]
if ok {
return &hs
}
return nil
}
func (s *SpinnakerValidation) GetValidationSettings() *ValidationSetting {
f := s.FrequencySeconds
if f.IntValue() == 0 {
f = DefaultValidationFreqSeconds
}
return &ValidationSetting{
Enabled: true,
FailOnError: s.FailOnError,
FrequencySeconds: f,
}
}
func (s *SpinnakerValidation) IsProviderValidationEnabled(key string) bool {
if provider, ok := s.Providers[key]; ok {
return provider.Enabled
}
return true
}