@@ -65,6 +65,7 @@ func newClusterScalingIntegration(depl *Deployment) *clusterScalingIntegration {
6565
6666// SendUpdateToCluster records the given spec to be sended to the cluster.
6767func (ci * clusterScalingIntegration ) SendUpdateToCluster (spec api.DeploymentSpec ) {
68+ ci .log .Debug ().Msg ("SendUpdateToCluster called" )
6869 ci .pendingUpdate .mutex .Lock ()
6970 defer ci .pendingUpdate .mutex .Unlock ()
7071 ci .pendingUpdate .spec = & spec
@@ -75,6 +76,7 @@ func (ci *clusterScalingIntegration) ListenForClusterEvents(stopCh <-chan struct
7576 start := time .Now ()
7677 goodInspections := 0
7778 for {
79+ ci .log .Debug ().Msg ("inspection loop for cluster int." )
7880 delay := time .Second * 2
7981
8082 // Is deployment in running state
@@ -97,6 +99,8 @@ func (ci *clusterScalingIntegration) ListenForClusterEvents(stopCh <-chan struct
9799 goodInspections ++
98100 }
99101 }
102+ } else {
103+ ci .log .Debug ().Msg ("cluster Phase not Running" )
100104 }
101105
102106 select {
@@ -112,6 +116,7 @@ func (ci *clusterScalingIntegration) ListenForClusterEvents(stopCh <-chan struct
112116// Perform a single inspection of the cluster
113117func (ci * clusterScalingIntegration ) inspectCluster (ctx context.Context , expectSuccess bool ) error {
114118 log := ci .log
119+ log .Debug ().Msg ("inspect cluster for scaling integration" )
115120 c , err := ci .depl .clientCache .GetDatabase (ctx )
116121 if err != nil {
117122 return maskAny (err )
@@ -124,6 +129,7 @@ func (ci *clusterScalingIntegration) inspectCluster(ctx context.Context, expectS
124129 return maskAny (err )
125130 }
126131 if req .Coordinators == nil && req .DBServers == nil {
132+ log .Debug ().Msg ("Nothing to check" )
127133 // Nothing to check
128134 return nil
129135 }
@@ -132,15 +138,32 @@ func (ci *clusterScalingIntegration) inspectCluster(ctx context.Context, expectS
132138 ci .lastNumberOfServers .mutex .Lock ()
133139 defer ci .lastNumberOfServers .mutex .Unlock ()
134140 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 () {
136142 // #Coordinator has changed
137143 coordinatorsChanged = true
138144 }
139- if req .DBServers != nil && req .GetDBServers () != desired .GetDBServers () {
145+ if req .DBServers != nil && desired . DBServers != nil && req .GetDBServers () != desired .GetDBServers () {
140146 // #DBServers has changed
141147 dbserversChanged = true
142148 }
143149 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" )
144167 // Nothing has changed
145168 return nil
146169 }
@@ -165,6 +188,7 @@ func (ci *clusterScalingIntegration) inspectCluster(ctx context.Context, expectS
165188 // Restore original spec in cluster
166189 ci .SendUpdateToCluster (current .Spec )
167190 } else {
191+ log .Debug ().Msg ("UpdatedCRSpec via agency" )
168192 if err := ci .depl .updateCRSpec (* newSpec ); err != nil {
169193 log .Warn ().Err (err ).Msg ("Failed to update current deployment" )
170194 return maskAny (err )
@@ -176,12 +200,14 @@ func (ci *clusterScalingIntegration) inspectCluster(ctx context.Context, expectS
176200// updateClusterServerCount updates the intended number of servers of the cluster.
177201// Returns true when it is safe to ask the cluster for updates.
178202func (ci * clusterScalingIntegration ) updateClusterServerCount (ctx context.Context , expectSuccess bool ) (bool , error ) {
203+ ci .log .Debug ().Msg ("updateClusterServerCount" )
179204 // Any update needed?
180205 ci .pendingUpdate .mutex .Lock ()
181206 spec := ci .pendingUpdate .spec
182207 ci .pendingUpdate .mutex .Unlock ()
183208 if spec == nil {
184209 // Nothing pending
210+ ci .log .Debug ().Msg ("Nothing pending" )
185211 return true , nil
186212 }
187213
@@ -198,13 +224,16 @@ func (ci *clusterScalingIntegration) updateClusterServerCount(ctx context.Contex
198224 ci .lastNumberOfServers .mutex .Unlock ()
199225
200226 // 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" )
202229 if err := arangod .SetNumberOfServers (ctx , c .Connection (), coordinatorCount , dbserverCount ); err != nil {
203230 if expectSuccess {
204231 log .Debug ().Err (err ).Msg ("Failed to set number of servers" )
205232 }
206233 return false , maskAny (err )
207234 }
235+ } else {
236+ ci .log .Debug ().Msg ("Nothing has changed" )
208237 }
209238
210239 // Success, now update internal state
0 commit comments