Skip to content

Commit

Permalink
Merge pull request #2838 from ezio-auditore/rm-healthchecker
Browse files Browse the repository at this point in the history
Remove healthchecker ceph client
  • Loading branch information
openshift-merge-bot[bot] authored Nov 11, 2024
2 parents bce1aa2 + a974162 commit ac1ecd0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 132 deletions.
68 changes: 3 additions & 65 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,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",
Expand Down Expand Up @@ -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",
Expand All @@ -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{
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
71 changes: 4 additions & 67 deletions controllers/storageconsumer/storageconsumer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand All @@ -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
}

0 comments on commit ac1ecd0

Please sign in to comment.