From 60fb7f0ae90d7120ec955d532517ef950c8acaa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Han?= Date: Wed, 8 Dec 2021 17:30:07 +0100 Subject: [PATCH 1/3] core: always return nil on error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We should always return a nil pointer of clusterInfo if CreateOrLoadClusterInfo() returns an error. Closes: https://github.com/rook/rook/issues/9314 Signed-off-by: Sébastien Han (cherry picked from commit fdd243d3dea1d3f7972ef0bfaf04163506799017) --- pkg/operator/ceph/cluster/mon/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/operator/ceph/cluster/mon/config.go b/pkg/operator/ceph/cluster/mon/config.go index 831dc6411..b9feb3ea9 100644 --- a/pkg/operator/ceph/cluster/mon/config.go +++ b/pkg/operator/ceph/cluster/mon/config.go @@ -155,7 +155,7 @@ func CreateOrLoadClusterInfo(clusterdContext *clusterd.Context, context context. if clusterInfo.CephCred.Secret == adminSecretNameKey { secret, err := clusterdContext.Clientset.CoreV1().Secrets(namespace).Get(context, OperatorCreds, metav1.GetOptions{}) if err != nil { - return clusterInfo, maxMonID, monMapping, err + return nil, maxMonID, monMapping, err } // Populate external credential clusterInfo.CephCred.Username = string(secret.Data["userID"]) @@ -163,7 +163,7 @@ func CreateOrLoadClusterInfo(clusterdContext *clusterd.Context, context context. } if err := ValidateCephCSIConnectionSecrets(clusterdContext, namespace); err != nil { - return clusterInfo, maxMonID, monMapping, err + return nil, maxMonID, monMapping, err } return clusterInfo, maxMonID, monMapping, nil From 0e28e48c8d06c3408fb8dcb84008c60fed294b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Han?= Date: Wed, 8 Dec 2021 17:30:49 +0100 Subject: [PATCH 2/3] core: fix error message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's have a more accurate and correct error message that reflects what the failing function tried to do. Signed-off-by: Sébastien Han (cherry picked from commit 4f1a2d47a41f6ef9fa5ad44af1eef3e630dc67ad) --- pkg/operator/ceph/cluster/mon/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/operator/ceph/cluster/mon/config.go b/pkg/operator/ceph/cluster/mon/config.go index b9feb3ea9..56c9d23ac 100644 --- a/pkg/operator/ceph/cluster/mon/config.go +++ b/pkg/operator/ceph/cluster/mon/config.go @@ -104,7 +104,7 @@ func CreateOrLoadClusterInfo(clusterdContext *clusterd.Context, context context. clusterInfo, err = createNamedClusterInfo(clusterdContext, namespace) if err != nil { - return nil, maxMonID, monMapping, errors.Wrap(err, "failed to create mon secrets") + return nil, maxMonID, monMapping, errors.Wrap(err, "failed to create initial cluster info") } clusterInfo.Context = context From e58939a2a0aa1e99515b1fb7e6e9b90befed292f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Han?= Date: Wed, 8 Dec 2021 17:31:44 +0100 Subject: [PATCH 3/3] core: continue and create an initial cluster info or fail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's catch the correct error when no cluster info exists yet. If we have another error, we fail the orchestration and try again. This could help up catching small API hiccups for example. Signed-off-by: Sébastien Han (cherry picked from commit e5ce6abac0b8d944752bba76daa4869d424d7b3f) --- pkg/operator/ceph/cluster/cluster.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/operator/ceph/cluster/cluster.go b/pkg/operator/ceph/cluster/cluster.go index 3970e6763..7ba602234 100755 --- a/pkg/operator/ceph/cluster/cluster.go +++ b/pkg/operator/ceph/cluster/cluster.go @@ -168,7 +168,11 @@ func (c *ClusterController) initializeCluster(cluster *cluster) error { clusterInfo, _, _, err := mon.LoadClusterInfo(c.context, c.OpManagerCtx, cluster.Namespace) if err != nil { - logger.Infof("clusterInfo not yet found, must be a new cluster") + if errors.Is(err, mon.ClusterInfoNoClusterNoSecret) { + logger.Info("clusterInfo not yet found, must be a new cluster.") + } else { + return errors.Wrap(err, "failed to load cluster info") + } } else { clusterInfo.OwnerInfo = cluster.ownerInfo clusterInfo.SetName(c.namespacedName.Name)