Skip to content

Commit f1d622b

Browse files
committed
Move the update status into a single place
1 parent b1e744e commit f1d622b

16 files changed

+33
-106
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ dist/
4848
# Used for testing locally build FDB library
4949
libfdb_c.so
5050
fdb-kubernetes-operator
51+
*.local.md

controllers/add_process_groups.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type addProcessGroups struct{}
3535

3636
// reconcile runs the reconciler's work.
3737
func (a addProcessGroups) reconcile(
38-
ctx context.Context,
38+
_ context.Context,
3939
r *FoundationDBClusterReconciler,
4040
cluster *fdbv1beta2.FoundationDBCluster,
4141
status *fdbv1beta2.FoundationDBStatus,
@@ -64,7 +64,6 @@ func (a addProcessGroups) reconcile(
6464
logger.Error(err, "Error getting exclusion list")
6565
}
6666

67-
hasNewProcessGroups := false
6867
for _, processClass := range fdbv1beta2.ProcessClasses {
6968
desiredCount := desiredCounts[processClass]
7069
if desiredCount < 0 {
@@ -80,7 +79,6 @@ func (a addProcessGroups) reconcile(
8079
processGroupIDs[processClass] = map[int]bool{}
8180
}
8281

83-
hasNewProcessGroups = true
8482
logger.Info(
8583
"Adding new Process Groups",
8684
"processClass",
@@ -120,13 +118,6 @@ func (a addProcessGroups) reconcile(
120118
}
121119
}
122120

123-
if hasNewProcessGroups {
124-
err = r.updateOrApply(ctx, cluster)
125-
if err != nil {
126-
return &requeue{curError: err}
127-
}
128-
}
129-
130121
if getLocalitiesErr != nil {
131122
return &requeue{curError: getLocalitiesErr, delayedRequeue: true}
132123
}

controllers/add_process_groups_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ var _ = Describe("add_process_groups", func() {
7171
Expect(requeue.curError).NotTo(HaveOccurred())
7272
}
7373

74-
_, err = reloadCluster(cluster)
75-
Expect(err).NotTo(HaveOccurred())
7674
newProcessCounts = fdbv1beta2.CreateProcessCountsFromProcessGroupStatus(
7775
cluster.Status.ProcessGroups,
7876
true,

controllers/change_coordinators.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type changeCoordinators struct{}
3838

3939
// reconcile runs the reconciler's work.
4040
func (c changeCoordinators) reconcile(
41-
ctx context.Context,
41+
_ context.Context,
4242
r *FoundationDBClusterReconciler,
4343
cluster *fdbv1beta2.FoundationDBCluster,
4444
status *fdbv1beta2.FoundationDBStatus,
@@ -115,10 +115,5 @@ func (c changeCoordinators) reconcile(
115115
// Reset the SecondsSinceLastRecovered sine the operator just changed the coordinators, which will cause a recovery.
116116
status.Cluster.RecoveryState.SecondsSinceLastRecovered = 0.0
117117

118-
err = r.updateOrApply(ctx, cluster)
119-
if err != nil {
120-
return &requeue{curError: err, delayedRequeue: true}
121-
}
122-
123118
return nil
124119
}

controllers/choose_removals.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type chooseRemovals struct{}
3838

3939
// reconcile runs the reconciler's work.
4040
func (c chooseRemovals) reconcile(
41-
ctx context.Context,
41+
_ context.Context,
4242
r *FoundationDBClusterReconciler,
4343
cluster *fdbv1beta2.FoundationDBCluster,
4444
status *fdbv1beta2.FoundationDBStatus,
@@ -151,10 +151,6 @@ func (c chooseRemovals) reconcile(
151151
processGroup.MarkForRemoval()
152152
}
153153
}
154-
err := r.updateOrApply(ctx, cluster)
155-
if err != nil {
156-
return &requeue{curError: err, delayedRequeue: true}
157-
}
158154
}
159155

160156
return nil

controllers/choose_removals_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
var _ = Describe("choose_removals", func() {
3636
var cluster *fdbv1beta2.FoundationDBCluster
3737
var adminClient *mock.AdminClient
38-
var err error
3938
var requeue *requeue
4039
var removals []fdbv1beta2.ProcessGroupID
4140

@@ -63,9 +62,6 @@ var _ = Describe("choose_removals", func() {
6362
nil,
6463
globalControllerLogger,
6564
)
66-
Expect(err).NotTo(HaveOccurred())
67-
_, err = reloadCluster(cluster)
68-
Expect(err).NotTo(HaveOccurred())
6965

7066
removals = nil
7167
for _, processGroup := range cluster.Status.ProcessGroups {

controllers/cluster_controller.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
"syscall"
3131
"time"
3232

33+
"k8s.io/apimachinery/pkg/api/equality"
34+
3335
"github.com/FoundationDB/fdb-kubernetes-operator/v2/pkg/fdbadminclient"
3436
"github.com/FoundationDB/fdb-kubernetes-operator/v2/pkg/podmanager"
3537
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -188,9 +190,23 @@ func (r *FoundationDBClusterReconciler) Reconcile(
188190
cacheStatus := cluster.CacheDatabaseStatusForReconciliation(
189191
r.CacheDatabaseStatusForReconciliationDefault,
190192
)
191-
// Printout the duration of the reconciliation, independent if the reconciliation was successful or had an error.
193+
194+
originalStatus := cluster.Status.DeepCopy()
192195
startTime := time.Now()
193196
defer func() {
197+
// If the cluster.Status has changed compared to the original Status, we have to update the status.
198+
// See: https://github.com/kubernetes-sigs/kubebuilder/issues/592
199+
// If we use the default reflect.DeepEqual method it will be recreating the clusterStatus multiple times
200+
// because the pointers are different.
201+
if !equality.Semantic.DeepEqual(cluster.Status, *originalStatus) {
202+
clusterLog.Info("cluster status was changed, will be updating the cluster status")
203+
err = r.updateOrApply(ctx, cluster)
204+
if err != nil {
205+
clusterLog.Error(err, "Error updating cluster clusterStatus")
206+
}
207+
}
208+
209+
// Printout the duration of the reconciliation, independent if the reconciliation was successful or had an error.
194210
clusterLog.Info(
195211
"Reconciliation run finished",
196212
"duration_seconds",

controllers/exclude_processes.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type excludeEntry struct {
4747

4848
// reconcile runs the reconciler's work.
4949
func (e excludeProcesses) reconcile(
50-
ctx context.Context,
50+
_ context.Context,
5151
r *FoundationDBClusterReconciler,
5252
cluster *fdbv1beta2.FoundationDBCluster,
5353
status *fdbv1beta2.FoundationDBStatus,
@@ -336,11 +336,6 @@ func (e excludeProcesses) reconcile(
336336
if coordinatorErr != nil {
337337
return &requeue{curError: coordinatorErr, delayedRequeue: true}
338338
}
339-
340-
err = r.updateOrApply(ctx, cluster)
341-
if err != nil {
342-
return &requeue{curError: err, delayedRequeue: true}
343-
}
344339
}
345340

346341
// If not all processes are excluded, ensure we requeue after 5 minutes.

controllers/exclude_processes_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,8 +1730,6 @@ var _ = Describe("exclude_processes", func() {
17301730
Expect(req).To(BeNil())
17311731
Expect(adminClient.ExcludedAddresses).To(HaveLen(1))
17321732

1733-
_, err = reloadCluster(cluster)
1734-
Expect(err).NotTo(HaveOccurred())
17351733
Expect(initialConnectionString).NotTo(Equal(cluster.Status.ConnectionString))
17361734
})
17371735

@@ -1749,8 +1747,6 @@ var _ = Describe("exclude_processes", func() {
17491747
Expect(req).To(BeNil())
17501748
Expect(adminClient.ExcludedAddresses).To(HaveLen(1))
17511749

1752-
_, err = reloadCluster(cluster)
1753-
Expect(err).NotTo(HaveOccurred())
17541750
Expect(
17551751
initialConnectionString,
17561752
).NotTo(Equal(cluster.Status.ConnectionString))
@@ -1918,9 +1914,6 @@ var _ = Describe("exclude_processes", func() {
19181914

19191915
Expect(req).To(BeNil())
19201916
Expect(adminClient.ExcludedAddresses).To(HaveLen(1))
1921-
1922-
_, err = reloadCluster(cluster)
1923-
Expect(err).NotTo(HaveOccurred())
19241917
Expect(initialConnectionString).NotTo(Equal(cluster.Status.ConnectionString))
19251918
})
19261919

@@ -1937,9 +1930,6 @@ var _ = Describe("exclude_processes", func() {
19371930

19381931
Expect(req).To(BeNil())
19391932
Expect(adminClient.ExcludedAddresses).To(HaveLen(1))
1940-
1941-
_, err = reloadCluster(cluster)
1942-
Expect(err).NotTo(HaveOccurred())
19431933
Expect(
19441934
initialConnectionString,
19451935
).NotTo(Equal(cluster.Status.ConnectionString))

controllers/generate_initial_cluster_file.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,6 @@ func (g generateInitialClusterFile) reconcile(
206206
}
207207

208208
cluster.Status.ConnectionString = connectionString.String()
209-
err = r.updateOrApply(ctx, cluster)
210-
if err != nil {
211-
return &requeue{curError: err}
212-
}
213209

214210
return nil
215211
}

0 commit comments

Comments
 (0)