hooks: Add debug logging for initial hook loading

We've had logrus logging in the monitor code since it landed in
68eb128f (pkg/hooks: Version the hook structure and add 1.0.0 hooks,
2018-04-27, #686).  This commit adds similar logging to the initial
hook.New() and Manager.Hooks() calls to make it easier to see if those
are working as expected.

Signed-off-by: W. Trevor King <wking@tremily.us>

Closes: #887
Approved by: rhatdan
This commit is contained in:
W. Trevor King
2018-06-03 12:34:42 -07:00
committed by Atomic Bot
parent d5bedf42cf
commit 41a3f48f6d
2 changed files with 7 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import (
rspec "github.com/opencontainers/runtime-spec/specs-go" rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors" "github.com/pkg/errors"
current "github.com/projectatomic/libpod/pkg/hooks/1.0.0" current "github.com/projectatomic/libpod/pkg/hooks/1.0.0"
"github.com/sirupsen/logrus"
"golang.org/x/text/collate" "golang.org/x/text/collate"
"golang.org/x/text/language" "golang.org/x/text/language"
) )
@ -112,6 +113,7 @@ func (m *Manager) Hooks(config *rspec.Spec, annotations map[string]string, hasBi
return extensionStageHooks, errors.Wrapf(err, "matching hook %q", namedHook.name) return extensionStageHooks, errors.Wrapf(err, "matching hook %q", namedHook.name)
} }
if match { if match {
logrus.Debugf("hook %s matched; adding to stages %v", namedHook.name, namedHook.hook.Stages)
if config.Hooks == nil { if config.Hooks == nil {
config.Hooks = &rspec.Hooks{} config.Hooks = &rspec.Hooks{}
} }
@ -134,6 +136,8 @@ func (m *Manager) Hooks(config *rspec.Spec, annotations map[string]string, hasBi
} }
} }
} }
} else {
logrus.Debugf("hook %s did not match", namedHook.name)
} }
} }

View File

@ -11,6 +11,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
current "github.com/projectatomic/libpod/pkg/hooks/1.0.0" current "github.com/projectatomic/libpod/pkg/hooks/1.0.0"
"github.com/sirupsen/logrus"
) )
type reader func(content []byte) (*current.Hook, error) type reader func(content []byte) (*current.Hook, error)
@ -61,6 +62,7 @@ func read(content []byte) (hook *current.Hook, err error) {
// ReadDir reads hook JSON files from a directory into the given map, // ReadDir reads hook JSON files from a directory into the given map,
// clobbering any previous entries with the same filenames. // clobbering any previous entries with the same filenames.
func ReadDir(path string, extensionStages []string, hooks map[string]*current.Hook) error { func ReadDir(path string, extensionStages []string, hooks map[string]*current.Hook) error {
logrus.Debugf("reading hooks from %s", path)
files, err := ioutil.ReadDir(path) files, err := ioutil.ReadDir(path)
if err != nil { if err != nil {
return err return err
@ -81,6 +83,7 @@ func ReadDir(path string, extensionStages []string, hooks map[string]*current.Ho
return err return err
} }
hooks[file.Name()] = hook hooks[file.Name()] = hook
logrus.Debugf("added hook %s", filePath)
} }
return nil return nil
} }