@@ -25,15 +25,12 @@ import (
25
25
"fmt"
26
26
"time"
27
27
28
+ fdbv1beta2 "github.com/FoundationDB/fdb-kubernetes-operator/v2/api/v1beta2"
28
29
"github.com/FoundationDB/fdb-kubernetes-operator/v2/pkg/fdbstatus"
29
-
30
30
"github.com/go-logr/logr"
31
-
32
- "k8s.io/utils/pointer"
33
-
34
- fdbv1beta2 "github.com/FoundationDB/fdb-kubernetes-operator/v2/api/v1beta2"
35
31
corev1 "k8s.io/api/core/v1"
36
32
"k8s.io/apimachinery/pkg/api/equality"
33
+ "k8s.io/utils/pointer"
37
34
)
38
35
39
36
// updateDatabaseConfiguration provides a reconciliation step for changing the
@@ -62,42 +59,38 @@ func (u updateDatabaseConfiguration) reconcile(_ context.Context, r *FoundationD
62
59
}
63
60
}
64
61
65
- initialConfig := ! cluster .Status .Configured
66
- if ! initialConfig && ! status .Client .DatabaseStatus .Available {
67
- logger .Info ("Skipping database configuration change because database is unavailable" )
68
- return & requeue {message : "cluster is not available" , delayedRequeue : true , delay : 5 * time .Second }
69
- }
70
-
62
+ clusterIsConfigured := fdbstatus .ClusterIsConfigured (cluster , status )
71
63
desiredConfiguration := cluster .DesiredDatabaseConfiguration ()
72
- desiredConfiguration .RoleCounts .Storage = 0
73
64
currentConfiguration := status .Cluster .DatabaseConfiguration .NormalizeConfiguration (cluster )
74
65
75
- runningVersion , err := fdbv1beta2 .ParseFdbVersion (cluster .GetRunningVersion ())
76
- if err != nil {
77
- return & requeue {curError : err , delayedRequeue : true }
78
- }
79
-
80
- if initialConfig || ! equality .Semantic .DeepEqual (desiredConfiguration , currentConfiguration ) {
66
+ if ! clusterIsConfigured || ! equality .Semantic .DeepEqual (desiredConfiguration , currentConfiguration ) {
81
67
var nextConfiguration fdbv1beta2.DatabaseConfiguration
82
- if initialConfig {
83
- nextConfiguration = desiredConfiguration
84
- } else {
68
+ if clusterIsConfigured {
85
69
nextConfiguration = currentConfiguration .GetNextConfigurationChange (desiredConfiguration )
70
+ } else {
71
+ nextConfiguration = desiredConfiguration
72
+ }
73
+ configurationString , configErr := nextConfiguration .GetConfigurationString ()
74
+ if configErr != nil {
75
+ return & requeue {curError : err , delayedRequeue : true }
86
76
}
87
- configurationString , _ := nextConfiguration .GetConfigurationString ()
88
77
89
- if ! initialConfig {
78
+ // If the cluster is configured run additional safety checks before performing the database configuration change.
79
+ if clusterIsConfigured {
80
+ runningVersion , err := fdbv1beta2 .ParseFdbVersion (cluster .GetRunningVersion ())
81
+ if err != nil {
82
+ return & requeue {curError : err , delayedRequeue : true }
83
+ }
84
+
90
85
err = fdbstatus .ConfigurationChangeAllowed (status , runningVersion .SupportsRecoveryState () && r .EnableRecoveryState )
91
86
if err != nil {
92
87
logger .Info ("Changing current configuration is not safe" , "error" , err , "current configuration" , currentConfiguration , "desired configuration" , desiredConfiguration )
93
88
r .Recorder .Event (cluster , corev1 .EventTypeNormal , "NeedsConfigurationChange" ,
94
- fmt .Sprintf ("Spec require configuration change to `%s`, but configuration change is not safe: %s" , configurationString , err .Error ()))
95
- return & requeue {message : "Configuration change is not safe, retry later" , delayedRequeue : true , delay : 10 * time .Second }
89
+ fmt .Sprintf ("Spec requires configuration change to `%s`, but configuration change is not safe: %s" , configurationString , err .Error ()))
90
+ return & requeue {message : fmt . Sprintf ( "Configuration change is not safe: %s, will retry" , err . Error ()) , delayedRequeue : true , delay : 10 * time .Second }
96
91
}
97
- }
98
92
99
- if ! initialConfig {
100
- err := r .takeLock (logger , cluster ,
93
+ err = r .takeLock (logger , cluster ,
101
94
fmt .Sprintf ("reconfiguring the database to `%s`" , configurationString ))
102
95
if err != nil {
103
96
return & requeue {curError : err , delayedRequeue : true }
@@ -108,18 +101,14 @@ func (u updateDatabaseConfiguration) reconcile(_ context.Context, r *FoundationD
108
101
r .Recorder .Event (cluster , corev1 .EventTypeNormal , "ConfiguringDatabase" ,
109
102
fmt .Sprintf ("Setting database configuration to `%s`" , configurationString ),
110
103
)
111
- err = adminClient .ConfigureDatabase (nextConfiguration , initialConfig )
104
+ err = adminClient .ConfigureDatabase (nextConfiguration , ! clusterIsConfigured )
112
105
if err != nil {
113
106
return & requeue {curError : err , delayedRequeue : true }
114
107
}
115
108
116
- if initialConfig {
117
- return & requeue {message : "Requeuing for fetching the initial configuration from FDB cluster" , delay : 1 * time .Second }
118
- }
119
-
120
- logger .Info ("Configured database" , "initialConfig" , initialConfig )
109
+ logger .Info ("Configured database" , "clusterIsConfigured" , clusterIsConfigured )
121
110
if ! equality .Semantic .DeepEqual (nextConfiguration , desiredConfiguration ) {
122
- return & requeue {message : "Requeuing for next stage of database configuration change" , delayedRequeue : true }
111
+ return & requeue {message : "Requeuing for next stage of database configuration change" , delay : 30 * time . Second , delayedRequeue : true }
123
112
}
124
113
}
125
114
0 commit comments