Skip to content

Commit 0ec0bb3

Browse files
committed
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>
1 parent f88d701 commit 0ec0bb3

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

ctr/container.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,22 @@ import (
2626

2727
// TODO: parse flags and pass opts
2828
func getClient(ctx *cli.Context) types.APIClient {
29+
// Parse proto://address form addresses.
30+
bindSpec := ctx.GlobalString("address")
31+
bindParts := strings.SplitN(bindSpec, "://", 2)
32+
if len(bindParts) != 2 {
33+
fatal(fmt.Sprintf("bad bind address format %s, expected proto://address", bindSpec), 1)
34+
}
35+
2936
// reset the logger for grpc to log to dev/null so that it does not mess with our stdio
3037
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
3138
dialOpts := []grpc.DialOption{grpc.WithInsecure(), grpc.WithTimeout(ctx.GlobalDuration("conn-timeout"))}
3239
dialOpts = append(dialOpts,
3340
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
34-
return net.DialTimeout("unix", addr, timeout)
41+
return net.DialTimeout(bindParts[0], bindParts[1], timeout)
3542
},
3643
))
37-
conn, err := grpc.Dial(ctx.GlobalString("address"), dialOpts...)
44+
conn, err := grpc.Dial(bindSpec, dialOpts...)
3845
if err != nil {
3946
fatal(err.Error(), 1)
4047
}

ctr/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func main() {
4141
},
4242
cli.StringFlag{
4343
Name: "address",
44-
Value: "/run/containerd/containerd.sock",
45-
Usage: "address of GRPC API",
44+
Value: "unix:///run/containerd/containerd.sock",
45+
Usage: "proto://address of GRPC API",
4646
},
4747
cli.DurationFlag{
4848
Name: "conn-timeout",

0 commit comments

Comments
 (0)