-
Notifications
You must be signed in to change notification settings - Fork 950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: add plugin framework #919
Merged
allencloud
merged 1 commit into
AliyunContainerService:master
from
yyb196:feature-plugin
Mar 20, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package plugins | ||
|
||
import "io" | ||
|
||
// ContainerPlugin defines in which place a plugin will be triggered in container lifecycle | ||
type ContainerPlugin interface { | ||
// PreCreate defines plugin point where recevives an 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) | ||
|
||
// 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. | ||
PreStart(interface{}) ([]int, [][]string, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package plugins | ||
|
||
// DaemonPlugin defines in which place does pouch daemon support plugin | ||
type DaemonPlugin interface { | ||
// PreStartHook is invoked by pouch daemon before real start, in this hook user could start dfget proxy or other | ||
// standalone process plugins | ||
PreStartHook() error | ||
|
||
// PreStopHook is invoked by pouch daemon before daemon process exit, not a promise if daemon is killed, in this | ||
// hook user could stop the process or plugin started by PreStartHook | ||
PreStopHook() error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ import ( | |
|
||
"github.com/go-openapi/strfmt" | ||
"github.com/gorilla/mux" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func (s *Server) removeContainers(ctx context.Context, rw http.ResponseWriter, req *http.Request) error { | ||
|
@@ -114,8 +116,16 @@ func (s *Server) startContainerExec(ctx context.Context, rw http.ResponseWriter, | |
|
||
func (s *Server) createContainer(ctx context.Context, rw http.ResponseWriter, req *http.Request) error { | ||
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 piont execute failed") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/piont/point There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these typo will be fixed in #929 |
||
} | ||
} | ||
// decode request body | ||
if err := json.NewDecoder(req.Body).Decode(config); err != nil { | ||
if err := json.NewDecoder(reader).Decode(config); err != nil { | ||
return httputils.NewHTTPError(err, http.StatusBadRequest) | ||
} | ||
// validate request body | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/recevives/receives