ctr: support proto://address format for --address

In order to match the containerd --listen update, allow users to set any
address of the form proto://address.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
This commit is contained in:
Aleksa Sarai 2016-04-01 22:09:02 +11:00
parent f88d701233
commit 0ec0bb380f
2 changed files with 11 additions and 4 deletions

View file

@ -26,15 +26,22 @@ import (
// TODO: parse flags and pass opts // TODO: parse flags and pass opts
func getClient(ctx *cli.Context) types.APIClient { func getClient(ctx *cli.Context) types.APIClient {
// Parse proto://address form addresses.
bindSpec := ctx.GlobalString("address")
bindParts := strings.SplitN(bindSpec, "://", 2)
if len(bindParts) != 2 {
fatal(fmt.Sprintf("bad bind address format %s, expected proto://address", bindSpec), 1)
}
// reset the logger for grpc to log to dev/null so that it does not mess with our stdio // reset the logger for grpc to log to dev/null so that it does not mess with our stdio
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags)) grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
dialOpts := []grpc.DialOption{grpc.WithInsecure(), grpc.WithTimeout(ctx.GlobalDuration("conn-timeout"))} dialOpts := []grpc.DialOption{grpc.WithInsecure(), grpc.WithTimeout(ctx.GlobalDuration("conn-timeout"))}
dialOpts = append(dialOpts, dialOpts = append(dialOpts,
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout) return net.DialTimeout(bindParts[0], bindParts[1], timeout)
}, },
)) ))
conn, err := grpc.Dial(ctx.GlobalString("address"), dialOpts...) conn, err := grpc.Dial(bindSpec, dialOpts...)
if err != nil { if err != nil {
fatal(err.Error(), 1) fatal(err.Error(), 1)
} }

View file

@ -41,8 +41,8 @@ func main() {
}, },
cli.StringFlag{ cli.StringFlag{
Name: "address", Name: "address",
Value: "/run/containerd/containerd.sock", Value: "unix:///run/containerd/containerd.sock",
Usage: "address of GRPC API", Usage: "proto://address of GRPC API",
}, },
cli.DurationFlag{ cli.DurationFlag{
Name: "conn-timeout", Name: "conn-timeout",