Skip to content

Commit

Permalink
Expands OnboardCosumer and creates odf-info
Browse files Browse the repository at this point in the history
Signed-off-by: raaizik <[email protected]>
  • Loading branch information
raaizik committed Feb 12, 2024
1 parent 35ac7ee commit 32abff4
Show file tree
Hide file tree
Showing 4 changed files with 386 additions and 215 deletions.
67 changes: 3 additions & 64 deletions controllers/storagecluster/clusterclaims.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@ package storagecluster
import (
"context"
"fmt"
"strconv"
"strings"

"github.com/go-logr/logr"
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
ocsv1 "github.com/red-hat-storage/ocs-operator/api/v4/v1"
rookCephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
corev1 "k8s.io/api/core/v1"
extensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -22,23 +17,19 @@ import (
clusterv1alpha1 "open-cluster-management.io/api/cluster/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"strconv"
)

const (
RookCephMonSecretName = "rook-ceph-mon"
FsidKey = "fsid"
OdfOperatorNamePrefix = "odf-operator"
ClusterClaimCRDName = "clusterclaims.cluster.open-cluster-management.io"
ClusterClaimCRDName = "clusterclaims.cluster.open-cluster-management.io"
)

var (
ClusterClaimGroup = "odf"
OdfVersion = fmt.Sprintf("version.%s.openshift.io", ClusterClaimGroup)
StorageSystemName = fmt.Sprintf("storagesystemname.%s.openshift.io", ClusterClaimGroup)
StorageClusterName = fmt.Sprintf("storageclustername.%s.openshift.io", ClusterClaimGroup)
StorageClusterCount = fmt.Sprintf("count.storageclusters.%s.openshift.io", ClusterClaimGroup)
StorageClusterDROptimized = fmt.Sprintf("droptimized.%s.openshift.io", ClusterClaimGroup)
CephFsid = fmt.Sprintf("cephfsid.%s.openshift.io", ClusterClaimGroup)
)

type ocsClusterClaim struct{}
Expand Down Expand Up @@ -83,20 +74,8 @@ func (obj *ocsClusterClaim) ensureCreated(r *StorageClusterReconciler, instance
StorageCluster: instance,
}

odfVersion, err := creator.getOdfVersion()
if err != nil {
r.Log.Error(err, "failed to get odf version for operator. retrying again")
return reconcile.Result{}, err
}

storageClusterCount := len(r.clusters.GetStorageClusters())

cephFsid, err := creator.getCephFsid()
if err != nil {
r.Log.Error(err, "failed to get ceph fsid from secret. retrying again")
return reconcile.Result{}, err
}

storageSystemName, err := creator.getStorageSystemName()
if err != nil {
r.Log.Error(err, "failed to get storagesystem name. retrying again")
Expand All @@ -117,8 +96,6 @@ func (obj *ocsClusterClaim) ensureCreated(r *StorageClusterReconciler, instance
err = creator.setStorageClusterCount(strconv.Itoa(storageClusterCount)).
setStorageSystemName(storageSystemName).
setStorageClusterName(instance.Name).
setOdfVersion(odfVersion).
setCephFsid(cephFsid).
setDROptimized(isDROptimized).
create()

Expand Down Expand Up @@ -179,34 +156,6 @@ func (c *ClusterClaimCreator) create() error {

return nil
}
func (c *ClusterClaimCreator) getOdfVersion() (string, error) {
var csvs operatorsv1alpha1.ClusterServiceVersionList
err := c.Client.List(c.Context, &csvs, &client.ListOptions{Namespace: c.StorageCluster.Namespace})
if err != nil {
return "", err
}

for _, csv := range csvs.Items {
if strings.HasPrefix(csv.Name, OdfOperatorNamePrefix) {
return csv.Spec.Version.String(), nil
}
}

return "", fmt.Errorf("failed to find csv with prefix %q", OdfOperatorNamePrefix)
}

func (c *ClusterClaimCreator) getCephFsid() (string, error) {
var rookCephMonSecret corev1.Secret
err := c.Client.Get(c.Context, types.NamespacedName{Name: RookCephMonSecretName, Namespace: c.StorageCluster.Namespace}, &rookCephMonSecret)
if err != nil {
return "", err
}
if val, ok := rookCephMonSecret.Data[FsidKey]; ok {
return string(val), nil
}

return "", fmt.Errorf("failed to fetch ceph fsid from %q secret", RookCephMonSecretName)
}

func (c *ClusterClaimCreator) getIsDROptimized(serverVersion *version.Info) (string, error) {
var cephCluster rookCephv1.CephCluster
Expand Down Expand Up @@ -238,21 +187,11 @@ func (c *ClusterClaimCreator) setStorageSystemName(name string) *ClusterClaimCre
return c
}

func (c *ClusterClaimCreator) setOdfVersion(version string) *ClusterClaimCreator {
c.Values[OdfVersion] = version
return c
}

func (c *ClusterClaimCreator) setStorageClusterName(name string) *ClusterClaimCreator {
c.Values[StorageClusterName] = fmt.Sprintf("%s/%s", name, c.StorageCluster.GetNamespace())
return c
}

func (c *ClusterClaimCreator) setCephFsid(fsid string) *ClusterClaimCreator {
c.Values[CephFsid] = fsid
return c
}

func (c *ClusterClaimCreator) setDROptimized(optimized string) *ClusterClaimCreator {
c.Values[StorageClusterDROptimized] = optimized
return c
Expand All @@ -277,7 +216,7 @@ func (obj *ocsClusterClaim) ensureDeleted(r *StorageClusterReconciler, _ *ocsv1.
}
return reconcile.Result{}, nil
}
names := []string{OdfVersion, StorageSystemName, StorageClusterName, CephFsid}
names := []string{StorageSystemName, StorageClusterName}
for _, name := range names {
cc := clusterv1alpha1.ClusterClaim{
ObjectMeta: metav1.ObjectMeta{
Expand Down
Loading

0 comments on commit 32abff4

Please sign in to comment.