From a3bf93595795cdfd56449213dc0f4f633ddcabfb Mon Sep 17 00:00:00 2001 From: Travis Nielsen Date: Wed, 5 Aug 2020 15:50:59 -0600 Subject: [PATCH] ceph: update the cluster status with a clean object The cluster CR status needs to be updated with the latest object instead of a cached copy or else it could fail if there is some other update. Using the Rook clientset ensures it is the latest instead of using the cached controller runtime object. Signed-off-by: Travis Nielsen --- pkg/operator/ceph/cluster/cephstatus.go | 8 +++----- pkg/operator/ceph/config/conditions.go | 5 ++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pkg/operator/ceph/cluster/cephstatus.go b/pkg/operator/ceph/cluster/cephstatus.go index 16e33766b..0a2316a83 100644 --- a/pkg/operator/ceph/cluster/cephstatus.go +++ b/pkg/operator/ceph/cluster/cephstatus.go @@ -18,7 +18,6 @@ limitations under the License. package cluster import ( - "context" "os" "time" @@ -31,6 +30,7 @@ import ( cephver "github.com/rook/rook/pkg/operator/ceph/version" v1 "k8s.io/api/core/v1" kerrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -127,8 +127,7 @@ func (c *cephStatusChecker) checkStatus() { // updateStatus updates an object with a given status func (c *cephStatusChecker) updateCephStatus(status *cephclient.CephStatus, condition cephv1.ConditionType, reason, message string) error { clusterName := c.clusterInfo.NamespacedName() - cephCluster := &cephv1.CephCluster{} - err := c.client.Get(context.TODO(), clusterName, cephCluster) + cephCluster, err := c.context.RookClientset.CephV1().CephClusters(clusterName.Namespace).Get(clusterName.Name, metav1.GetOptions{}) if err != nil { if kerrors.IsNotFound(err) { logger.Debug("CephCluster resource not found. Ignoring since object must be deleted.") @@ -182,8 +181,7 @@ func formatTime(t time.Time) string { func (c *ClusterController) updateClusterCephVersion(image string, cephVersion cephver.CephVersion) { logger.Infof("cluster %q: version %q detected for image %q", c.namespacedName.Namespace, cephVersion.String(), image) - cephCluster := &cephv1.CephCluster{} - err := c.client.Get(context.TODO(), c.namespacedName, cephCluster) + cephCluster, err := c.context.RookClientset.CephV1().CephClusters(c.namespacedName.Namespace).Get(c.namespacedName.Name, metav1.GetOptions{}) if err != nil { if kerrors.IsNotFound(err) { logger.Debug("CephCluster resource not found. Ignoring since object must be deleted.") diff --git a/pkg/operator/ceph/config/conditions.go b/pkg/operator/ceph/config/conditions.go index 844bffcd8..75e9caa66 100644 --- a/pkg/operator/ceph/config/conditions.go +++ b/pkg/operator/ceph/config/conditions.go @@ -47,8 +47,7 @@ func ConditionExport(context *clusterd.Context, namespaceName types.NamespacedNa // setCondition updates the conditions of the cluster custom resource func setCondition(c *clusterd.Context, namespaceName types.NamespacedName, newCondition cephv1.Condition) { - cluster := &cephv1.CephCluster{} - err := c.Client.Get(context.TODO(), namespaceName, cluster) + cluster, err := c.RookClientset.CephV1().CephClusters(namespaceName.Namespace).Get(namespaceName.Name, metav1.GetOptions{}) if err != nil { if kerrors.IsNotFound(err) { logger.Errorf("no CephCluster could not be found. %+v", err) @@ -86,7 +85,7 @@ func setCondition(c *clusterd.Context, namespaceName types.NamespacedName, newCo cluster.Status.State = state } cluster.Status.Message = newCondition.Message - logger.Infof("CephCluster %q status: %q. %q", namespaceName.Namespace, cluster.Status.Phase, cluster.Status.Message) + logger.Debugf("CephCluster %q status: %q. %q", namespaceName.Namespace, cluster.Status.Phase, cluster.Status.Message) } err = c.Client.Status().Update(context.TODO(), cluster)