This repository has been archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
checks.go
142 lines (117 loc) · 3.33 KB
/
checks.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package release
import (
"fmt"
"sort"
shipper "github.com/bookingcom/shipper/pkg/apis/shipper/v1alpha1"
targetutil "github.com/bookingcom/shipper/pkg/util/target"
)
func checkInstallation(it *shipper.InstallationTarget) (bool, string) {
return targetutil.IsReady(it.Status.Conditions)
}
func checkCapacity(
ct *shipper.CapacityTarget,
stepCapacity int32,
) (
bool,
*shipper.CapacityTargetSpec,
string,
) {
canProceed := true
newSpec := &shipper.CapacityTargetSpec{}
reason := ""
clustersNotReadyMap := make(map[string]struct{})
for _, spec := range ct.Spec.Clusters {
t := spec
if spec.Percent != stepCapacity {
t = shipper.ClusterCapacityTarget{
Name: spec.Name,
Percent: stepCapacity,
TotalReplicaCount: spec.TotalReplicaCount,
}
clustersNotReadyMap[spec.Name] = struct{}{}
canProceed = false
}
newSpec.Clusters = append(newSpec.Clusters, t)
}
if canProceed {
// We return an empty new spec if cluster spec check went fine
// so far.
newSpec = nil
if ct.Status.ObservedGeneration >= ct.Generation {
canProceed, reason = targetutil.IsReady(ct.Status.Conditions)
} else {
canProceed = false
clustersNotReady := make([]string, 0)
for _, spec := range ct.Spec.Clusters {
clustersNotReady = append(clustersNotReady, spec.Name)
}
// We need a sorted order, otherwise it will trigger
// unnecessary etcd update operations
sort.Strings(clustersNotReady)
reason = fmt.Sprintf("%v", clustersNotReady)
}
} else {
clustersNotReady := make([]string, 0)
for c, _ := range clustersNotReadyMap {
clustersNotReady = append(clustersNotReady, c)
}
// We need a sorted order, otherwise it will trigger
// unnecessary etcd update operations
sort.Strings(clustersNotReady)
reason = fmt.Sprintf("%v", clustersNotReady)
}
return canProceed, newSpec, reason
}
func checkTraffic(
tt *shipper.TrafficTarget,
stepTrafficWeight uint32,
) (
bool,
*shipper.TrafficTargetSpec,
string,
) {
canProceed := true
newSpec := &shipper.TrafficTargetSpec{}
reason := ""
clustersNotReadyMap := make(map[string]struct{})
for _, spec := range tt.Spec.Clusters {
t := spec
if spec.Weight != stepTrafficWeight {
t = shipper.ClusterTrafficTarget{
Name: spec.Name,
Weight: stepTrafficWeight,
}
clustersNotReadyMap[spec.Name] = struct{}{}
canProceed = false
}
newSpec.Clusters = append(newSpec.Clusters, t)
}
if canProceed {
// We return an empty new spec if cluster spec check went fine
// so far.
newSpec = nil
if tt.Status.ObservedGeneration >= tt.Generation {
canProceed, reason = targetutil.IsReady(tt.Status.Conditions)
} else {
canProceed = false
clustersNotReady := make([]string, 0)
for _, c := range tt.Spec.Clusters {
clustersNotReady = append(clustersNotReady, c.Name)
}
// We need a sorted order, otherwise it will trigger
// unnecessary etcd update operations
sort.Strings(clustersNotReady)
reason = fmt.Sprintf("%v", clustersNotReady)
}
} else {
clustersNotReady := make([]string, 0)
for c, _ := range clustersNotReadyMap {
clustersNotReady = append(clustersNotReady, c)
}
// We need a sorted order, otherwise it will trigger
// unnecessary etcd update operations
sort.Strings(clustersNotReady)
reason = fmt.Sprintf("%v", clustersNotReady)
}
return canProceed, newSpec, reason
}