Skip to content
This repository has been archived by the owner on Apr 17, 2024. It is now read-only.

Commit

Permalink
feat: add basic scrubbing schedule recommender module
Browse files Browse the repository at this point in the history
Started work on the k8s resources module as well.

Signed-off-by: Alexander Trost <galexrt@googlemail.com>
  • Loading branch information
galexrt committed Feb 9, 2024
1 parent 14c56a9 commit 67ed4d9
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 1 deletion.
73 changes: 73 additions & 0 deletions pkg/recommender/modules/k8s_resources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package recommendermodules

import (
"context"

cephv1 "github.com/koor-tech/data-control-center/gen/go/api/resources/ceph/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var k8sResourcesClusterResMustHave = []string{
"mon",
"mgr",
"osd",
"mds",
"rgw",
}

func init() {
moduleFactories["k8s_resources"] = NewK8SResources
}

func NewK8SResources() (Module, error) {
return &K8SResources{}, nil
}

type K8SResources struct {
Module
}

func (m *K8SResources) GetName() string {
return "k8s_resources"
}

func (m *K8SResources) Run(ctx context.Context, p *Params) ([]*cephv1.ClusterRecommendation, error) {
recs := []*cephv1.ClusterRecommendation{}

clusters, err := p.K8S.GetRookClient().CephV1().CephClusters(p.Namespace).List(ctx, v1.ListOptions{})
if err != nil {
return nil, err
}
for _, item := range clusters.Items {
// TODO check against k8sResourcesClusterResMustHave
_ = item
}

fses, err := p.K8S.GetRookClient().CephV1().CephFilesystems(p.Namespace).List(ctx, v1.ListOptions{})
if err != nil {
return nil, err
}
for _, item := range fses.Items {
_ = item
}

rgws, err := p.K8S.GetRookClient().CephV1().CephObjectStores(p.Namespace).List(ctx, v1.ListOptions{})
if err != nil {
return nil, err
}
for _, item := range rgws.Items {
_ = item
}

nfses, err := p.K8S.GetRookClient().CephV1().CephNFSes(p.Namespace).List(ctx, v1.ListOptions{})
if err != nil {
return nil, err
}
for _, item := range nfses.Items {
_ = item
}

// TODO check CephFilesystems, CephObjectStores, and CephNFSes

return recs, nil
}
2 changes: 1 addition & 1 deletion pkg/recommender/modules/pool_sizes.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (m *PoolSizes) checkPool(name string, pSpec rookcephv1.PoolSpec) []*cephv1.
})
}
}
// TODO check sizes for a hybrid storage pool
// TODO check sizes for hybrid storage pools

return recs
}
71 changes: 71 additions & 0 deletions pkg/recommender/modules/scrubbing_schedule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package recommendermodules

import (
"context"
"slices"

cephv1 "github.com/koor-tech/data-control-center/gen/go/api/resources/ceph/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var scrubbingScheduleMinimumConfigOptions = []string{
"osd_scrub_begin_hour",
"osd_scrub_end_hour",
"osd_scrub_begin_week_day",
"osd_scrub_end_week_day",
}

func init() {
moduleFactories["scrubbing_schedule"] = NewScrubbingSchedule
}

func NewScrubbingSchedule() (Module, error) {
return &ScrubbingSchedule{}, nil
}

type ScrubbingSchedule struct {
Module
}

func (m *ScrubbingSchedule) GetName() string {
return "scrubbing_schedule"
}

func (m *ScrubbingSchedule) Run(ctx context.Context, p *Params) ([]*cephv1.ClusterRecommendation, error) {
recs := []*cephv1.ClusterRecommendation{}

clusters, err := p.K8S.GetRookClient().CephV1().CephClusters(p.Namespace).List(ctx, v1.ListOptions{})
if err != nil {
return nil, err
}
for _, item := range clusters.Items {
if cfg, ok := item.Spec.CephConfig["global"]; ok {
// Collect the set global config options so we can check if a scrubbing schedule is set
configOpts := []string{}
for opt := range cfg {
configOpts = append(configOpts, opt)
}

found := true
for _, opt := range scrubbingScheduleMinimumConfigOptions {
if !slices.Contains(configOpts, opt) {
found = false
break
}
}

if found {
break
}
}

recs = append(recs, &cephv1.ClusterRecommendation{
Title: "No Custom Scrubbing Schedule set",
Description: "It is recommended to set up a custom OSD scrubbing schedule to ensure the cluster will scrub during off hours.",
Level: cephv1.RecommendationLevel_RECOMMENDATION_LEVEL_INFORMAL,
Type: cephv1.RecommendationType_RECOMMENDATION_TYPE_OSD,
})
}

return recs, nil
}

0 comments on commit 67ed4d9

Please sign in to comment.