diff --git a/metrics/vendor/github.com/red-hat-storage/ocs-operator/v4/controllers/util/k8sutil.go b/metrics/vendor/github.com/red-hat-storage/ocs-operator/v4/controllers/util/k8sutil.go index fb4f5921f4..9f001b5158 100644 --- a/metrics/vendor/github.com/red-hat-storage/ocs-operator/v4/controllers/util/k8sutil.go +++ b/metrics/vendor/github.com/red-hat-storage/ocs-operator/v4/controllers/util/k8sutil.go @@ -11,6 +11,7 @@ import ( "github.com/go-logr/logr" configv1 "github.com/openshift/api/config/v1" + rookCephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" "golang.org/x/exp/maps" corev1 "k8s.io/api/core/v1" storagev1 "k8s.io/api/storage/v1" @@ -203,6 +204,20 @@ func GetStorageClusterInNamespace(ctx context.Context, cl client.Client, namespa return &storageClusterList.Items[0], nil } +func GetCephClusterInNamespace(ctx context.Context, cl client.Client, namespace string) (*rookCephv1.CephCluster, error) { + cephClusterList := &rookCephv1.CephClusterList{} + err := cl.List(ctx, cephClusterList, client.InNamespace(namespace), client.Limit(1)) + if err != nil { + return nil, fmt.Errorf("unable to list cephCluster(s) in namespace %s: %v", namespace, err) + } + + if len(cephClusterList.Items) == 0 { + return nil, fmt.Errorf("no cephCluster found in namespace %s", namespace) + } + + return &cephClusterList.Items[0], nil +} + func NewK8sClient(scheme *runtime.Scheme) (client.Client, error) { klog.Info("Setting up k8s client")