From 4950f96bc3e2aeecfa9e8789569580eba70b0b34 Mon Sep 17 00:00:00 2001 From: Rewant Soni Date: Mon, 4 Nov 2024 21:35:46 +0530 Subject: [PATCH] add generated changes Signed-off-by: Rewant Soni --- .../ocs-operator/manifests/provider-role.yaml | 1 + .../v4/controllers/util/k8sutil.go | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/deploy/ocs-operator/manifests/provider-role.yaml b/deploy/ocs-operator/manifests/provider-role.yaml index dd1c692975..74ed3fa301 100644 --- a/deploy/ocs-operator/manifests/provider-role.yaml +++ b/deploy/ocs-operator/manifests/provider-role.yaml @@ -16,6 +16,7 @@ rules: resources: - cephfilesystemsubvolumegroups - cephblockpoolradosnamespaces + - cephblockpools verbs: - get - list 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 fb1e5504ea..87103da9d1 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 @@ -166,3 +166,29 @@ func GenerateNameForNonResilientCephBlockPoolSC(initData *ocsv1.StorageCluster) } return fmt.Sprintf("%s-ceph-non-resilient-rbd", initData.Name) } + +func GetStorageClusterInNamespace(ctx context.Context, cl client.Client, namespace string) (*ocsv1.StorageCluster, error) { + storageClusterList := &ocsv1.StorageClusterList{} + err := cl.List(ctx, storageClusterList, client.InNamespace(namespace)) + if err != nil { + return nil, fmt.Errorf("unable to list storageCluster(s) in namespace %s: %v", namespace, err) + } + + var foundSc *ocsv1.StorageCluster + for i := range storageClusterList.Items { + sc := &storageClusterList.Items[i] + if sc.Status.Phase == PhaseIgnored { + continue // Skip Ignored storage cluster + } + if foundSc != nil { + // This means we have already found one storage cluster, so this is a second one + return nil, fmt.Errorf("multiple storageClusters found in namespace %s, expected: 1 actual: %v", namespace, len(storageClusterList.Items)) + } + foundSc = sc + } + + if foundSc == nil { + return nil, fmt.Errorf("no storageCluster found in namespace %s, expected: 1", namespace) + } + return foundSc, nil +}