Skip to content
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

refactor: refact the pouch hook plugin #2360

Merged
merged 1 commit into from
Oct 31, 2018

Conversation

rudyfly
Copy link
Collaborator

@rudyfly rudyfly commented Oct 25, 2018

Ⅰ. Describe what this PR did

Refact the pouch hook plugin, add plugins code into binary when
building, instead of hook_plugin.so.

Add the Cri plugin.

More detail you can see: docs/features/pouch_with_plugin.md

Ⅱ. Does this pull request fix one issue?

NONE

Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)

NONE

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

Signed-off-by: Rudy Zhang [email protected]

@codecov
Copy link

codecov bot commented Oct 25, 2018

Codecov Report

Merging #2360 into master will increase coverage by 0.21%.
The diff coverage is 86.84%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2360      +/-   ##
=========================================
+ Coverage   68.29%   68.5%   +0.21%     
=========================================
  Files         265     275      +10     
  Lines       18211   18245      +34     
=========================================
+ Hits        12437   12499      +62     
+ Misses       4357    4324      -33     
- Partials     1417    1422       +5
Flag Coverage Δ
#criv1alpha1test 31.85% <61.84%> (+0.21%) ⬆️
#criv1alpha2test 35.71% <78.94%> (+0.2%) ⬆️
#integrationtest 39.83% <67.1%> (+0.27%) ⬆️
#nodee2etest 33.32% <80.26%> (+0.2%) ⬆️
#unittest 25.53% <0%> (+0.01%) ⬆️
Impacted Files Coverage Δ
storage/plugins/error.go 0% <ø> (ø)
storage/volume/driver/proxy.go 79.45% <ø> (ø) ⬆️
cri/v1alpha2/cri_types.go 100% <ø> (ø) ⬆️
storage/plugins/manager.go 78.72% <ø> (ø)
storage/plugins/client.go 60.49% <ø> (ø)
daemon/config/config.go 47.94% <ø> (ø) ⬆️
apis/server/server.go 58.69% <ø> (ø) ⬆️
storage/volume/driver/remote.go 68.96% <ø> (ø) ⬆️
storage/volume/driver/driver.go 68.03% <ø> (ø) ⬆️
storage/plugins/plugins.go 50% <ø> (ø)
... and 37 more

@@ -21,7 +21,7 @@ type DaemonProvider interface {
VolMgr() mgr.VolumeMgr
NetMgr() mgr.NetworkMgr
MetaStore() *meta.Store
ContainerPlugin() plugins.ContainerPlugin
ContainerPlugin() hookplugins.ContainerPlugin
Copy link
Contributor

Choose a reason for hiding this comment

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

The definition of DaemonProvider interface should also expose other 3 three plugin? Provide the access method to construct other components. WDYT @rudyfly

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe it is unnessary.

if err != nil {
return nil, err
}

// call cri plugin to update create config
if c.CriPlugin != nil {
if err := c.CriPlugin.PreCreateContainer(createConfig, sandboxMeta); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't you put this hook immediately before c.ContainerMgr.Create? The changes of plugin would be overwrote by other code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idae.

daemon/daemon.go Outdated
if err != nil {
return errors.Wrapf(err, "load plugin at %s error", d.config.PluginPath)
}
//load daemon plugin if exist
Copy link
Contributor

Choose a reason for hiding this comment

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

missing a space after two slash//

daemon/daemon.go Outdated
} else if s != nil {
return fmt.Errorf("not a daemon plugin at %s %q", d.config.PluginPath, s)
}
//load container plugin if exist
Copy link
Contributor

Choose a reason for hiding this comment

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

missing a space after two slash//

}
## Which plugins

Currently pouch provides four plugins,they are: `container plugin`,`daemon plugin`,`volume plugin`,`cri plugin`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Currently pouch provides four plugins,they are: `container plugin``daemon plugin``volume plugin``cri plugin`
Currently pouch-container provides four plugins,they are: `container plugin``daemon plugin``volume plugin``cri plugin`.

docs/features/pouch_with_plugin.md Outdated Show resolved Hide resolved
docs/features/pouch_with_plugin.md Outdated Show resolved Hide resolved

