@@ -17,27 +17,42 @@ limitations under the License.
17
17
package controller
18
18
19
19
import (
20
+ "fmt"
20
21
"time"
21
22
22
23
"github.com/csi-addons/kubernetes-csi-addons/api/replication.storage/v1alpha1"
23
24
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24
25
)
25
26
27
+ func getSource (dataSource string ) v1alpha1.Source {
28
+ if dataSource == pvcDataSource {
29
+ return v1alpha1 .Volume
30
+ } else if dataSource == volumeGroupReplicationDataSource {
31
+ return v1alpha1 .VolumeGroup
32
+ } else {
33
+ return ""
34
+ }
35
+ }
36
+
26
37
// sets conditions when volume was promoted successfully.
27
- func setPromotedCondition (conditions * []metav1.Condition , observedGeneration int64 ) {
38
+ func setPromotedCondition (conditions * []metav1.Condition , observedGeneration int64 , dataSource string ) {
39
+ source := getSource (dataSource )
28
40
setStatusCondition (conditions , & metav1.Condition {
41
+ Message : fmt .Sprintf ("%s %s" , source , v1alpha1 .MessagePromoted ),
29
42
Type : v1alpha1 .ConditionCompleted ,
30
43
Reason : v1alpha1 .Promoted ,
31
44
ObservedGeneration : observedGeneration ,
32
45
Status : metav1 .ConditionTrue ,
33
46
})
34
47
setStatusCondition (conditions , & metav1.Condition {
48
+ Message : fmt .Sprintf ("%s %s" , source , v1alpha1 .MessageHealthy ),
35
49
Type : v1alpha1 .ConditionDegraded ,
36
50
Reason : v1alpha1 .Healthy ,
37
51
ObservedGeneration : observedGeneration ,
38
52
Status : metav1 .ConditionFalse ,
39
53
})
40
54
setStatusCondition (conditions , & metav1.Condition {
55
+ Message : fmt .Sprintf ("%s %s" , source , v1alpha1 .MessageNotResyncing ),
41
56
Type : v1alpha1 .ConditionResyncing ,
42
57
Reason : v1alpha1 .NotResyncing ,
43
58
ObservedGeneration : observedGeneration ,
@@ -46,26 +61,31 @@ func setPromotedCondition(conditions *[]metav1.Condition, observedGeneration int
46
61
}
47
62
48
63
// sets conditions when volume promotion was failed.
49
- func setFailedPromotionCondition (conditions * []metav1.Condition , observedGeneration int64 ) {
64
+ func setFailedPromotionCondition (conditions * []metav1.Condition , observedGeneration int64 , dataSource , completedMessage , degradedDetailedMessage string ) {
65
+ source := getSource (dataSource )
50
66
setStatusCondition (conditions , & metav1.Condition {
67
+ Message : completedMessage ,
51
68
Type : v1alpha1 .ConditionCompleted ,
52
69
Reason : v1alpha1 .FailedToPromote ,
53
70
ObservedGeneration : observedGeneration ,
54
71
Status : metav1 .ConditionFalse ,
55
72
})
56
73
setStatusCondition (conditions , & metav1.Condition {
74
+ Message : fmt .Sprintf ("%s %s: %s" , source , v1alpha1 .MessageFailedPromoted , degradedDetailedMessage ),
57
75
Type : v1alpha1 .ConditionDegraded ,
58
76
Reason : v1alpha1 .Error ,
59
77
ObservedGeneration : observedGeneration ,
60
78
Status : metav1 .ConditionTrue ,
61
79
})
62
80
setStatusCondition (conditions , & metav1.Condition {
81
+ Message : fmt .Sprintf ("%s %s" , source , v1alpha1 .MessageNotResyncing ),
63
82
Type : v1alpha1 .ConditionResyncing ,
64
83
Reason : v1alpha1 .NotResyncing ,
65
84
ObservedGeneration : observedGeneration ,
66
85
Status : metav1 .ConditionFalse ,
67
86
})
68
87
setStatusCondition (conditions , & metav1.Condition {
88
+ Message : fmt .Sprintf ("%s %s" , source , v1alpha1 .MessageValidated ),
69
89
Type : v1alpha1 .ConditionValidated ,
70
90
Reason : v1alpha1 .PrerequisiteMet ,
71
91
ObservedGeneration : observedGeneration ,
@@ -74,26 +94,31 @@ func setFailedPromotionCondition(conditions *[]metav1.Condition, observedGenerat
74
94
}
75
95
76
96
// sets conditions when volume promotion was failed due to failed validation.
77
- func setFailedValidationCondition (conditions * []metav1.Condition , observedGeneration int64 ) {
97
+ func setFailedValidationCondition (conditions * []metav1.Condition , observedGeneration int64 , dataSource , degradedMessage , validationDetailedMessage string ) {
98
+ source := getSource (dataSource )
78
99
setStatusCondition (conditions , & metav1.Condition {
100
+ Message : fmt .Sprintf ("%s %s" , source , v1alpha1 .MessageFailedPromoted ),
79
101
Type : v1alpha1 .ConditionCompleted ,
80
102
Reason : v1alpha1 .FailedToPromote ,
81
103
ObservedGeneration : observedGeneration ,
82
104
Status : metav1 .ConditionFalse ,
83
105
})
84
106
setStatusCondition (conditions , & metav1.Condition {
107
+ Message : degradedMessage ,
85
108
Type : v1alpha1 .ConditionDegraded ,
86
109
Reason : v1alpha1 .Error ,
87
110
ObservedGeneration : observedGeneration ,
88
111
Status : metav1 .ConditionTrue ,
89
112
})
90
113
setStatusCondition (conditions , & metav1.Condition {
114
+ Message : fmt .Sprintf ("%s %s" , source , v1alpha1 .MessageNotResyncing ),
91
115
Type : v1alpha1 .ConditionResyncing ,
92
116
Reason : v1alpha1 .NotResyncing ,
93
117
ObservedGeneration : observedGeneration ,
94
118
Status : metav1 .ConditionFalse ,
95
119
})
96
120
setStatusCondition (conditions , & metav1.Condition {
121
+ Message : fmt .Sprintf ("%s: %s" , v1alpha1 .MessageFailedPreCondition , validationDetailedMessage ),
97
122
Type : v1alpha1 .ConditionValidated ,
98
123
Reason : v1alpha1 .PrerequisiteNotMet ,
99
124
ObservedGeneration : observedGeneration ,
@@ -102,14 +127,17 @@ func setFailedValidationCondition(conditions *[]metav1.Condition, observedGenera
102
127
}
103
128
104
129
// sets conditions when volume is demoted and ready to use (resync completed).
105
- func setNotDegradedCondition (conditions * []metav1.Condition , observedGeneration int64 ) {
130
+ func setNotDegradedCondition (conditions * []metav1.Condition , observedGeneration int64 , dataSource string ) {
131
+ source := getSource (dataSource )
106
132
setStatusCondition (conditions , & metav1.Condition {
133
+ Message : fmt .Sprintf ("%s %s" , source , v1alpha1 .MessageDemoted ),
107
134
Type : v1alpha1 .ConditionDegraded ,
108
135
Reason : v1alpha1 .Healthy ,
109
136
ObservedGeneration : observedGeneration ,
110
137
Status : metav1 .ConditionFalse ,
111
138
})
112
139
setStatusCondition (conditions , & metav1.Condition {
140
+ Message : fmt .Sprintf ("%s %s" , source , v1alpha1 .MessageNotResyncing ),
113
141
Type : v1alpha1 .ConditionResyncing ,
114
142
Reason : v1alpha1 .NotResyncing ,
115
143
ObservedGeneration : observedGeneration ,
@@ -118,20 +146,24 @@ func setNotDegradedCondition(conditions *[]metav1.Condition, observedGeneration
118
146
}
119
147
120
148
// sets conditions when volume was demoted successfully.
121
- func setDemotedCondition (conditions * []metav1.Condition , observedGeneration int64 ) {
149
+ func setDemotedCondition (conditions * []metav1.Condition , observedGeneration int64 , dataSource string ) {
150
+ source := getSource (dataSource )
122
151
setStatusCondition (conditions , & metav1.Condition {
152
+ Message : fmt .Sprintf ("%s %s" , source , v1alpha1 .MessageDemoted ),
123
153
Type : v1alpha1 .ConditionCompleted ,
124
154
Reason : v1alpha1 .Demoted ,
125
155
ObservedGeneration : observedGeneration ,
126
156
Status : metav1 .ConditionTrue ,
127
157
})
128
158
setStatusCondition (conditions , & metav1.Condition {
159
+ Message : fmt .Sprintf ("%s %s" , source , v1alpha1 .MessageDegraded ),
129
160
Type : v1alpha1 .ConditionDegraded ,
130
161
Reason : v1alpha1 .VolumeDegraded ,
131
162
ObservedGeneration : observedGeneration ,
132
163
Status : metav1 .ConditionTrue ,
133
164
})
134
165
setStatusCondition (conditions , & metav1.Condition {
166
+ Message : fmt .Sprintf ("%s %s" , source , v1alpha1 .MessageNotResyncing ),
135
167
Type : v1alpha1 .ConditionResyncing ,
136
168
Reason : v1alpha1 .NotResyncing ,
137
169
ObservedGeneration : observedGeneration ,
@@ -140,20 +172,24 @@ func setDemotedCondition(conditions *[]metav1.Condition, observedGeneration int6
140
172
}
141
173
142
174
// sets conditions when volume demotion was failed.
143
- func setFailedDemotionCondition (conditions * []metav1.Condition , observedGeneration int64 ) {
175
+ func setFailedDemotionCondition (conditions * []metav1.Condition , observedGeneration int64 , dataSource , completedMessage , degradedDetailedMessage string ) {
176
+ source := getSource (dataSource )
144
177
setStatusCondition (conditions , & metav1.Condition {
178
+ Message : completedMessage ,
145
179
Type : v1alpha1 .ConditionCompleted ,
146
180
Reason : v1alpha1 .FailedToDemote ,
147
181
ObservedGeneration : observedGeneration ,
148
182
Status : metav1 .ConditionFalse ,
149
183
})
150
184
setStatusCondition (conditions , & metav1.Condition {
185
+ Message : fmt .Sprintf ("%s %s: %s" , source , v1alpha1 .MessageFailedDemoted , degradedDetailedMessage ),
151
186
Type : v1alpha1 .ConditionDegraded ,
152
187
Reason : v1alpha1 .Error ,
153
188
ObservedGeneration : observedGeneration ,
154
189
Status : metav1 .ConditionTrue ,
155
190
})
156
191
setStatusCondition (conditions , & metav1.Condition {
192
+ Message : fmt .Sprintf ("%s %s" , source , v1alpha1 .MessageNotResyncing ),
157
193
Type : v1alpha1 .ConditionResyncing ,
158
194
Reason : v1alpha1 .NotResyncing ,
159
195
ObservedGeneration : observedGeneration ,
@@ -162,20 +198,24 @@ func setFailedDemotionCondition(conditions *[]metav1.Condition, observedGenerati
162
198
}
163
199
164
200
// sets conditions when volume resync was triggered successfully.
165
- func setResyncCondition (conditions * []metav1.Condition , observedGeneration int64 ) {
201
+ func setResyncCondition (conditions * []metav1.Condition , observedGeneration int64 , dataSource string ) {
202
+ source := getSource (dataSource )
166
203
setStatusCondition (conditions , & metav1.Condition {
204
+ Message : fmt .Sprintf ("%s %s" , source , v1alpha1 .MessageDemoted ),
167
205
Type : v1alpha1 .ConditionCompleted ,
168
206
Reason : v1alpha1 .Demoted ,
169
207
ObservedGeneration : observedGeneration ,
170
208
Status : metav1 .ConditionTrue ,
171
209
})
172
210
setStatusCondition (conditions , & metav1.Condition {
211
+ Message : fmt .Sprintf ("%s %s" , source , v1alpha1 .MessageDegraded ),
173
212
Type : v1alpha1 .ConditionDegraded ,
174
213
Reason : v1alpha1 .VolumeDegraded ,
175
214
ObservedGeneration : observedGeneration ,
176
215
Status : metav1 .ConditionTrue ,
177
216
})
178
217
setStatusCondition (conditions , & metav1.Condition {
218
+ Message : fmt .Sprintf ("%s %s" , source , v1alpha1 .MessageResyncTriggered ),
179
219
Type : v1alpha1 .ConditionResyncing ,
180
220
Reason : v1alpha1 .ResyncTriggered ,
181
221
ObservedGeneration : observedGeneration ,
@@ -184,20 +224,24 @@ func setResyncCondition(conditions *[]metav1.Condition, observedGeneration int64
184
224
}
185
225
186
226
// sets conditions when volume resync failed.
187
- func setFailedResyncCondition (conditions * []metav1.Condition , observedGeneration int64 ) {
227
+ func setFailedResyncCondition (conditions * []metav1.Condition , observedGeneration int64 , dataSource , completedMessage , degradedDetailedMessage string ) {
228
+ source := getSource (dataSource )
188
229
setStatusCondition (conditions , & metav1.Condition {
230
+ Message : completedMessage ,
189
231
Type : v1alpha1 .ConditionCompleted ,
190
232
Reason : v1alpha1 .FailedToResync ,
191
233
ObservedGeneration : observedGeneration ,
192
234
Status : metav1 .ConditionFalse ,
193
235
})
194
236
setStatusCondition (conditions , & metav1.Condition {
237
+ Message : fmt .Sprintf ("%s %s: %s" , source , v1alpha1 .MessageResyncFailed , degradedDetailedMessage ),
195
238
Type : v1alpha1 .ConditionDegraded ,
196
239
Reason : v1alpha1 .Error ,
197
240
ObservedGeneration : observedGeneration ,
198
241
Status : metav1 .ConditionTrue ,
199
242
})
200
243
setStatusCondition (conditions , & metav1.Condition {
244
+ Message : fmt .Sprintf ("%s %s" , source , v1alpha1 .MessageNotResyncing ),
201
245
Type : v1alpha1 .ConditionResyncing ,
202
246
Reason : v1alpha1 .FailedToResync ,
203
247
ObservedGeneration : observedGeneration ,
@@ -223,6 +267,7 @@ func setStatusCondition(existingConditions *[]metav1.Condition, newCondition *me
223
267
existingCondition .LastTransitionTime = metav1 .NewTime (time .Now ())
224
268
}
225
269
270
+ existingCondition .Message = newCondition .Message
226
271
existingCondition .Reason = newCondition .Reason
227
272
existingCondition .ObservedGeneration = newCondition .ObservedGeneration
228
273
}
0 commit comments