Merge pull request #10523 from leseb/fix-stuck-reconciler
core: fix stuck reconciler (more checkpoints for cancelled context)
This commit is contained in:
11 files changed
+66
-50
No files matched your search
@@ -99,8 +99,8 @@ func TestGenerateConfigFile(t *testing.T) {
|
||||
Context: ctx,
|
||||
}
|
||||
|
||||
isInitialized := clusterInfo.IsInitialized(true)
|
||||
assert.True(t, isInitialized)
|
||||
isInitialized := clusterInfo.IsInitialized()
|
||||
assert.NoError(t, isInitialized)
|
||||
|
||||
// generate the config file to disk now
|
||||
configFilePath, err := generateConfigFile(context, clusterInfo, configDir, filepath.Join(configDir, "mykeyring"), nil, nil)
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
||||
cephver "github.com/rook/rook/pkg/operator/ceph/version"
|
||||
"github.com/rook/rook/pkg/operator/k8sutil"
|
||||
@@ -112,42 +113,30 @@ func AdminTestClusterInfo(namespace string) *ClusterInfo {
|
||||
// in. This method exists less out of necessity than the desire to be explicit about the lifecycle
|
||||
// of the ClusterInfo struct during startup, specifically that it is expected to exist after the
|
||||
// Rook operator has started up or connected to the first components of the Ceph cluster.
|
||||
func (c *ClusterInfo) IsInitialized(logError bool) bool {
|
||||
var isInitialized bool
|
||||
|
||||
func (c *ClusterInfo) IsInitialized() error {
|
||||
if c == nil {
|
||||
if logError {
|
||||
logger.Error("clusterInfo is nil")
|
||||
}
|
||||
} else if c.FSID == "" {
|
||||
if logError {
|
||||
logger.Error("cluster fsid is empty")
|
||||
}
|
||||
} else if c.MonitorSecret == "" {
|
||||
if logError {
|
||||
logger.Error("monitor secret is empty")
|
||||
}
|
||||
} else if c.CephCred.Username == "" {
|
||||
if logError {
|
||||
logger.Error("ceph username is empty")
|
||||
}
|
||||
} else if c.CephCred.Secret == "" {
|
||||
if logError {
|
||||
logger.Error("ceph secret is empty")
|
||||
}
|
||||
} else if c.Context == nil {
|
||||
if logError {
|
||||
logger.Error("nil context")
|
||||
}
|
||||
} else if c.Context.Err() != nil {
|
||||
if logError {
|
||||
logger.Errorf("%v", c.Context.Err())
|
||||
}
|
||||
} else {
|
||||
isInitialized = true
|
||||
return errors.New("clusterInfo is nil")
|
||||
}
|
||||
if c.FSID == "" {
|
||||
return errors.New("cluster fsid is empty")
|
||||
}
|
||||
if c.MonitorSecret == "" {
|
||||
return errors.New("monitor secret is empty")
|
||||
}
|
||||
if c.CephCred.Username == "" {
|
||||
return errors.New("ceph username is empty")
|
||||
}
|
||||
if c.CephCred.Secret == "" {
|
||||
return errors.New("ceph secret is empty")
|
||||
}
|
||||
if c.Context == nil {
|
||||
return errors.New("context is nil")
|
||||
}
|
||||
if c.Context.Err() != nil {
|
||||
return c.Context.Err()
|
||||
}
|
||||
|
||||
return isInitialized
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewMonInfo returns a new Ceph mon info struct from the given inputs.
|
||||
|
||||
@@ -118,8 +118,8 @@ func (c *cluster) reconcileCephDaemons(rookImage string, cephVersion cephver.Cep
|
||||
c.ClusterInfo.NetworkSpec = c.Spec.Network
|
||||
|
||||
// The cluster Identity must be established at this point
|
||||
if !c.ClusterInfo.IsInitialized(true) {
|
||||
return errors.New("the cluster identity was not established")
|
||||
if err := c.ClusterInfo.IsInitialized(); err != nil {
|
||||
return errors.Wrap(err, "the cluster identity was not established")
|
||||
}
|
||||
|
||||
if c.ClusterInfo.Context.Err() != nil {
|
||||
|
||||
@@ -94,8 +94,8 @@ func (c *ClusterController) configureExternalCephCluster(cluster *cluster) error
|
||||
}
|
||||
|
||||
// The cluster Identity must be established at this point
|
||||
if !cluster.ClusterInfo.IsInitialized(true) {
|
||||
return errors.New("the cluster identity was not established")
|
||||
if err := cluster.ClusterInfo.IsInitialized(); err != nil {
|
||||
return errors.Wrap(err, "the cluster identity was not established")
|
||||
}
|
||||
logger.Info("external cluster identity established")
|
||||
|
||||
|
||||
@@ -256,6 +256,18 @@ func (r *ReconcileCephCluster) reconcile(request reconcile.Request) (reconcile.R
|
||||
// Do reconcile here!
|
||||
ownerInfo := k8sutil.NewOwnerInfo(cephCluster, r.scheme)
|
||||
if err := r.clusterController.reconcileCephCluster(cephCluster, ownerInfo); err != nil {
|
||||
// If the error has a context cancelled let's return a success result so that the controller can
|
||||
// exit gracefully and the goroutine (the one the manager runs in) won't block retrying even if the parent context has been
|
||||
// cancelled.
|
||||
// Normally this should not happen but in some circumstances if the context is cancelled we will
|
||||
// error-loop (backoff) and the controller will never exit (even though a new one has been
|
||||
// started). So we would get messages from the other go routine printing a message
|
||||
// repeatedly that the context is cancelled.
|
||||
if errors.Is(r.opManagerContext.Err(), context.Canceled) {
|
||||
logger.Info("context cancelled, exiting reconcile")
|
||||
return reconcile.Result{}, *cephCluster, nil
|
||||
}
|
||||
|
||||
return reconcile.Result{}, *cephCluster, errors.Wrapf(err, "failed to reconcile cluster %q", cephCluster.Name)
|
||||
}
|
||||
|
||||
|
||||
@@ -133,6 +133,12 @@ func (hc *HealthChecker) Check(monitoringRoutines map[string]*controller.Cluster
|
||||
delete(monitoringRoutines, daemon)
|
||||
return
|
||||
|
||||
// Since c.ClusterInfo.IsInitialized() below uses a different context, we need to check if the context is done
|
||||
case <-hc.monCluster.ClusterInfo.Context.Done():
|
||||
logger.Infof("stopping monitoring of mons in namespace %q", hc.monCluster.Namespace)
|
||||
delete(monitoringRoutines, daemon)
|
||||
return
|
||||
|
||||
case <-time.After(hc.interval):
|
||||
logger.Debugf("checking health of mons")
|
||||
err := hc.monCluster.checkHealth(monitoringRoutines[daemon].InternalCtx)
|
||||
@@ -148,8 +154,8 @@ func (c *Cluster) checkHealth(ctx context.Context) error {
|
||||
defer c.releaseOrchestrationLock()
|
||||
|
||||
// If cluster details are not initialized
|
||||
if !c.ClusterInfo.IsInitialized(true) {
|
||||
return errors.New("skipping mon health check since cluster details are not initialized")
|
||||
if err := c.ClusterInfo.IsInitialized(); err != nil {
|
||||
return errors.Wrap(err, "skipping mon health check since cluster details are not initialized")
|
||||
}
|
||||
|
||||
// If the cluster is converged and no mons were specified
|
||||
|
||||
@@ -1320,6 +1320,11 @@ func waitForQuorumWithMons(context *clusterd.Context, clusterInfo *cephclient.Cl
|
||||
retryCount := 0
|
||||
retryMax := 30
|
||||
for {
|
||||
// Return immediately if the context has been canceled
|
||||
if clusterInfo.Context.Err() != nil {
|
||||
return clusterInfo.Context.Err()
|
||||
}
|
||||
|
||||
retryCount++
|
||||
if retryCount > retryMax {
|
||||
return errors.New("exceeded max retry count waiting for monitors to reach quorum")
|
||||
|
||||
@@ -213,7 +213,7 @@ func TestOperatorRestart(t *testing.T) {
|
||||
// start a basic cluster
|
||||
info, err := c.Start(c.ClusterInfo, c.rookVersion, cephver.Quincy, c.spec)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, info.IsInitialized(true))
|
||||
assert.NoError(t, info.IsInitialized())
|
||||
|
||||
validateStart(t, c)
|
||||
|
||||
@@ -223,7 +223,7 @@ func TestOperatorRestart(t *testing.T) {
|
||||
// starting again should be a no-op, but will not result in an error
|
||||
info, err = c.Start(c.ClusterInfo, c.rookVersion, cephver.Quincy, c.spec)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, info.IsInitialized(true))
|
||||
assert.NoError(t, info.IsInitialized())
|
||||
|
||||
validateStart(t, c)
|
||||
}
|
||||
@@ -241,7 +241,7 @@ func TestOperatorRestartHostNetwork(t *testing.T) {
|
||||
// start a basic cluster
|
||||
info, err := c.Start(c.ClusterInfo, c.rookVersion, cephver.Quincy, c.spec)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, info.IsInitialized(true))
|
||||
assert.NoError(t, info.IsInitialized())
|
||||
|
||||
validateStart(t, c)
|
||||
|
||||
@@ -253,7 +253,7 @@ func TestOperatorRestartHostNetwork(t *testing.T) {
|
||||
// starting again should be a no-op, but still results in an error
|
||||
info, err = c.Start(c.ClusterInfo, c.rookVersion, cephver.Quincy, c.spec)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, info.IsInitialized(true), info)
|
||||
assert.NoError(t, info.IsInitialized(), info)
|
||||
|
||||
validateStart(t, c)
|
||||
}
|
||||
|
||||
@@ -268,13 +268,14 @@ func (c *Cluster) updateAndCreateOSDsLoop(
|
||||
updateConfig.updateExistingOSDs(errs)
|
||||
|
||||
case <-minuteTicker.C:
|
||||
if c.clusterInfo.Context.Err() != nil {
|
||||
return false, c.clusterInfo.Context.Err()
|
||||
}
|
||||
// Log progress
|
||||
c, cExp := createConfig.progress()
|
||||
u, uExp := updateConfig.progress()
|
||||
logger.Infof("waiting... %d of %d OSD prepare jobs have finished processing and %d of %d OSDs have been updated", c, cExp, u, uExp)
|
||||
|
||||
case <-c.clusterInfo.Context.Done():
|
||||
logger.Infof("context cancelled, exiting OSD update and create loop")
|
||||
return false, c.clusterInfo.Context.Err()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -153,9 +153,9 @@ func (c *cluster) validateCephVersion(version *cephver.CephVersion) error {
|
||||
}
|
||||
}
|
||||
|
||||
if !clusterInfo.IsInitialized(false) {
|
||||
if err := clusterInfo.IsInitialized(); err != nil {
|
||||
// If not initialized, this is likely a new cluster so there is nothing to do
|
||||
logger.Debug("cluster not initialized, nothing to validate")
|
||||
logger.Debugf("cluster not initialized, nothing to validate. %v", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -400,6 +400,9 @@ func (r *ReconcileClusterDisruption) reconcilePDBsForOSDs(
|
||||
|
||||
err = r.client.Update(clusterInfo.Context, pdbStateMap)
|
||||
if err != nil {
|
||||
if errors.Is(err, context.Canceled) {
|
||||
return reconcile.Result{}, nil
|
||||
}
|
||||
return reconcile.Result{}, errors.Wrapf(err, "failed to update configMap %q in cluster %q", pdbStateMapName, request)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user