forked from rook/rook
ceph: convert the CephCluster controller to the controller-runtime
This is the final conversion to controller-runtime conversion. This time the CephCluster CRD has been converted to use the controller-runtime library. The controller incorporates all the previous watchers too, so the Node and hot-plug configmap are been watched too. Only the operator setting configmap is not being watcher since it's not related to the CephCluster CRD. Not only the patch converts to controller-runtime but also tries to re-organize the tree of the repo to actually make the code more readable and have better functions/methods/tests separations. Closes: https://github.com/rook/rook/issues/4939 Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
@@ -18,12 +18,16 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
||||
"github.com/rook/rook/pkg/clusterd"
|
||||
cephclient "github.com/rook/rook/pkg/daemon/ceph/client"
|
||||
"github.com/rook/rook/pkg/operator/k8sutil"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
@@ -86,3 +90,25 @@ func IsReadyToReconcile(c client.Client, clustercontext *clusterd.Context, names
|
||||
logger.Infof("%s: CephCluster %q found but skipping reconcile since Ceph health is %q", controllerName, cephCluster.Name, status.Health.Status)
|
||||
return cephCluster.Spec, false, cephClusterExists, WaitForRequeueIfCephClusterNotReady
|
||||
}
|
||||
|
||||
// ClusterOwnerRef represents the owner reference of the CephCluster CR
|
||||
func ClusterOwnerRef(clusterName, clusterID string) metav1.OwnerReference {
|
||||
blockOwner := true
|
||||
return metav1.OwnerReference{
|
||||
APIVersion: fmt.Sprintf("%s/%s", ClusterResource.Group, ClusterResource.Version),
|
||||
Kind: ClusterResource.Kind,
|
||||
Name: clusterName,
|
||||
UID: types.UID(clusterID),
|
||||
BlockOwnerDeletion: &blockOwner,
|
||||
}
|
||||
}
|
||||
|
||||
// ClusterResource operator-kit Custom Resource Definition
|
||||
var ClusterResource = k8sutil.CustomResource{
|
||||
Name: "cephcluster",
|
||||
Plural: "cephclusters",
|
||||
Group: cephv1.CustomResourceGroup,
|
||||
Version: cephv1.Version,
|
||||
Kind: reflect.TypeOf(cephv1.CephCluster{}).Name(),
|
||||
APIVersion: fmt.Sprintf("%s/%s", cephv1.CustomResourceGroup, cephv1.Version),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user