@@ -52,19 +52,30 @@ func (u RemovePods) Reconcile(r *FoundationDBClusterReconciler, context ctx.Cont
52
52
}
53
53
54
54
r .Recorder .Event (cluster , "Normal" , "RemovingProcesses" , fmt .Sprintf ("Removing pods: %v" , processGroupsToRemove ))
55
+ allRemoved := true
55
56
for _ , id := range processGroupsToRemove {
57
+
56
58
err := removePod (r , context , cluster , id )
57
59
if err != nil {
58
60
return false , err
59
61
}
60
62
61
63
removed , err := confirmPodRemoval (r , context , cluster , id )
64
+ if err != nil {
65
+ return false , err
66
+ }
62
67
if ! removed {
63
- return removed , err
68
+ allRemoved = false
69
+ continue
70
+ }
71
+
72
+ err = includeInstance (r , context , cluster , id )
73
+ if err != nil {
74
+ return false , err
64
75
}
65
76
}
66
77
67
- return true , nil
78
+ return allRemoved , nil
68
79
}
69
80
70
81
func removePod (r * FoundationDBClusterReconciler , context ctx.Context , cluster * fdbtypes.FoundationDBCluster , instanceID string ) error {
@@ -168,6 +179,55 @@ func confirmPodRemoval(r *FoundationDBClusterReconciler, context ctx.Context, cl
168
179
return true , nil
169
180
}
170
181
182
+ func includeInstance (r * FoundationDBClusterReconciler , context ctx.Context , cluster * fdbtypes.FoundationDBCluster , instanceID string ) error {
183
+ adminClient , err := r .AdminClientProvider (cluster , r )
184
+ if err != nil {
185
+ return err
186
+ }
187
+ defer adminClient .Close ()
188
+
189
+ addresses := make ([]string , 0 )
190
+
191
+ hasStatusUpdate := false
192
+
193
+ processGroups := make ([]* fdbtypes.ProcessGroupStatus , 0 , len (cluster .Status .ProcessGroups ))
194
+ for _ , processGroup := range cluster .Status .ProcessGroups {
195
+ if processGroup .Remove {
196
+ addresses = append (addresses , processGroup .Addresses ... )
197
+ hasStatusUpdate = true
198
+ } else {
199
+ processGroups = append (processGroups , processGroup )
200
+ }
201
+ }
202
+
203
+ if len (addresses ) > 0 {
204
+ r .Recorder .Event (cluster , "Normal" , "IncludingInstances" , fmt .Sprintf ("Including removed processes: %v" , addresses ))
205
+ }
206
+
207
+ err = adminClient .IncludeInstances (addresses )
208
+ if err != nil {
209
+ return err
210
+ }
211
+
212
+ needsSpecUpdate := cluster .Spec .PendingRemovals != nil
213
+ if needsSpecUpdate {
214
+ err := r .clearPendingRemovalsFromSpec (context , cluster )
215
+ if err != nil {
216
+ return err
217
+ }
218
+ }
219
+
220
+ if hasStatusUpdate {
221
+ cluster .Status .ProcessGroups = processGroups
222
+ err := r .Status ().Update (context , cluster )
223
+ if err != nil {
224
+ return err
225
+ }
226
+ }
227
+
228
+ return nil
229
+ }
230
+
171
231
// RequeueAfter returns the delay before we should run the reconciliation
172
232
// again.
173
233
func (u RemovePods ) RequeueAfter () time.Duration {
0 commit comments