diff --git a/pkg/operator/ceph/cluster/cephstatus.go b/pkg/operator/ceph/cluster/cephstatus.go index a08ef82c5..68b7fbdae 100644 --- a/pkg/operator/ceph/cluster/cephstatus.go +++ b/pkg/operator/ceph/cluster/cephstatus.go @@ -26,7 +26,6 @@ import ( cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" "github.com/rook/rook/pkg/clusterd" cephclient "github.com/rook/rook/pkg/daemon/ceph/client" - "github.com/rook/rook/pkg/daemon/ceph/config" opcontroller "github.com/rook/rook/pkg/operator/ceph/controller" cephver "github.com/rook/rook/pkg/operator/ceph/version" kerrors "k8s.io/apimachinery/pkg/api/errors" @@ -44,18 +43,18 @@ type cephStatusChecker struct { context *clusterd.Context resourceName string interval time.Duration - externalCred config.ExternalCred + cephUser string client client.Client namespacedName types.NamespacedName } // newCephStatusChecker creates a new HealthChecker object -func newCephStatusChecker(context *clusterd.Context, resourceName string, externalCred config.ExternalCred, namespacedName types.NamespacedName) *cephStatusChecker { +func newCephStatusChecker(context *clusterd.Context, resourceName string, cephUser string, namespacedName types.NamespacedName) *cephStatusChecker { c := &cephStatusChecker{ context: context, resourceName: resourceName, interval: defaultStatusCheckInterval, - externalCred: externalCred, + cephUser: cephUser, client: context.Client, namespacedName: namespacedName, } @@ -95,19 +94,8 @@ func (c *cephStatusChecker) checkStatus() { logger.Debugf("checking health of cluster") - // Set the user health check to the admin user - healthCheckUser := cephclient.AdminUsername - - // This is an external cluster OR if the admin keyring is not present - // As of 1.3 an external cluster is deployed it uses a different user to check ceph's status - if c.externalCred.Username != "" && c.externalCred.Secret != "" { - if c.externalCred.Username != cephclient.AdminUsername { - healthCheckUser = c.externalCred.Username - } - } - // Check ceph's status - status, err = cephclient.StatusWithUser(c.context, c.namespacedName.Namespace, healthCheckUser) + status, err = cephclient.StatusWithUser(c.context, c.namespacedName.Namespace, c.cephUser) if err != nil { logger.Errorf("failed to get ceph status. %v", err) return diff --git a/pkg/operator/ceph/cluster/cluster.go b/pkg/operator/ceph/cluster/cluster.go index 37d53b327..6a598f01c 100755 --- a/pkg/operator/ceph/cluster/cluster.go +++ b/pkg/operator/ceph/cluster/cluster.go @@ -191,13 +191,17 @@ func (c *ClusterController) initializeCluster(cluster *cluster, clusterObj *ceph } } + // The Ceph user the operator will use for management + cephUser := client.AdminUsername + // Depending on the cluster type choose the correct orchestation if cluster.Spec.External.Enable { err := c.configureExternalCephCluster(cluster) if err != nil { config.ConditionExport(c.context, c.namespacedName, cephv1.ConditionFailure, v1.ConditionTrue, "ClusterFailure", "Failed to configure external ceph cluster") - return errors.Wrapf(err, "failed to configure external ceph cluster. %v") + return errors.Wrap(err, "failed to configure external ceph cluster") } + cephUser = cluster.Info.ExternalCred.Username } else { // If the local cluster has already been configured, immediately start monitoring the cluster. // Test if the cluster has already been configured if the mgr deployment has been created. @@ -205,12 +209,12 @@ func (c *ClusterController) initializeCluster(cluster *cluster, clusterObj *ceph opts := metav1.ListOptions{LabelSelector: fmt.Sprintf("%s=%s", k8sutil.AppAttr, mgr.AppName)} mgrDeployments, err := c.context.Clientset.AppsV1().Deployments(cluster.Namespace).List(opts) if err == nil && len(mgrDeployments.Items) > 0 { - c.startClusterMonitoring(cluster) + c.startClusterMonitoring(cluster, cephUser) } - err := c.configureLocalCephCluster(cluster, clusterObj) + err = c.configureLocalCephCluster(cluster, clusterObj) if err != nil { - return errors.Wrapf(err, "failed to configure local ceph cluster. %v", err) + return errors.Wrap(err, "failed to configure local ceph cluster") } } @@ -218,40 +222,27 @@ func (c *ClusterController) initializeCluster(cluster *cluster, clusterObj *ceph cluster.mons.ClusterInfo = cluster.Info // Start the monitoring if not already started - c.startClusterMonitoring(cluster) + c.startClusterMonitoring(cluster, cephUser) + return nil } -func (c *ClusterController) startClusterMonitoring(cluster *cluster) error { +func (c *ClusterController) startClusterMonitoring(cluster *cluster, cephUser string) { if cluster.monitoringActivated == true { // the cluster monitoring goroutines are already running - logger.Infof("cluster is already being monitored") - return nil - } - - if cluster.Info == nil { - clusterInfo, _, _, err := mon.CreateOrLoadClusterInfo(c.context, cluster.Namespace, nil) - if err != nil { - return errors.Wrapf(err, "failed to start osd monitoring") - } - cluster.Info = clusterInfo - logger.Infof("cluster info loaded for monitoring: %+v", clusterInfo) + logger.Debugf("cluster is already being monitored for cluster %q", cluster.Namespace) + return } // enable the cluster monitoring goroutines once - logger.Infof("enabling cluster monitoring goroutines") + logger.Infof("enabling cluster monitoring goroutines for cluster %q", cluster.Namespace) cluster.monitoringActivated = true // Start client CRD watcher clientController := cephclient.NewClientController(c.context, cluster.Namespace) clientController.StartWatch(cluster.stopCh) - clientToUse := client.AdminUsername - if cluster.Spec.External.Enable { - clientToUse = cluster.Info.ExternalCred.Username - } - // Start the object bucket provisioner - bucketProvisioner := bucket.NewProvisioner(c.context, cluster.Namespace, clientToUse) + bucketProvisioner := bucket.NewProvisioner(c.context, cluster.Namespace, cephUser) // If cluster is external, pass down the user to the bucket controller // note: the error return below is ignored and is expected to be removed from the @@ -270,10 +261,8 @@ func (c *ClusterController) startClusterMonitoring(cluster *cluster) error { } // Start the ceph status checker - cephChecker := newCephStatusChecker(c.context, cluster.Namespace, cluster.mons.ClusterInfo.ExternalCred, c.namespacedName) + cephChecker := newCephStatusChecker(c.context, cluster.Namespace, cephUser, c.namespacedName) go cephChecker.checkCephStatus(cluster.stopCh) - - return nil } func (c *ClusterController) configureLocalCephCluster(cluster *cluster, clusterObj *cephv1.CephCluster) error {