Skip to content

Commit

Permalink
++ IsSynchronization method
Browse files Browse the repository at this point in the history
  • Loading branch information
diafour committed Mar 17, 2021
1 parent 755abac commit 422f4cf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.12
require (
github.com/davecgh/go-spew v1.1.1
github.com/evanphx/json-patch v4.9.0+incompatible
github.com/flant/shell-operator v1.0.0-rc.2.0.20210312082814-474da3366f0c // branch: master
github.com/flant/shell-operator v1.0.0-rc.2.0.20210317131220-020ac6f87d1b // branch: fix_fresh_objects_on_synchronization_retries
github.com/go-chi/chi v4.0.3+incompatible
github.com/go-openapi/spec v0.19.3
github.com/go-openapi/strfmt v0.19.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ github.com/flant/shell-operator v1.0.0-rc.2.0.20210309133328-81e5d893a769 h1:ujR
github.com/flant/shell-operator v1.0.0-rc.2.0.20210309133328-81e5d893a769/go.mod h1:RHkdgTcyRh/B3imV4O13xH7rmDazd6V5RZ8E3hVq8BM=
github.com/flant/shell-operator v1.0.0-rc.2.0.20210312082814-474da3366f0c h1:Lhvvm3fe4mfzyDvubxAw6oyD8dwzgIlDnPh74Dwsbbs=
github.com/flant/shell-operator v1.0.0-rc.2.0.20210312082814-474da3366f0c/go.mod h1:RHkdgTcyRh/B3imV4O13xH7rmDazd6V5RZ8E3hVq8BM=
github.com/flant/shell-operator v1.0.0-rc.2.0.20210317131220-020ac6f87d1b h1:cCE0eSoYLTSMDLU37M9JpmU9THomBqsHP+mKIf+e1LM=
github.com/flant/shell-operator v1.0.0-rc.2.0.20210317131220-020ac6f87d1b/go.mod h1:RHkdgTcyRh/B3imV4O13xH7rmDazd6V5RZ8E3hVq8BM=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand Down
10 changes: 3 additions & 7 deletions pkg/addon-operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,11 +851,7 @@ func (op *AddonOperator) TaskHandler(t sh_task.Task) queue.TaskResult {
t.WithQueuedAt(time.Now())
res.Status = "Repeat"
} else {
taskLogEntry.Infof("Global hooks enable kubernetes events")
//op.ModuleManager.GlobalEnableKubernetesEvents()
//hm := task.HookMetadataAccessor(t)
//globalHook := op.ModuleManager.GetGlobalHook(hm.HookName)
//globalHook.HookController.EnableKubernetesEvents()
taskLogEntry.Infof("Global 'Synchronization' is done")
}

case task.ReloadAllModules:
Expand Down Expand Up @@ -1300,7 +1296,7 @@ func (op *AddonOperator) HandleModuleHookRun(t sh_task.Task, labels map[string]s
op.MetricStorage.HistogramObserve("{PREFIX}module_hook_run_seconds", d.Seconds(), metricLabels)
})()

isSynchronization := hm.BindingType == OnKubernetesEvent && hm.BindingContext[0].Type == types.TypeSynchronization
isSynchronization := hm.IsSynchronization()
shouldRunHook := true
if isSynchronization {
// There were no Synchronization for v0 hooks, skip hook execution.
Expand Down Expand Up @@ -1453,7 +1449,7 @@ func (op *AddonOperator) HandleGlobalHookRun(t sh_task.Task, labels map[string]s
op.MetricStorage.HistogramObserve("{PREFIX}global_hook_run_seconds", d.Seconds(), metricLabels)
})()

isSynchronization := hm.BindingType == OnKubernetesEvent && hm.BindingContext[0].Type == types.TypeSynchronization
isSynchronization := hm.IsSynchronization()
shouldRunHook := true
if isSynchronization {
// There were no Synchronization for v0 hooks, skip hook execution.
Expand Down
6 changes: 5 additions & 1 deletion pkg/task/hook_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/flant/shell-operator/pkg/task"
)

// HookMetadata is metadata for addon-operator tasks
// HookMetadata is a metadata for addon-operator tasks
type HookMetadata struct {
EventDescription string // event name for informative queue dump
HookName string
Expand Down Expand Up @@ -92,3 +92,7 @@ func (hm HookMetadata) GetBindingContext() []BindingContext {
func (hm HookMetadata) GetMonitorIDs() []string {
return hm.MonitorIDs
}

func (hm HookMetadata) IsSynchronization() bool {
return len(hm.BindingContext) > 0 && hm.BindingContext[0].IsSynchronization()
}

0 comments on commit 422f4cf

Please sign in to comment.