@@ -65,6 +65,7 @@ func newClusterScalingIntegration(depl *Deployment) *clusterScalingIntegration {
65
65
66
66
// SendUpdateToCluster records the given spec to be sended to the cluster.
67
67
func (ci * clusterScalingIntegration ) SendUpdateToCluster (spec api.DeploymentSpec ) {
68
+ ci .log .Debug ().Msg ("SendUpdateToCluster called" )
68
69
ci .pendingUpdate .mutex .Lock ()
69
70
defer ci .pendingUpdate .mutex .Unlock ()
70
71
ci .pendingUpdate .spec = & spec
@@ -75,6 +76,7 @@ func (ci *clusterScalingIntegration) ListenForClusterEvents(stopCh <-chan struct
75
76
start := time .Now ()
76
77
goodInspections := 0
77
78
for {
79
+ ci .log .Debug ().Msg ("inspection loop for cluster int." )
78
80
delay := time .Second * 2
79
81
80
82
// Is deployment in running state
@@ -97,6 +99,8 @@ func (ci *clusterScalingIntegration) ListenForClusterEvents(stopCh <-chan struct
97
99
goodInspections ++
98
100
}
99
101
}
102
+ } else {
103
+ ci .log .Debug ().Msg ("cluster Phase not Running" )
100
104
}
101
105
102
106
select {
@@ -112,6 +116,7 @@ func (ci *clusterScalingIntegration) ListenForClusterEvents(stopCh <-chan struct
112
116
// Perform a single inspection of the cluster
113
117
func (ci * clusterScalingIntegration ) inspectCluster (ctx context.Context , expectSuccess bool ) error {
114
118
log := ci .log
119
+ log .Debug ().Msg ("inspect cluster for scaling integration" )
115
120
c , err := ci .depl .clientCache .GetDatabase (ctx )
116
121
if err != nil {
117
122
return maskAny (err )
@@ -124,6 +129,7 @@ func (ci *clusterScalingIntegration) inspectCluster(ctx context.Context, expectS
124
129
return maskAny (err )
125
130
}
126
131
if req .Coordinators == nil && req .DBServers == nil {
132
+ log .Debug ().Msg ("Nothing to check" )
127
133
// Nothing to check
128
134
return nil
129
135
}
@@ -132,15 +138,32 @@ func (ci *clusterScalingIntegration) inspectCluster(ctx context.Context, expectS
132
138
ci .lastNumberOfServers .mutex .Lock ()
133
139
defer ci .lastNumberOfServers .mutex .Unlock ()
134
140
desired := ci .lastNumberOfServers .NumberOfServers
135
- if req .Coordinators != nil && req .GetCoordinators () != desired .GetCoordinators () {
141
+ if req .Coordinators != nil && desired . Coordinators != nil && req .GetCoordinators () != desired .GetCoordinators () {
136
142
// #Coordinator has changed
137
143
coordinatorsChanged = true
138
144
}
139
- if req .DBServers != nil && req .GetDBServers () != desired .GetDBServers () {
145
+ if req .DBServers != nil && desired . DBServers != nil && req .GetDBServers () != desired .GetDBServers () {
140
146
// #DBServers has changed
141
147
dbserversChanged = true
142
148
}
143
149
if ! coordinatorsChanged && ! dbserversChanged {
150
+ // if there is nothing to change, check if we naver have asked the cluster before
151
+ // if so, fill in the values for the first time.
152
+ // This happens, when the operator is redeployed and there has not been any
153
+ // update events yet.
154
+ if desired .Coordinators == nil || desired .DBServers == nil {
155
+ //ci.lastNumberOfServers.mutex.Lock()
156
+ //defer ci.lastNumberOfServers.mutex.Unlock()
157
+ ci .log .Debug ().Msg ("Some of desired is nil" )
158
+ if req .Coordinators != nil {
159
+ ci .lastNumberOfServers .NumberOfServers .Coordinators = req .Coordinators
160
+ }
161
+ if req .DBServers != nil {
162
+ ci .lastNumberOfServers .NumberOfServers .DBServers = req .DBServers
163
+ }
164
+ }
165
+
166
+ ci .log .Debug ().Msg ("Nothing has changed" )
144
167
// Nothing has changed
145
168
return nil
146
169
}
@@ -165,6 +188,7 @@ func (ci *clusterScalingIntegration) inspectCluster(ctx context.Context, expectS
165
188
// Restore original spec in cluster
166
189
ci .SendUpdateToCluster (current .Spec )
167
190
} else {
191
+ log .Debug ().Msg ("UpdatedCRSpec via agency" )
168
192
if err := ci .depl .updateCRSpec (* newSpec ); err != nil {
169
193
log .Warn ().Err (err ).Msg ("Failed to update current deployment" )
170
194
return maskAny (err )
@@ -176,12 +200,14 @@ func (ci *clusterScalingIntegration) inspectCluster(ctx context.Context, expectS
176
200
// updateClusterServerCount updates the intended number of servers of the cluster.
177
201
// Returns true when it is safe to ask the cluster for updates.
178
202
func (ci * clusterScalingIntegration ) updateClusterServerCount (ctx context.Context , expectSuccess bool ) (bool , error ) {
203
+ ci .log .Debug ().Msg ("updateClusterServerCount" )
179
204
// Any update needed?
180
205
ci .pendingUpdate .mutex .Lock ()
181
206
spec := ci .pendingUpdate .spec
182
207
ci .pendingUpdate .mutex .Unlock ()
183
208
if spec == nil {
184
209
// Nothing pending
210
+ ci .log .Debug ().Msg ("Nothing pending" )
185
211
return true , nil
186
212
}
187
213
@@ -198,13 +224,16 @@ func (ci *clusterScalingIntegration) updateClusterServerCount(ctx context.Contex
198
224
ci .lastNumberOfServers .mutex .Unlock ()
199
225
200
226
// This is to prevent unneseccary updates that may override some values written by the WebUI (in the case of a update loop)
201
- if coordinatorCount != lastNumberOfServers .GetCoordinators () && dbserverCount != lastNumberOfServers .GetDBServers () {
227
+ if coordinatorCount != lastNumberOfServers .GetCoordinators () || dbserverCount != lastNumberOfServers .GetDBServers () {
228
+ ci .log .Debug ().Msg ("Set number of servers now" )
202
229
if err := arangod .SetNumberOfServers (ctx , c .Connection (), coordinatorCount , dbserverCount ); err != nil {
203
230
if expectSuccess {
204
231
log .Debug ().Err (err ).Msg ("Failed to set number of servers" )
205
232
}
206
233
return false , maskAny (err )
207
234
}
235
+ } else {
236
+ ci .log .Debug ().Msg ("Nothing has changed" )
208
237
}
209
238
210
239
// Success, now update internal state
0 commit comments