diff --git a/pkg/daemon/ceph/client/info.go b/pkg/daemon/ceph/client/info.go index e0c28890d..b27bbbbf1 100644 --- a/pkg/daemon/ceph/client/info.go +++ b/pkg/daemon/ceph/client/info.go @@ -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 } diff --git a/pkg/operator/ceph/cluster/cluster_external.go b/pkg/operator/ceph/cluster/cluster_external.go index fb97a9adf..a77a6f184 100644 --- a/pkg/operator/ceph/cluster/cluster_external.go +++ b/pkg/operator/ceph/cluster/cluster_external.go @@ -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 diff --git a/pkg/operator/ceph/cluster/mon/config.go b/pkg/operator/ceph/cluster/mon/config.go index 56c9d23ac..b29f2fb30 100644 --- a/pkg/operator/ceph/cluster/mon/config.go +++ b/pkg/operator/ceph/cluster/mon/config.go @@ -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 } }