Skip to content

Commit 430629e

Browse files
committed
Improve parallelism in pod deletion.
1 parent 73a95d6 commit 430629e

File tree

3 files changed

+62
-92
lines changed

3 files changed

+62
-92
lines changed

controllers/cluster_controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ func (r *FoundationDBClusterReconciler) Reconcile(request ctrl.Request) (ctrl.Re
134134
UpdatePods{},
135135
RemoveServices{},
136136
RemovePods{},
137-
IncludeInstances{},
138137
UpdateStatus{},
139138
}
140139

controllers/include_instances.go

Lines changed: 0 additions & 89 deletions
This file was deleted.

controllers/remove_pods.go

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,30 @@ func (u RemovePods) Reconcile(r *FoundationDBClusterReconciler, context ctx.Cont
5252
}
5353

5454
r.Recorder.Event(cluster, "Normal", "RemovingProcesses", fmt.Sprintf("Removing pods: %v", processGroupsToRemove))
55+
allRemoved := true
5556
for _, id := range processGroupsToRemove {
57+
5658
err := removePod(r, context, cluster, id)
5759
if err != nil {
5860
return false, err
5961
}
6062

6163
removed, err := confirmPodRemoval(r, context, cluster, id)
64+
if err != nil {
65+
return false, err
66+
}
6267
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
6475
}
6576
}
6677

67-
return true, nil
78+
return allRemoved, nil
6879
}
6980

7081
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
168179
return true, nil
169180
}
170181

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+
171231
// RequeueAfter returns the delay before we should run the reconciliation
172232
// again.
173233
func (u RemovePods) RequeueAfter() time.Duration {

0 commit comments

Comments
 (0)