Skip to content

Commit

Permalink
promote ruleset manager interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Eikykun authored and shaofan-hs committed Aug 17, 2023
1 parent 9a75786 commit 2bba136
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 59 deletions.
10 changes: 2 additions & 8 deletions pkg/controllers/podopslifecycle/podopslifecycle_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,11 @@ func (r *ReconcilePodOpsLifecycle) addLabels(ctx context.Context, pod *corev1.Po
func (r *ReconcilePodOpsLifecycle) registerStages() {
r.ruleSetManager.RegisterStage(v1alpha1.PodOpsLifecyclePreCheckStage, func(po client.Object) bool {
labels := po.GetLabels()
if labels == nil {
return false
}
return labelHasPrefix(labels, v1alpha1.PodPreCheckLabelPrefix)
return labels == nil && labelHasPrefix(labels, v1alpha1.PodPreCheckLabelPrefix)
})
r.ruleSetManager.RegisterStage(v1alpha1.PodOpsLifecyclePostCheckStage, func(po client.Object) bool {
labels := po.GetLabels()
if labels == nil {
return false
}
return labelHasPrefix(labels, v1alpha1.PodPostCheckLabelPrefix)
return labels != nil && labelHasPrefix(labels, v1alpha1.PodPostCheckLabelPrefix)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,10 @@ type mockRuleSetManager struct {
*checker.CheckState
}

func (rsm *mockRuleSetManager) RegisterStage(key string, inStage func(obj client.Object) bool) error {
return nil
func (rsm *mockRuleSetManager) RegisterStage(key string, inStage func(obj client.Object) bool) {
}

func (rsm *mockRuleSetManager) RegisterCondition(opsCondition string, inCondition func(obj client.Object) bool) error {
return nil
func (rsm *mockRuleSetManager) RegisterCondition(opsCondition string, inCondition func(obj client.Object) bool) {
}

func (rsm *mockRuleSetManager) SetupRuleSetController(manager.Manager) error {
Expand Down
6 changes: 2 additions & 4 deletions pkg/controllers/ruleset/register/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,19 @@ type cache struct {
mu sync.Mutex
}

func (r *cache) RegisterStage(stage string, inStage func(obj client.Object) bool) error {
func (r *cache) RegisterStage(stage string, inStage func(obj client.Object) bool) {
r.mu.Lock()
defer r.mu.Unlock()
r.stages = append(r.stages, stage)
r.stageKey.Insert(stage)
r.inStageFunc.Add(stage, inStage)
return nil
}

func (r *cache) RegisterCondition(opsCondition string, inCondition func(obj client.Object) bool) error {
func (r *cache) RegisterCondition(opsCondition string, inCondition func(obj client.Object) bool) {
r.mu.Lock()
defer r.mu.Unlock()
r.conditionKey.Insert(opsCondition)
r.condition.Add(opsCondition, inCondition)
return nil
}

func (r *cache) Stage(obj client.Object) string {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/ruleset/register/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ type Policy interface {
}

type Register interface {
RegisterStage(key string, inStage func(obj client.Object) bool) error
RegisterCondition(opsCondition string, inCondition func(obj client.Object) bool) error
RegisterStage(key string, inStage func(obj client.Object) bool)
RegisterCondition(opsCondition string, inCondition func(obj client.Object) bool)
}
37 changes: 0 additions & 37 deletions pkg/controllers/ruleset/register/kind.go

This file was deleted.

8 changes: 4 additions & 4 deletions pkg/controllers/ruleset/ruleset_controller_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ type rsManager struct {
controller controller.Controller
}

func (m *rsManager) RegisterStage(key string, needCheck func(obj client.Object) bool) error {
return m.register.RegisterStage(key, needCheck)
func (m *rsManager) RegisterStage(key string, needCheck func(obj client.Object) bool) {
m.register.RegisterStage(key, needCheck)
}

func (m *rsManager) RegisterCondition(opsCondition string, inCondition func(obj client.Object) bool) error {
return m.register.RegisterCondition(opsCondition, inCondition)
func (m *rsManager) RegisterCondition(opsCondition string, inCondition func(obj client.Object) bool) {
m.register.RegisterCondition(opsCondition, inCondition)
}

func (m *rsManager) GetState(c client.Client, item client.Object) (checker.CheckState, error) {
Expand Down

0 comments on commit 2bba136

Please sign in to comment.