diff --git a/apis/plugins/ContainerPlugin.go b/apis/plugins/ContainerPlugin.go index 722825fb6..728a41da0 100644 --- a/apis/plugins/ContainerPlugin.go +++ b/apis/plugins/ContainerPlugin.go @@ -1,12 +1,16 @@ package plugins -import "io" +import ( + "io" + + "github.com/alibaba/pouch/apis/types" +) // ContainerPlugin defines places where a plugin will be triggered in container lifecycle type ContainerPlugin interface { // PreCreate defines plugin point where receives a container create request, in this plugin point user // could change the container create body passed-in by http request body - PreCreate(io.ReadCloser) (io.ReadCloser, error) + PreCreate(*types.ContainerCreateConfig) error // PreStart returns an array of priority and args which will pass to runc, the every priority // used to sort the pre start array that pass to runc, network plugin hook always has priority value 0. diff --git a/apis/server/container_bridge.go b/apis/server/container_bridge.go index 53c8a5215..008512f07 100644 --- a/apis/server/container_bridge.go +++ b/apis/server/container_bridge.go @@ -31,13 +31,6 @@ func (s *Server) createContainer(ctx context.Context, rw http.ResponseWriter, re config := &types.ContainerCreateConfig{} reader := req.Body - var ex error - if s.ContainerPlugin != nil { - logrus.Infof("invoke container pre-create hook in plugin") - if reader, ex = s.ContainerPlugin.PreCreate(req.Body); ex != nil { - return errors.Wrapf(ex, "pre-create plugin point execute failed") - } - } // decode request body if err := json.NewDecoder(reader).Decode(config); err != nil { return httputils.NewHTTPError(err, http.StatusBadRequest) diff --git a/daemon/mgr/container.go b/daemon/mgr/container.go index f0fbcbaf0..9eebbe93b 100644 --- a/daemon/mgr/container.go +++ b/daemon/mgr/container.go @@ -268,6 +268,13 @@ func (mgr *ContainerManager) Restore(ctx context.Context) error { // Create checks passed in parameters and create a Container object whose status is set at Created. func (mgr *ContainerManager) Create(ctx context.Context, name string, config *types.ContainerCreateConfig) (resp *types.ContainerCreateResp, err error) { + if mgr.containerPlugin != nil { + logrus.Infof("invoke container pre-create hook in plugin") + if ex := mgr.containerPlugin.PreCreate(config); ex != nil { + return nil, errors.Wrapf(ex, "pre-create plugin point execute failed") + } + } + // cleanup allocated resources when failed cleanups := []func() error{} defer func() { diff --git a/daemon/mgr/spec_hook.go b/daemon/mgr/spec_hook.go index 681b1e49f..e55ab202a 100644 --- a/daemon/mgr/spec_hook.go +++ b/daemon/mgr/spec_hook.go @@ -6,9 +6,8 @@ import ( "sort" "strings" - "github.com/pkg/errors" - "github.com/opencontainers/runtime-spec/specs-go" + "github.com/pkg/errors" ) //setup hooks specified by user via plugins, if set rich mode and init-script exists set init-script