Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apis/plugins/ContainerPlugin.go
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interface signature and return value are all different from origin, some files missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xiaoxubeii You are right...


// 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.
Expand Down
7 changes: 0 additions & 7 deletions apis/server/container_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 1 addition & 2 deletions daemon/mgr/spec_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down