Skip to content

Commit af2aae4

Browse files
authored
Run the addPods reconciler before connecting to FDB in case we use DNS entries in the cluster file (#2283)
* Run the addPods reconciler before connecting to FDB in case we use DNS entries in the cluster file
1 parent 5c86e60 commit af2aae4

File tree

4 files changed

+55
-45
lines changed

4 files changed

+55
-45
lines changed

controllers/add_pods.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (a addPods) reconcile(ctx context.Context, r *FoundationDBClusterReconciler
114114
return &requeue{curError: err, delayedRequeue: true}
115115
}
116116

117-
return &requeue{curError: err}
117+
return &requeue{curError: err, delayedRequeue: true}
118118
}
119119
}
120120

controllers/cluster_controller.go

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,39 @@ import (
5757
"sigs.k8s.io/controller-runtime/pkg/client"
5858
)
5959

60+
// addPodsReconciler is the reconciler for addPods.
61+
var addPodsReconciler = addPods{}
62+
63+
// subReconcilers has the ordered list of all reconcilers that should be used by the cluster controller.
64+
var subReconcilers = []clusterSubReconciler{
65+
updateStatus{},
66+
updateLockConfiguration{},
67+
updateConfigMap{},
68+
checkClientCompatibility{},
69+
deletePodsForBuggification{},
70+
replaceMisconfiguredProcessGroups{},
71+
replaceFailedProcessGroups{},
72+
addProcessGroups{},
73+
addServices{},
74+
addPVCs{},
75+
addPodsReconciler,
76+
generateInitialClusterFile{},
77+
removeIncompatibleProcesses{},
78+
updateSidecarVersions{},
79+
updatePodConfig{},
80+
updateMetadata{},
81+
updateDatabaseConfiguration{},
82+
chooseRemovals{},
83+
excludeProcesses{},
84+
changeCoordinators{},
85+
bounceProcesses{},
86+
maintenanceModeChecker{},
87+
updatePods{},
88+
removeProcessGroups{},
89+
removeServices{},
90+
updateStatus{},
91+
}
92+
6093
// FoundationDBClusterReconciler reconciles a FoundationDBCluster object
6194
type FoundationDBClusterReconciler struct {
6295
client.Client
@@ -148,20 +181,19 @@ func (r *FoundationDBClusterReconciler) Reconcile(ctx context.Context, request c
148181
return ctrl.Result{}, err
149182
}
150183

184+
err = cluster.Validate()
185+
if err != nil {
186+
r.Recorder.Event(cluster, corev1.EventTypeWarning, "ClusterSpec not valid", err.Error())
187+
return ctrl.Result{}, fmt.Errorf("ClusterSpec is not valid: %w", err)
188+
}
189+
151190
adminClient, err := r.getAdminClient(clusterLog, cluster)
152191
if err != nil {
153192
return ctrl.Result{}, err
154193
}
155194
defer func() {
156195
_ = adminClient.Close()
157196
}()
158-
159-
err = cluster.Validate()
160-
if err != nil {
161-
r.Recorder.Event(cluster, corev1.EventTypeWarning, "ClusterSpec not valid", err.Error())
162-
return ctrl.Result{}, fmt.Errorf("ClusterSpec is not valid: %w", err)
163-
}
164-
165197
supportedVersion, err := adminClient.VersionSupported(cluster.Spec.Version)
166198
if err != nil {
167199
return ctrl.Result{}, err
@@ -170,6 +202,17 @@ func (r *FoundationDBClusterReconciler) Reconcile(ctx context.Context, request c
170202
return ctrl.Result{}, fmt.Errorf("version %s is not supported", cluster.Spec.Version)
171203
}
172204

205+
// When using DNS entries in the cluster file, we want to make sure to create pods if required before doing any
206+
// interaction with the FDB cluster. If none of the coordinator pods is running, this will cause a crash in the FDB
207+
// go bindings (or rather the C client). To prevent those case we run the addPods reconciler before interacting with
208+
// the FoundationDB cluster.
209+
if cluster.UseDNSInClusterFile() {
210+
req := runClusterSubReconciler(ctx, clusterLog, addPodsReconciler, r, cluster, nil)
211+
if req != nil && !req.delayedRequeue {
212+
return processRequeue(req, addPodsReconciler, cluster, r.Recorder, clusterLog)
213+
}
214+
}
215+
173216
var status *fdbv1beta2.FoundationDBStatus
174217
if cacheStatus {
175218
clusterLog.Info("Fetch machine-readable status for reconcilitation loop", "cacheStatus", cacheStatus)
@@ -179,35 +222,6 @@ func (r *FoundationDBClusterReconciler) Reconcile(ctx context.Context, request c
179222
}
180223
}
181224

182-
subReconcilers := []clusterSubReconciler{
183-
updateStatus{},
184-
updateLockConfiguration{},
185-
updateConfigMap{},
186-
checkClientCompatibility{},
187-
deletePodsForBuggification{},
188-
replaceMisconfiguredProcessGroups{},
189-
replaceFailedProcessGroups{},
190-
addProcessGroups{},
191-
addServices{},
192-
addPVCs{},
193-
addPods{},
194-
generateInitialClusterFile{},
195-
removeIncompatibleProcesses{},
196-
updateSidecarVersions{},
197-
updatePodConfig{},
198-
updateMetadata{},
199-
updateDatabaseConfiguration{},
200-
chooseRemovals{},
201-
excludeProcesses{},
202-
changeCoordinators{},
203-
bounceProcesses{},
204-
maintenanceModeChecker{},
205-
updatePods{},
206-
removeProcessGroups{},
207-
removeServices{},
208-
updateStatus{},
209-
}
210-
211225
originalGeneration := cluster.ObjectMeta.Generation
212226
normalizedSpec := cluster.Spec.DeepCopy()
213227
var delayedRequeueDuration time.Duration

controllers/update_status.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ func (c updateStatus) reconcile(ctx context.Context, r *FoundationDBClusterRecon
166166

167167
if clusterStatus.ConnectionString == "" {
168168
connectionString, ok := existingConfigMap.Data[fdbv1beta2.ClusterFileKey]
169-
if ok {
169+
// Only update the connection string if the connection string value is not empty.
170+
if ok && connectionString != "" {
170171
clusterStatus.ConnectionString = connectionString
171172
} else {
172173
clusterStatus.ConnectionString = cluster.Spec.SeedConnectionString

e2e/test_operator/operator_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,13 +2076,8 @@ var _ = Describe("Operator", Label("e2e", "pr"), func() {
20762076
// Make sure the operator is not taking any action to prevent any race condition.
20772077
fdbCluster.SetSkipReconciliation(true)
20782078

2079-
// Delete all Pods
2080-
pods := fdbCluster.GetPods()
2081-
initialPodsCnt = len(pods.Items)
2082-
for _, pod := range pods.Items {
2083-
podToDelete := &pod
2084-
factory.Delete(podToDelete)
2085-
}
2079+
// Delete all Pods, including the operator pods.
2080+
Expect(factory.GetControllerRuntimeClient().DeleteAllOf(context.Background(), &corev1.Pod{}, ctrlClient.InNamespace(fdbCluster.Namespace()))).To(Succeed())
20862081

20872082
// Make sure the Pods are all deleted.
20882083
Eventually(func() []corev1.Pod {

0 commit comments

Comments
 (0)