-
Notifications
You must be signed in to change notification settings - Fork 949
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 pouch plugin #1278
feature: add pouch plugin #1278
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1278 +/- ##
==========================================
+ Coverage 15.31% 16.29% +0.97%
==========================================
Files 174 178 +4
Lines 11014 10994 -20
==========================================
+ Hits 1687 1791 +104
+ Misses 9208 9065 -143
- Partials 119 138 +19
|
plugins/plugin.go
Outdated
) | ||
|
||
// TLSConfig contains information of tls which users can specify | ||
type TLSConfig struct { |
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.
I think we have already defined a TLSConfig in the code base package client
. I am wondering if we could avoid the duplication.
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.
plugins.TLSConfig is different from client.TLSConfig
plugins/client.go
Outdated
// defaultContentTypeis the default content type accepted and sent by the plugins. | ||
const defaultContentType = "application/vnd.docker.plugins.v1.1+json" | ||
|
||
// PluginClient the client which call Plugin ServiceMethod |
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.
Please add every a .
in every function's comments.
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.
Get it
plugins/client.go
Outdated
|
||
u, err := url.Parse(addr) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse plugin addr: %s", addr) |
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.
fmt.Errorf("failed to parse plugin addr %s: %v", addr, err)
?
plugins/client.go
Outdated
if tlsconfig != nil && tlsconfig.InsecureSkipVerify == false { | ||
config, err = client.GenTLSConfig(tlsconfig.KeyFile, tlsconfig.CertFile, tlsconfig.CAFile) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse plugin tls config") |
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.
please throw out the error. I think that will make the error message more explicit.
plugins/client.go
Outdated
return nil, err | ||
} | ||
|
||
if resp.StatusCode != http.StatusOK { |
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.
Does only 200 make sense?
In my opinion, 2xx and 3xx are both regarded valid.
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.
It seems that the resp
should be handled out of this function. 101
/ 20x
/ 30x
are the OK.
plugins/client.go
Outdated
return nil, err | ||
} | ||
counter++ | ||
logrus.Warnf("plugin %s call %s failed, retry after %d seconds", cli.address, service, delay) |
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.
throw out the error in the log message?
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.
it's an warning msg.
plugins/client.go
Outdated
|
||
resp, err := cli.client.Do(req) | ||
if err != nil { | ||
if retry { |
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.
I would suggest that we could use return fast
to reduce more ident, like:
if !retry {
return nil, err
}
delay := backoff(counter)
if timeout(start, delay) {
return nil, err
}
......
plugins/client.go
Outdated
"github.com/sirupsen/logrus" | ||
) | ||
|
||
var defaultTimeout = 30 |
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.
How about make this type of time.Duration
instead of a type of int
?
plugins/error.go
Outdated
var ErrNotFound = errors.New("plugin not found") | ||
|
||
// ErrNotImplement represents that the plugin not implement the given protocol | ||
var ErrNotImplement = errors.New("plugin not implement") |
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/NotImplement/NotImplemented ?
for { | ||
plugin, err := m.newPlugin(name) | ||
if err != nil { | ||
if retry { |
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.
We can use return fast
here.
plugins/manager.go
Outdated
} | ||
|
||
for _, path := range specPaths { | ||
fi, err := os.Open(path) |
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.
I think we should close this fi
when finishing dealing.
Thank @shaloulcy for your work.
also cc @fuweid |
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.
@allencloud , In my option, most functions has been covered in pkg client
.
I think we can upgrade the pkg client
instead of new pkg plugin
.
plugins/client.go
Outdated
return nil, err | ||
} | ||
|
||
if resp.StatusCode != http.StatusOK { |
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.
It seems that the resp
should be handled out of this function. 101
/ 20x
/ 30x
are the OK.
789b5c2
to
4dcd71b
Compare
plugins/manager.go
Outdated
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// pluginManager is a pluginManager, which manages all plugin events. |
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.
pluginManager is a plugin manager
is it better?
plugins/manager.go
Outdated
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// pluginManager is a pluginManager, which manages all plugin events. |
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.
pluginManager is a plugin manager
is it better?
plugins/plugins.go
Outdated
var manager = &pluginManager{ | ||
plugins: make(map[string]*Plugin), | ||
pluginSockPaths: []string{"/run/pouch/plugins"}, | ||
pluginSpecPaths: []string{"/etc/pouch/plugins", "/usr/lib/pouch/plugins"}, |
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.
/usr/lib/pouch/plugins
I think it should change to /var/lib/pouch/plugins
.
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.
agree it
plugins/plugins.go
Outdated
pluginSpecPaths: []string{"/etc/pouch/plugins", "/usr/lib/pouch/plugins"}, | ||
} | ||
|
||
// Get return the requested plugin. |
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/return/returns
plugins/plugins.go
Outdated
return manager.getPluginByName(pluginType, name) | ||
} | ||
|
||
// SetPluginSockPaths set the plugin sock paths. |
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/set/sets
plugins/plugins.go
Outdated
manager.setPluginSockPaths(paths) | ||
} | ||
|
||
// SetPluginSpecPaths set the plugin spec paths. |
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/set/sets
b176f4d
to
b45eec4
Compare
pkg/httputils/client.go
Outdated
|
||
// ParseHost inputs a host address string, and output three type: | ||
// url.URL, basePath and an error. | ||
func ParseHost(host string) (*url.URL, string, string, error) { |
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.
In the comment, you wrote that this function returns three types. While I found that this function actually returns four types (*url.URL, string, string, error)
.
I am afraid inconsistency exists.
plugins/client.go
Outdated
} | ||
} | ||
|
||
if out != nil { |
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.
How about
if out == nil {
return nil
}
return json.NewDecoder(resp.Body).Decode(out)
To use existing docker volume and network plugin. We implement pouch plugin mechanism. We change the plugin discovery directory to /run/pouch/plugins, /etc/pouch/plugins, /usr/lib/pouch/plugins. In future, maybe we will use the grpc protocol to implement the plugin Signed-off-by: Eric Li <[email protected]>
b45eec4
to
2caa0d4
Compare
LGTM |
To use existing docker volume and network plugin. We implement pouch plugin
mechanism. We change the plugin discovery directory to /run/pouch/plugins,
/etc/pouch/plugins, /usr/lib/pouch/plugins. In future, maybe we will use the
grpc protocol to implement the plugin
Signed-off-by: Eric Li [email protected]
Ⅰ. Describe what this PR did
To use existing docker volume and network plugin. We implement pouch plugin
mechanism. We change the plugin discovery directory to /run/pouch/plugins,
/etc/pouch/plugins, /usr/lib/pouch/plugins. In future, maybe we will use the
grpc protocol to implement the plugin
Ⅱ. Does this pull request fix one issue?
Ⅲ. Describe how you did it
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews