Skip to content

Commit

Permalink
Merge pull request #9353 from rook/mergify/bp/release-1.7/pr-9347
Browse files Browse the repository at this point in the history
core: always return nil clusterInfo on failure (backport #9347)
  • Loading branch information
mergify[bot] committed Dec 9, 2021
2 parents a118856 + fe1754d commit 8bbfb94
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion pkg/operator/ceph/cluster/cluster.go
Expand Up @@ -182,7 +182,11 @@ func (c *ClusterController) initializeCluster(cluster *cluster) error {

clusterInfo, _, _, err := mon.LoadClusterInfo(c.context, 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)
Expand Down
12 changes: 8 additions & 4 deletions pkg/operator/ceph/cluster/mon/config.go
Expand Up @@ -57,6 +57,10 @@ const (
externalConnectionRetry = 60 * time.Second
)

var (
ClusterInfoNoClusterNoSecret = errors.New("not expected to create new cluster info and did not find existing secret")
)

func (c *Cluster) genMonSharedKeyring() string {
return fmt.Sprintf(
keyringTemplate,
Expand Down Expand Up @@ -96,12 +100,12 @@ func CreateOrLoadClusterInfo(clusterdContext *clusterd.Context, namespace string
return nil, maxMonID, monMapping, errors.Wrap(err, "failed to get mon secrets")
}
if ownerInfo == nil {
return nil, maxMonID, monMapping, errors.New("not expected to create new cluster info and did not find existing secret")
return nil, maxMonID, monMapping, ClusterInfoNoClusterNoSecret
}

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")
}

err = createClusterAccessSecret(clusterdContext.Clientset, namespace, clusterInfo, ownerInfo)
Expand Down Expand Up @@ -150,15 +154,15 @@ func CreateOrLoadClusterInfo(clusterdContext *clusterd.Context, namespace string
if clusterInfo.CephCred.Secret == adminSecretNameKey {
secret, err := clusterdContext.Clientset.CoreV1().Secrets(namespace).Get(ctx, 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"])
clusterInfo.CephCred.Secret = string(secret.Data["userKey"])
}

if err := ValidateCephCSIConnectionSecrets(clusterdContext, namespace); err != nil {
return clusterInfo, maxMonID, monMapping, err
return nil, maxMonID, monMapping, err
}

return clusterInfo, maxMonID, monMapping, nil
Expand Down

0 comments on commit 8bbfb94

Please sign in to comment.