Skip to content

Commit fc3ab8f

Browse files
committed
Prevent warnings about not reaching the cluster in the first 2min, while the cluster may not yet be ready
1 parent badc27c commit fc3ab8f

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

pkg/deployment/cluster_scaling_integration.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ type clusterScalingIntegration struct {
5050
}
5151
}
5252

53+
const (
54+
maxClusterBootstrapTime = time.Minute * 2 // Time we allow a cluster bootstrap to take, before we can do cluster inspections.
55+
)
56+
5357
// newClusterScalingIntegration creates a new clusterScalingIntegration.
5458
func newClusterScalingIntegration(depl *Deployment) *clusterScalingIntegration {
5559
return &clusterScalingIntegration{
@@ -67,20 +71,29 @@ func (ci *clusterScalingIntegration) SendUpdateToCluster(spec api.DeploymentSpec
6771

6872
// listenForClusterEvents keep listening for changes entered in the UI of the cluster.
6973
func (ci *clusterScalingIntegration) ListenForClusterEvents(stopCh <-chan struct{}) {
74+
start := time.Now()
75+
goodInspections := 0
7076
for {
7177
delay := time.Second * 2
7278

7379
// Is deployment in running state
7480
if ci.depl.GetPhase() == api.DeploymentPhaseRunning {
7581
// Update cluster with our state
7682
ctx := context.Background()
77-
safeToAskCluster, err := ci.updateClusterServerCount(ctx)
83+
expectSuccess := goodInspections > 0 || time.Since(start) > maxClusterBootstrapTime
84+
safeToAskCluster, err := ci.updateClusterServerCount(ctx, expectSuccess)
7885
if err != nil {
79-
ci.log.Debug().Err(err).Msg("Cluster update failed")
86+
if expectSuccess {
87+
ci.log.Debug().Err(err).Msg("Cluster update failed")
88+
}
8089
} else if safeToAskCluster {
8190
// Inspect once
82-
if err := ci.inspectCluster(ctx); err != nil {
83-
ci.log.Debug().Err(err).Msg("Cluster inspection failed")
91+
if err := ci.inspectCluster(ctx, expectSuccess); err != nil {
92+
if expectSuccess {
93+
ci.log.Debug().Err(err).Msg("Cluster inspection failed")
94+
}
95+
} else {
96+
goodInspections++
8497
}
8598
}
8699
}
@@ -96,15 +109,17 @@ func (ci *clusterScalingIntegration) ListenForClusterEvents(stopCh <-chan struct
96109
}
97110

98111
// Perform a single inspection of the cluster
99-
func (ci *clusterScalingIntegration) inspectCluster(ctx context.Context) error {
112+
func (ci *clusterScalingIntegration) inspectCluster(ctx context.Context, expectSuccess bool) error {
100113
log := ci.log
101114
c, err := ci.depl.clientCache.GetDatabase(ctx)
102115
if err != nil {
103116
return maskAny(err)
104117
}
105118
req, err := arangod.GetNumberOfServers(ctx, c.Connection())
106119
if err != nil {
107-
log.Debug().Err(err).Msg("Failed to get number of servers")
120+
if expectSuccess {
121+
log.Debug().Err(err).Msg("Failed to get number of servers")
122+
}
108123
return maskAny(err)
109124
}
110125
if req.Coordinators == nil && req.DBServers == nil {
@@ -150,7 +165,7 @@ func (ci *clusterScalingIntegration) inspectCluster(ctx context.Context) error {
150165

151166
// updateClusterServerCount updates the intended number of servers of the cluster.
152167
// Returns true when it is safe to ask the cluster for updates.
153-
func (ci *clusterScalingIntegration) updateClusterServerCount(ctx context.Context) (bool, error) {
168+
func (ci *clusterScalingIntegration) updateClusterServerCount(ctx context.Context, expectSuccess bool) (bool, error) {
154169
// Any update needed?
155170
ci.pendingUpdate.mutex.Lock()
156171
spec := ci.pendingUpdate.spec
@@ -168,7 +183,9 @@ func (ci *clusterScalingIntegration) updateClusterServerCount(ctx context.Contex
168183
coordinatorCount := spec.Coordinators.GetCount()
169184
dbserverCount := spec.DBServers.GetCount()
170185
if err := arangod.SetNumberOfServers(ctx, c.Connection(), coordinatorCount, dbserverCount); err != nil {
171-
log.Debug().Err(err).Msg("Failed to set number of servers")
186+
if expectSuccess {
187+
log.Debug().Err(err).Msg("Failed to set number of servers")
188+
}
172189
return false, maskAny(err)
173190
}
174191

0 commit comments

Comments
 (0)