Files
my-rook-config/pkg/operator/ceph/cluster/dependents.go
T
Sébastien Han 21c6a89541 subvolumegroup: add new crd
This introduces a new CRD to add the ability to create subvolumegroup
for a given ceph filesystem volume. Typically the name of the volume is
the name of the filesystem created by rook.

Closes: https://github.com/rook/rook/issues/7036
Signed-off-by: Sébastien Han <seb@redhat.com>
(cherry picked from commit 6e9eb33782)
2021-12-21 17:24:36 +00:00

88 lines
2.5 KiB
Go

/*
Copyright 2021 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cluster
import (
"context"
"strings"
"github.com/pkg/errors"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
"github.com/rook/rook/pkg/clusterd"
"github.com/rook/rook/pkg/util"
"github.com/rook/rook/pkg/util/dependents"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/client"
)
var (
// must use plural kinds
cephClusterDependentListKinds []string = []string{
"CephBlockPoolList",
"CephRBDMirrorList",
"CephFilesystemList",
"CephFilesystemMirrorList",
"CephObjectStoreList",
"CephObjectStoreUserList",
"CephObjectZoneList",
"CephObjectZoneGroupList",
"CephObjectRealmList",
"CephNFSList",
"CephClientList",
"CephBucketTopic",
"CephBucketNotification",
"CephFilesystemSubVolumeGroup",
}
)
// CephClusterDependents returns a DependentList of dependents of a CephCluster in the namespace.
func CephClusterDependents(c *clusterd.Context, namespace string) (*dependents.DependentList, error) {
ctx := context.TODO()
dependents := dependents.NewDependentList()
errs := []error{}
for _, listKind := range cephClusterDependentListKinds {
list := &unstructured.UnstructuredList{}
list.SetGroupVersionKind(schema.GroupVersionKind{
Group: cephv1.SchemeGroupVersion.Group,
Version: cephv1.SchemeGroupVersion.Version,
Kind: listKind,
})
err := c.Client.List(ctx, list, client.InNamespace(namespace))
if err != nil {
errs = append(errs, errors.Wrapf(err, "failed to get %s", listKind))
continue
}
if len(list.Items) > 0 {
for _, obj := range list.Items {
dependents.Add(listKindToSingularKind(listKind), obj.GetName())
}
}
}
// returns a nil error if there are no errors in the list
outErr := util.AggregateErrors(errs, "failed to list some dependents for CephCluster in namespace %q", namespace)
return dependents, outErr
}
func listKindToSingularKind(listKind string) string {
return strings.TrimSuffix(listKind, "List")
}