Skip to content

Commit

Permalink
Remove healthchecker ceph client
Browse files Browse the repository at this point in the history
Signed-off-by: Kaustav Majumder <[email protected]>
  • Loading branch information
Kaustav Majumder committed Oct 3, 2024
1 parent f80f43b commit c73917f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 111 deletions.
50 changes: 4 additions & 46 deletions controllers/storageconsumer/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -94,11 +80,6 @@ func TestCephName(t *testing.T) {
},
Status: ocsv1alpha1.StorageConsumerStatus{
CephResources: []*ocsv1alpha1.CephResourcesSpec{
{
Kind: "CephClient",
Name: "healthchecker",
Phase: "Ready",
},
{
Kind: "CephClient",
Name: "rbd",
Expand Down Expand Up @@ -142,11 +123,6 @@ func TestCephName(t *testing.T) {
assert.NoError(t, err)

want := []*ocsv1alpha1.CephResourcesSpec{
{
Kind: "CephClient",
Name: "healthchecker",
Phase: "Ready",
},
{
Kind: "NooBaaAccount",
Name: "consumer-acc",
Expand All @@ -156,15 +132,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{
Expand All @@ -179,18 +147,13 @@ func TestCephName(t *testing.T) {
{
Kind: "CephClient",
Name: "rbd",
Phase: "Error",
Phase: "Ready",
},
{
Kind: "CephClient",
Name: "cephfs",
Phase: "Ready",
},
{
Kind: "CephClient",
Name: "healthchecker",
Phase: "Error",
},
{
Kind: "NooBaaAccount",
Name: "consumer-acc",
Expand Down Expand Up @@ -221,11 +184,6 @@ func TestCephName(t *testing.T) {
assert.NoError(t, err)

want = []*ocsv1alpha1.CephResourcesSpec{
{
Kind: "CephClient",
Name: "healthchecker",
Phase: "Error",
},
{
Kind: "NooBaaAccount",
Name: "consumer-acc",
Expand Down
69 changes: 4 additions & 65 deletions controllers/storageconsumer/storageconsumer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ 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
Expand Down Expand Up @@ -130,10 +129,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
Expand All @@ -151,9 +146,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.
Expand Down Expand Up @@ -183,47 +175,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 {
Expand Down Expand Up @@ -316,15 +267,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
}

0 comments on commit c73917f

Please sign in to comment.