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 <tnielsen@redhat.com>
This commit is contained in:
2 files changed
+5
-8
No files matched your search
@@ -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.")
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user