core: check for canceled context in external mode
This is fixing a potential race where the context is canceled and the
external cluster is trying to fetch the cluster info. If the context is
canceled then the loop will be stuck forever. Now we check for the
canceled context and return appropriately.
Signed-off-by: Sébastien Han <seb@redhat.com>
(cherry picked from commit fdcad15b87)
This commit is contained in:
1 parent
b778ff1695
commit
48feb7d4aa
3 files changed
+19
-6
No files matched your search
@@ -138,6 +138,10 @@ func (c *ClusterInfo) IsInitialized(logError bool) bool {
|
||||
if logError {
|
||||
logger.Error("nil context")
|
||||
}
|
||||
} else if c.Context.Err() != nil {
|
||||
if logError {
|
||||
logger.Errorf("%v", c.Context.Err())
|
||||
}
|
||||
} else {
|
||||
isInitialized = true
|
||||
}
|
||||
|
||||
@@ -49,7 +49,10 @@ func (c *ClusterController) configureExternalCephCluster(cluster *cluster) error
|
||||
// loop until we find the secret necessary to connect to the external cluster
|
||||
// then populate clusterInfo
|
||||
|
||||
cluster.ClusterInfo = mon.PopulateExternalClusterInfo(c.context, c.OpManagerCtx, c.namespacedName.Namespace, cluster.ownerInfo)
|
||||
cluster.ClusterInfo, err = mon.PopulateExternalClusterInfo(c.context, c.OpManagerCtx, c.namespacedName.Namespace, cluster.ownerInfo)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to populate external cluster info")
|
||||
}
|
||||
cluster.ClusterInfo.SetName(c.namespacedName.Name)
|
||||
cluster.ClusterInfo.Context = c.OpManagerCtx
|
||||
|
||||
|
||||
@@ -373,18 +373,24 @@ func ExtractKey(contents string) (string, error) {
|
||||
return secret, nil
|
||||
}
|
||||
|
||||
// PopulateExternalClusterInfo Add validation in the code to fail if the external cluster has no OSDs keep waiting
|
||||
func PopulateExternalClusterInfo(context *clusterd.Context, ctx context.Context, namespace string, ownerInfo *k8sutil.OwnerInfo) *cephclient.ClusterInfo {
|
||||
// PopulateExternalClusterInfo Add validation in the code to fail if the external cluster has no
|
||||
// OSDs keep waiting
|
||||
func PopulateExternalClusterInfo(context *clusterd.Context, ctx context.Context, namespace string, ownerInfo *k8sutil.OwnerInfo) (*cephclient.ClusterInfo, error) {
|
||||
for {
|
||||
clusterInfo, _, _, err := LoadClusterInfo(context, ctx, namespace)
|
||||
// Checking for the context makes sure we don't loop forever with a canceled context
|
||||
if ctx.Err() != nil {
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
clusterInfo, _, _, err := CreateOrLoadClusterInfo(context, ctx, namespace, nil)
|
||||
if err != nil {
|
||||
logger.Warningf("waiting for the csi connection info of the external cluster. retrying in %s.", externalConnectionRetry.String())
|
||||
logger.Warningf("waiting for connection info of the external cluster. retrying in %s.", externalConnectionRetry.String())
|
||||
logger.Debugf("%v", err)
|
||||
time.Sleep(externalConnectionRetry)
|
||||
continue
|
||||
}
|
||||
logger.Infof("found the cluster info to connect to the external cluster. will use %q to check health and monitor status. mons=%+v", clusterInfo.CephCred.Username, clusterInfo.Monitors)
|
||||
clusterInfo.OwnerInfo = ownerInfo
|
||||
return clusterInfo
|
||||
|
||||
return clusterInfo, nil
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user