From a9741629e18e82fe2e78dcd54607ebb00c99ef3e Mon Sep 17 00:00:00 2001 From: Kaustav Majumder Date: Thu, 3 Oct 2024 18:53:11 +0530 Subject: [PATCH] Remove healthchecker ceph client Signed-off-by: Kaustav Majumder --- controllers/storageconsumer/consumer_test.go | 68 +----------------- .../storageconsumer_controller.go | 71 ++----------------- 2 files changed, 7 insertions(+), 132 deletions(-) diff --git a/controllers/storageconsumer/consumer_test.go b/controllers/storageconsumer/consumer_test.go index 0cdeb8310e..0a34c6485c 100644 --- a/controllers/storageconsumer/consumer_test.go +++ b/controllers/storageconsumer/consumer_test.go @@ -26,8 +26,6 @@ import ( routev1 "github.com/openshift/api/route/v1" v1 "github.com/red-hat-storage/ocs-operator/api/v4/v1" ocsv1alpha1 "github.com/red-hat-storage/ocs-operator/api/v4/v1alpha1" - "github.com/red-hat-storage/ocs-operator/v4/controllers/util" - rookCephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -49,10 +47,6 @@ func createFakeScheme(t *testing.T) *runtime.Scheme { assert.Fail(t, "failed to add ocsv1alpha1 scheme") } - err = rookCephv1.AddToScheme(scheme) - if err != nil { - assert.Fail(t, "failed to add rookCephv1 scheme") - } err = routev1.AddToScheme(scheme) if err != nil { assert.Fail(t, "failed to add routev1 scheme") @@ -69,19 +63,11 @@ func createFakeScheme(t *testing.T) *runtime.Scheme { return scheme } -func TestCephName(t *testing.T) { +func TestNoobaaAccount(t *testing.T) { var r StorageConsumerReconciler ctx := context.TODO() - r.cephClientHealthChecker = &rookCephv1.CephClient{ - ObjectMeta: metav1.ObjectMeta{ - Name: "healthchecker", - }, - Status: &rookCephv1.CephClientStatus{ - Phase: rookCephv1.ConditionType(util.PhaseReady), - }, - } scheme := createFakeScheme(t) - client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(r.cephClientHealthChecker).Build() + client := fake.NewClientBuilder().WithScheme(scheme).Build() r.Client = client r.Scheme = scheme r.Log = log.Log.WithName("controller_storagecluster_test") @@ -94,21 +80,6 @@ func TestCephName(t *testing.T) { }, Status: ocsv1alpha1.StorageConsumerStatus{ CephResources: []*ocsv1alpha1.CephResourcesSpec{ - { - Kind: "CephClient", - Name: "healthchecker", - Phase: "Ready", - }, - { - Kind: "CephClient", - Name: "rbd", - Phase: "Ready", - }, - { - Kind: "CephClient", - Name: "cephfs", - Phase: "Ready", - }, { Kind: "NooBaaAccount", Name: "consumer-acc", @@ -142,11 +113,6 @@ func TestCephName(t *testing.T) { assert.NoError(t, err) want := []*ocsv1alpha1.CephResourcesSpec{ - { - Kind: "CephClient", - Name: "healthchecker", - Phase: "Ready", - }, { Kind: "NooBaaAccount", Name: "consumer-acc", @@ -156,15 +122,7 @@ func TestCephName(t *testing.T) { assert.Equal(t, r.storageConsumer.Status.CephResources, want) // When StorageConsumer cr status in Error state - r.cephClientHealthChecker = &rookCephv1.CephClient{ - ObjectMeta: metav1.ObjectMeta{ - Name: "healthchecker", - }, - Status: &rookCephv1.CephClientStatus{ - Phase: rookCephv1.ConditionType(util.PhaseError), - }, - } - client = fake.NewClientBuilder().WithScheme(scheme).WithObjects(r.cephClientHealthChecker).Build() + client = fake.NewClientBuilder().WithScheme(scheme).Build() r.Client = client r.storageConsumer = &ocsv1alpha1.StorageConsumer{ @@ -176,21 +134,6 @@ func TestCephName(t *testing.T) { }, Status: ocsv1alpha1.StorageConsumerStatus{ CephResources: []*ocsv1alpha1.CephResourcesSpec{ - { - Kind: "CephClient", - Name: "rbd", - Phase: "Error", - }, - { - Kind: "CephClient", - Name: "cephfs", - Phase: "Ready", - }, - { - Kind: "CephClient", - Name: "healthchecker", - Phase: "Error", - }, { Kind: "NooBaaAccount", Name: "consumer-acc", @@ -221,11 +164,6 @@ func TestCephName(t *testing.T) { assert.NoError(t, err) want = []*ocsv1alpha1.CephResourcesSpec{ - { - Kind: "CephClient", - Name: "healthchecker", - Phase: "Error", - }, { Kind: "NooBaaAccount", Name: "consumer-acc", diff --git a/controllers/storageconsumer/storageconsumer_controller.go b/controllers/storageconsumer/storageconsumer_controller.go index 2a4535a2c2..53be0e8c4e 100644 --- a/controllers/storageconsumer/storageconsumer_controller.go +++ b/controllers/storageconsumer/storageconsumer_controller.go @@ -59,15 +59,13 @@ type StorageConsumerReconciler struct { Log logr.Logger Scheme *runtime.Scheme - ctx context.Context - storageConsumer *ocsv1alpha1.StorageConsumer - cephClientHealthChecker *rookCephv1.CephClient - namespace string - noobaaAccount *nbv1.NooBaaAccount + ctx context.Context + storageConsumer *ocsv1alpha1.StorageConsumer + namespace string + noobaaAccount *nbv1.NooBaaAccount } //+kubebuilder:rbac:groups=ocs.openshift.io,resources=storageconsumers,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=ceph.rook.io,resources=cephclients,verbs=get;list;watch;create;update;delete //+kubebuilder:rbac:groups=ocs.openshift.io,resources=storageconsumers/status,verbs=get;update;patch // +kubebuilder:rbac:groups=ocs.openshift.io,resources=storagerequests,verbs=get;list; // +kubebuilder:rbac:groups=noobaa.io,resources=noobaaaccounts,verbs=get;list;watch;create;update;delete @@ -130,10 +128,6 @@ func (r *StorageConsumerReconciler) initReconciler(request reconcile.Request) { r.storageConsumer.Name = request.Name r.storageConsumer.Namespace = r.namespace - r.cephClientHealthChecker = &rookCephv1.CephClient{} - r.cephClientHealthChecker.Name = GenerateHashForCephClient(r.storageConsumer.Name, "global") - r.cephClientHealthChecker.Namespace = r.namespace - r.noobaaAccount = &nbv1.NooBaaAccount{} r.noobaaAccount.Name = r.storageConsumer.Name r.noobaaAccount.Namespace = r.storageConsumer.Namespace @@ -151,9 +145,6 @@ func (r *StorageConsumerReconciler) reconcilePhases() (reconcile.Result, error) if r.storageConsumer.GetDeletionTimestamp().IsZero() { - if err := r.reconcileCephClientHealthChecker(); err != nil { - return reconcile.Result{}, err - } // A provider cluster already has a NooBaa system and does not require a NooBaa account // to connect to a remote cluster, unlike client clusters. // A NooBaa account only needs to be created if the storage consumer is for a client cluster. @@ -183,47 +174,6 @@ func (r *StorageConsumerReconciler) reconcilePhases() (reconcile.Result, error) return reconcile.Result{}, nil } -func (r *StorageConsumerReconciler) reconcileCephClientHealthChecker() error { - - desired := &rookCephv1.CephClient{ - Spec: rookCephv1.ClientSpec{ - Caps: map[string]string{ - "mgr": "allow command config", - "mon": "allow r, allow command quorum_status, allow command version", - }, - }, - } - - _, err := ctrl.CreateOrUpdate(r.ctx, r.Client, r.cephClientHealthChecker, func() error { - if err := r.own(r.cephClientHealthChecker); err != nil { - return err - } - - addStorageRelatedAnnotations(r.cephClientHealthChecker, r.storageConsumer.Name, "global", "healthchecker") - r.cephClientHealthChecker.Spec = desired.Spec - return nil - }) - - if err != nil { - r.Log.Error( - err, - "Failed to update CephClient.", - "CephClient", - klog.KRef(r.cephClientHealthChecker.Namespace, r.cephClientHealthChecker.Name), - ) - return err - } - - phase := "" - if r.cephClientHealthChecker.Status != nil { - phase = string(r.cephClientHealthChecker.Status.Phase) - } - - r.setCephResourceStatus(r.cephClientHealthChecker.Name, "CephClient", phase, nil) - - return nil -} - func (r *StorageConsumerReconciler) reconcileNoobaaAccount() error { _, err := ctrl.CreateOrUpdate(r.ctx, r.Client, r.noobaaAccount, func() error { if err := r.own(r.noobaaAccount); err != nil { @@ -289,7 +239,6 @@ func (r *StorageConsumerReconciler) SetupWithManager(mgr ctrl.Manager) error { For(&ocsv1alpha1.StorageConsumer{}, builder.WithPredicates( predicate.GenerationChangedPredicate{}, )). - Owns(&rookCephv1.CephClient{}). Owns(&nbv1.NooBaaAccount{}). // Watch non-owned resources cephBlockPool // Whenever their is new cephBockPool created to keep storageConsumer up to date. @@ -316,15 +265,3 @@ func GenerateHashForCephClient(storageConsumerName, cephUserType string) string name := md5.Sum([]byte(cephClient)) return hex.EncodeToString(name[:16]) } - -func addStorageRelatedAnnotations(obj client.Object, storageConsumerName, storageRequest, cephUserType string) { - annotations := obj.GetAnnotations() - if annotations == nil { - annotations = map[string]string{} - obj.SetAnnotations(annotations) - } - - annotations[StorageConsumerAnnotation] = storageConsumerName - annotations[StorageRequestAnnotation] = storageRequest - annotations[StorageCephUserTypeAnnotation] = cephUserType -}