Skip to content

Commit

Permalink
remove Dump()
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Scherba <mikhail.scherba@flant.com>
  • Loading branch information
miklezzzz committed Jun 6, 2024
1 parent 3e29717 commit e2c0c21
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 82 deletions.
25 changes: 5 additions & 20 deletions pkg/module_manager/module_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,27 +791,20 @@ func (mm *ModuleManager) applyEnabledPatch(enabledPatch utils.ValuesPatch, exten
modName := strings.TrimSuffix(op.Path, "Enabled")
modName = strings.TrimPrefix(modName, "/")
modName = utils.ModuleNameFromValuesKey(modName)

var (
v *bool
err error
)

v, err := utils.ModuleEnabledValue(op.Value)
if err != nil {
return fmt.Errorf("apply enabled patch operation '%s' for %s: %v", op.Op, op.Path, err)
}
switch op.Op {
case "add":
v, err = utils.ModuleEnabledValue(op.Value)
if err != nil {
return fmt.Errorf("apply enabled patch operation '%s' for %s: %v", op.Op, op.Path, err)
}
log.Debugf("apply dynamic enable: module %s set to '%v'", modName, *v)
case "remove":
log.Debugf("apply dynamic enable: module %s removed from dynamic enable", modName)
}
extender.UpdateStatus(modName, op.Op, *v)
log.Infof("dynamically enabled module status change: module %s, operation %s, state *v", modName, op.Op, *v)

Check failure on line 805 in pkg/module_manager/module_manager.go

View workflow job for this annotation

GitHub Actions / Run unit tests

github.com/sirupsen/logrus.Infof call needs 2 args but has 3 args

Check failure on line 805 in pkg/module_manager/module_manager.go

View workflow job for this annotation

GitHub Actions / Run Go linters

printf: github.com/sirupsen/logrus.Infof call needs 2 args but has 3 args (govet)
}

log.Infof("dynamic enabled modules list after patch: %s", mm.DumpDynamicEnabled())

return nil
}

Expand All @@ -820,14 +813,6 @@ func (mm *ModuleManager) UpdateGraphState() (bool, error) {
return mm.moduleScheduler.UpdateGraphState()
}

func (mm *ModuleManager) DumpDynamicEnabled() string {
dump := "["
for k, v := range mm.moduleScheduler.DumpExtender(dynamic_extender.Name) {
dump += fmt.Sprintf("%s(%t), ", k, v)
}
return dump + "]"
}

// GlobalSynchronizationNeeded is true if there is at least one global
// kubernetes hook with executeHookOnSynchronization.
func (mm *ModuleManager) GlobalSynchronizationNeeded() bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ func NewExtender() *Extender {
return e
}

func (e *Extender) Dump() map[string]bool {
e.l.Lock()
defer e.l.Unlock()
return e.modulesStatus
}

func (e *Extender) UpdateStatus(moduleName, operation string, value bool) {
e.l.Lock()
switch operation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,62 @@ import (
"github.com/stretchr/testify/assert"

"github.com/flant/addon-operator/pkg/module_manager/scheduler/extenders"
"github.com/flant/addon-operator/pkg/module_manager/scheduler/node"
)

func TestUpdateStatus(t *testing.T) {
de := NewExtender()
ch := make(chan extenders.ExtenderEvent)
de.SetNotifyChannel(context.TODO(), ch)
var boolNilP *bool

go func() {
//nolint:revive
for range ch {
}
}()

l2BalancerModule := node.ModuleMock{
Name: "l2-load-balancer",
Order: 1,
}
dnsModule := node.ModuleMock{
Name: "node-local-dns",
Order: 2,
}
openstackCPModule := node.ModuleMock{
Name: "openstack-cloud-provider",
Order: 3,
}

de.UpdateStatus("l2-load-balancer", "add", true)
de.UpdateStatus("node-local-dns", "remove", true)
de.UpdateStatus("openstack-cloud-provider", "add", true)
de.UpdateStatus("openstack-cloud-provider", "add", false)

status := de.Dump()

expectedStatus := map[string]bool{
"l2-load-balancer": true,
"openstack-cloud-provider": false,
}

assert.Equal(t, expectedStatus, status)
filterResult, _ := de.Filter(l2BalancerModule)
assert.Equal(t, true, *filterResult)
filterResult, _ = de.Filter(dnsModule)
assert.Equal(t, boolNilP, filterResult)
filterResult, _ = de.Filter(openstackCPModule)
assert.Equal(t, false, *filterResult)

de.UpdateStatus("node-local-dns", "add", false)
de.UpdateStatus("openstack-cloud-provider", "add", true)

status = de.Dump()

expectedStatus = map[string]bool{
"l2-load-balancer": true,
"openstack-cloud-provider": true,
"node-local-dns": false,
}

assert.Equal(t, expectedStatus, status)
filterResult, _ = de.Filter(l2BalancerModule)
assert.Equal(t, true, *filterResult)
filterResult, _ = de.Filter(dnsModule)
assert.Equal(t, false, *filterResult)
filterResult, _ = de.Filter(openstackCPModule)
assert.Equal(t, true, *filterResult)

de.UpdateStatus("l2-load-balancer", "remove", true)

status = de.Dump()

expectedStatus = map[string]bool{
"openstack-cloud-provider": true,
"node-local-dns": false,
}

assert.Equal(t, expectedStatus, status)
filterResult, _ = de.Filter(l2BalancerModule)
assert.Equal(t, boolNilP, filterResult)
filterResult, _ = de.Filter(dnsModule)
assert.Equal(t, false, *filterResult)
filterResult, _ = de.Filter(openstackCPModule)
assert.Equal(t, true, *filterResult)
}
2 changes: 0 additions & 2 deletions pkg/module_manager/scheduler/extenders/extenders.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ type Extender interface {
Name() ExtenderName
// Filter returns the result of applying the extender
Filter(module node.ModuleInterface) (*bool, error)
// Dump returns the extender's status of all modules
Dump() map[string]bool

// not implemented
Order()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ func NewExtender(kcm kubeConfigManager) *Extender {
return e
}

func (e Extender) Dump() map[string]bool {
return nil
}

func (e Extender) Name() extenders.ExtenderName {
return Name
}
Expand Down
10 changes: 0 additions & 10 deletions pkg/module_manager/scheduler/extenders/script_enabled/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ func NewExtender(tmpDir string) (*Extender, error) {
return e, nil
}

func (e *Extender) Dump() map[string]bool {
status := make(map[string]bool, 0)
e.l.Lock()
for i := range e.enabledModules {
status[e.enabledModules[i]] = true
}
e.l.Unlock()
return status
}

func (e *Extender) Name() extenders.ExtenderName {
return Name
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/module_manager/scheduler/extenders/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ func NewExtender(staticValuesFilePaths string) (*Extender, error) {
return e, nil
}

func (e Extender) Dump() map[string]bool {
return e.modulesStatus
}

func (e Extender) Name() extenders.ExtenderName {
return Name
}
Expand Down
11 changes: 0 additions & 11 deletions pkg/module_manager/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,3 @@ func (s *Scheduler) GleanGraphDiff() map[string]bool {
s.l.Unlock()
return diff
}

// DumpExtender returns current state of the extender (its meta), if possible
func (s *Scheduler) DumpExtender(name extenders.ExtenderName) map[string]bool {
for _, ex := range s.extenders {
if ex.Name() == name {
return ex.Dump()
}
}

return nil
}

0 comments on commit e2c0c21

Please sign in to comment.