define two plugin symbols which only print some logs at correspond point:
* pre-volume-create volume point, at this point you can change the create volume's config as you want, add your default volume's options.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* pre-volume-create volume point, at this point you can change the create volume's config as you want, add your default volume's options.
* pre-volume-create volume point, at this point you can change the volume's create config as you want, add your default volume's options.


var ContainerPlugin ContPlugin
* pre-create-container cri container point, at this point you can update the container config what it will be created, such as update the container's envs or labels.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* pre-create-container cri container point, at this point you can update the container config what it will be created, such as update the container's envs or labels.
* pre-create-container cri point, at this point you can update the container config to what it will be created, such as update the container's envs or labels.

]
}
// PreStartHook copy config from /etc/pouch/config.json to /etc/sysconfig/pouch
// and start plugin processes than daemon depended
Copy link
Contributor

Choose a reason for hiding this comment

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

mismatched doc.

return nil
}

// PreStopHook stops plugin processes than start ed by PreStartHook.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// PreStopHook stops plugin processes than start ed by PreStartHook.
// PreStopHook stops plugin processes than started by PreStartHook.

hookplugins/daemonplugin/daemon_hook.go Outdated Show resolved Hide resolved
@rudyfly rudyfly force-pushed the master_plugin branch 3 times, most recently from 7e5c839 to d116b17 Compare October 29, 2018 09:05
@zhuangqh
Copy link
Contributor

This failure case is strange

FAIL: /home/travis/gopath/src/github.com/alibaba/pouch/test/cli_run_dns_test.go:55: PouchRunSuite.TestRunWithBridgeNetwork
/home/travis/gopath/src/github.com/alibaba/pouch/test/cli_run_dns_test.go:67:
    c.Assert(res.Stdout(), check.Equals, hostRes.Stdout())
... obtained string = "" +
...     "search c.eco-emissary-99515.internal google.internal\n" +
...     "nameserver 127.0.0.11\n" +
...     "options ndots:0\n"
... expected string = "" +
...     "# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)\n" +
...     "#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN\n" +
...     "nameserver 169.254.169.254\n" +
...     "search c.eco-emissary-99515.internal google.internal\n"

However, I can't find a button to restart this job.

@@ -683,6 +686,12 @@ func (c *CriManager) CreateContainer(ctx context.Context, r *runtime.CreateConta
sandboxConfig := r.GetSandboxConfig()
podSandboxID := r.GetPodSandboxId()

// get sandbox
sandbox, err := c.ContainerMgr.Get(ctx, podSandboxID)
Copy link
Collaborator

@allencloud allencloud Oct 30, 2018

Choose a reason for hiding this comment

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

Is this part of code related to the hookplugin? @rudyfly Just wish confirmation from you.

In addition, the codes added gets instance sandbox, but this sandbox is used in L741, about 50 lines of code away from here.

If you are not putting this code on purpose, I am wondering if we could locate the code just along with L741 to improve aggregation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I see you are constructing sandboxMeta for the hook plugin.

But also wish you could answer the second question.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have moved them together, PTAL.

@@ -1,148 +1,159 @@
# PouchContainer with plugin
# Pouch-container with plugin
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why to change the name of it?
I think the logo of this project is PouchContainer indeed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should pouchcontainer instead of pouch-container?

// PostUpdate called after update method successful,
// the method accepts the rootfs path and envs of container
PostUpdate(string, []string) error
} []()
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove []()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@rudyfly rudyfly force-pushed the master_plugin branch 2 times, most recently from 92c4014 to a40d852 Compare October 30, 2018 07:51
// CriPlugin defines places where a plugin will be triggered in CRI api lifecycle
type CriPlugin interface {
// PreCreateContainer defines plugin point where receives a container create request, in this plugin point user
// could the container's config in cri interface.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// could the container's config in cri interface.
// could update the container's config in cri interface.

or something else? :)

Refact the pouch hook plugin, add plugins code into binary when
building, instead of hook_plugin.so.

Add the Cri plugin.

More detail you can see: `docs/features/pouch_with_plugin.md`

Signed-off-by: Rudy Zhang <[email protected]>
@zhuangqh
Copy link
Contributor

LGTM

@zhuangqh zhuangqh merged commit 1ceb1e9 into AliyunContainerService:master Oct 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants