Skip to content

Commit 6b5965f

Browse files
committed
Support specifying tcp endpoints
1 parent 5ee912e commit 6b5965f

File tree

6 files changed

+39
-25
lines changed

6 files changed

+39
-25
lines changed

cmd/crictl/main.go

+28-14
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ package main
1818

1919
import (
2020
"fmt"
21-
"net"
2221
"os"
2322
"sort"
23+
"strings"
2424
"time"
2525

2626
"github.com/Sirupsen/logrus"
2727
"github.com/urfave/cli"
2828
"google.golang.org/grpc"
2929
"k8s.io/kubernetes/pkg/kubelet/apis/cri"
3030
"k8s.io/kubernetes/pkg/kubelet/remote"
31+
"k8s.io/kubernetes/pkg/kubelet/util"
3132
)
3233

3334
const (
@@ -36,7 +37,7 @@ const (
3637
)
3738

3839
var (
39-
// RuntimeEndpoint is CRI server runtime endpoint (default: "/var/run/dockershim.sock")
40+
// RuntimeEndpoint is CRI server runtime endpoint (default: "unix:///var/run/dockershim.sock")
4041
RuntimeEndpoint string
4142
// ImageEndpoint is CRI server image endpoint, default same as runtime endpoint
4243
ImageEndpoint string
@@ -47,30 +48,43 @@ var (
4748
)
4849

4950
func getRuntimeClientConnection(context *cli.Context) (*grpc.ClientConn, error) {
50-
if RuntimeEndpoint == "" {
51+
runtimeEndpoint := RuntimeEndpoint
52+
if runtimeEndpoint == "" {
5153
return nil, fmt.Errorf("--runtime-endpoint is not set")
5254
}
53-
conn, err := grpc.Dial(RuntimeEndpoint, grpc.WithInsecure(), grpc.WithTimeout(Timeout),
54-
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
55-
return net.DialTimeout("unix", addr, timeout)
56-
}))
55+
56+
// Default connects to unix sockets.
57+
if !strings.HasPrefix(RuntimeEndpoint, "unix://") && !strings.HasPrefix(RuntimeEndpoint, "tcp://") {
58+
runtimeEndpoint = fmt.Sprintf("unix://%s", RuntimeEndpoint)
59+
}
60+
61+
addr, dialer, err := util.GetAddressAndDialer(runtimeEndpoint)
62+
if err != nil {
63+
return nil, err
64+
}
65+
66+
conn, err := grpc.Dial(addr, grpc.WithInsecure(), grpc.WithTimeout(Timeout), grpc.WithDialer(dialer))
5767
if err != nil {
5868
return nil, fmt.Errorf("failed to connect: %v", err)
5969
}
6070
return conn, nil
6171
}
6272

6373
func getImageClientConnection(context *cli.Context) (*grpc.ClientConn, error) {
64-
if ImageEndpoint == "" {
74+
imageEndpoint := ImageEndpoint
75+
if imageEndpoint == "" {
6576
if RuntimeEndpoint == "" {
6677
return nil, fmt.Errorf("--image-endpoint is not set")
6778
}
68-
ImageEndpoint = RuntimeEndpoint
79+
imageEndpoint = RuntimeEndpoint
6980
}
70-
conn, err := grpc.Dial(ImageEndpoint, grpc.WithInsecure(), grpc.WithTimeout(Timeout),
71-
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
72-
return net.DialTimeout("unix", addr, timeout)
73-
}))
81+
82+
addr, dialer, err := util.GetAddressAndDialer(imageEndpoint)
83+
if err != nil {
84+
return nil, err
85+
}
86+
87+
conn, err := grpc.Dial(addr, grpc.WithInsecure(), grpc.WithTimeout(Timeout), grpc.WithDialer(dialer))
7488
if err != nil {
7589
return nil, fmt.Errorf("failed to connect: %v", err)
7690
}
@@ -125,7 +139,7 @@ func main() {
125139
cli.StringFlag{
126140
Name: "runtime-endpoint, r",
127141
EnvVar: "CRI_RUNTIME_ENDPOINT",
128-
Value: "/var/run/dockershim.sock",
142+
Value: "unix:///var/run/dockershim.sock",
129143
Usage: "Endpoint of CRI container runtime service",
130144
},
131145
cli.StringFlag{

cmd/critest/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func main() {
4949
cli.StringFlag{
5050
Name: "runtime-endpoint, r",
5151
EnvVar: "CRI_RUNTIME_ENDPOINT",
52-
Value: "/var/run/dockershim.sock",
52+
Value: "unix:///var/run/dockershim.sock",
5353
Usage: "CRI runtime service address which is tested.",
5454
},
5555
cli.StringFlag{

docs/benchmark.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ This will
3232
- Run the benchmark tests using `ginkgo`
3333
- Output the test results to STDOUT
3434

35-
critest connects to `/var/run/dockershim.sock` by default. For other runtimes, the endpoint can be set in two ways:
35+
critest connects to `unix:///var/run/dockershim.sock` by default. For other runtimes, the endpoint can be set in two ways:
3636

3737
- By setting flags `--runtime-endpoint` and `--image-endpoint`
3838
- By setting environment variables `CRI_RUNTIME_ENDPOINT` and `CRI_IMAGE_ENDPOINT`
@@ -42,5 +42,5 @@ critest connects to `/var/run/dockershim.sock` by default. For other runtimes, t
4242
- `--focus`, `-f`: Only run the tests that match the regular expression.
4343
- -`-ginkgo-flags`, `-g`: Space-separated list of arguments to pass to Ginkgo test runner.
4444
- `--image-endpoint`, `-i`: Set the endpoint of image service. Same with runtime-endpoint if not specified.
45-
- `--runtime-endpoint`, `-r`: Set the endpoint of runtime service. Default to `/var/run/dockershim.sock`.
45+
- `--runtime-endpoint`, `-r`: Set the endpoint of runtime service. Default to `unix:///var/run/dockershim.sock`.
4646
- `--skip`, `-s`: Skip the tests that match the regular expression.

docs/crictl.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,23 @@ Subcommands includes:
4747
- `logs`: Fetch the logs of a container
4848
- `help`: Shows a list of commands or help for one command
4949

50-
crictl connects to `/var/run/dockershim.sock` by default. For other runtimes, the endpoint can be set in three ways:
50+
crictl connects to `unix:///var/run/dockershim.sock` by default. For other runtimes, the endpoint can be set in three ways:
5151

5252
- By setting flags `--runtime-endpoint` and `--image-endpoint`
5353
- By setting environment variables `CRI_RUNTIME_ENDPOINT` and `CRI_IMAGE_ENDPOINT`
5454
- By setting the endpoint in the config file `--config=/etc/crictl.yaml`
5555

5656
```
5757
# cat /etc/crictl.yaml
58-
runtime-endpoint: /var/run/dockershim.sock
59-
image-endpoint: /var/run/dockershim.sock
58+
runtime-endpoint: unix:///var/run/dockershim.sock
59+
image-endpoint: unix:///var/run/dockershim.sock
6060
timeout: 10
6161
debug: true
6262
```
6363

6464
## Additional options
6565

66-
- `--runtime-endpoint`, `-r`: CRI server runtime endpoint (default: "/var/run/dockershim.sock").The default server is dockershim. If we want to debug other CRI server such as frakti, we can add flag `--runtime-endpoint=/var/run/frakti.sock`
66+
- `--runtime-endpoint`, `-r`: CRI server runtime endpoint (default: "unix:///var/run/dockershim.sock").The default server is dockershim. If we want to debug other CRI server such as frakti, we can add flag `--runtime-endpoint=/var/run/frakti.sock`
6767
- `--image-endpoint`, `-i`: CRI server image endpoint, default same as runtime endpoint.
6868
- `--timeout`, `-t`: Timeout of connecting to server (default: 10s)
6969
- `--debug`, `-D`: Enable debug output

docs/validation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This will
3434
- Run the tests using `ginkgo`
3535
- Output the test results to STDOUT
3636

37-
critest connects to `/var/run/dockershim.sock` by default. For other runtimes, the endpoint can be set in two ways:
37+
critest connects to `unix:///var/run/dockershim.sock` by default. For other runtimes, the endpoint can be set in two ways:
3838

3939
- By setting flags `--runtime-endpoint` and `--image-endpoint`
4040
- By setting environment variables `CRI_RUNTIME_ENDPOINT` and `CRI_IMAGE_ENDPOINT`
@@ -44,5 +44,5 @@ critest connects to `/var/run/dockershim.sock` by default. For other runtimes, t
4444
- `--focus`, `-f`: Only run the tests that match the regular expression.
4545
- -`-ginkgo-flags`, `-g`: Space-separated list of arguments to pass to Ginkgo test runner.
4646
- `--image-endpoint`, `-i`: Set the endpoint of image service. Same with runtime-endpoint if not specified.
47-
- `--runtime-endpoint`, `-r`: Set the endpoint of runtime service. Default to `/var/run/dockershim.sock`.
47+
- `--runtime-endpoint`, `-r`: Set the endpoint of runtime service. Default to `unix:///var/run/dockershim.sock`.
4848
- `--skip`, `-s`: Skip the tests that match the regular expression.

pkg/framework/test_context.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ func RegisterFlags() {
5555

5656
flag.StringVar(&TestContext.ReportPrefix, "report-prefix", "", "Optional prefix for JUnit XML reports. Default is empty, which doesn't prepend anything to the default name.")
5757
flag.StringVar(&TestContext.ReportDir, "report-dir", "", "Path to the directory where the JUnit XML reports should be saved. Default is empty, which doesn't generate these reports.")
58-
flag.StringVar(&TestContext.ImageServiceAddr, "image-service-address", "/var/run/dockershim.sock", "Image service socket for client to connect.")
58+
flag.StringVar(&TestContext.ImageServiceAddr, "image-service-address", "unix:///var/run/dockershim.sock", "Image service socket for client to connect.")
5959
flag.DurationVar(&TestContext.ImageServiceTimeout, "image-service-timeout", 300*time.Second, "Timeout when trying to connect to image service.")
60-
flag.StringVar(&TestContext.RuntimeServiceAddr, "runtime-service-address", "/var/run/dockershim.sock", "Runtime service socket for client to connect..")
60+
flag.StringVar(&TestContext.RuntimeServiceAddr, "runtime-service-address", "unix:///var/run/dockershim.sock", "Runtime service socket for client to connect..")
6161
flag.DurationVar(&TestContext.RuntimeServiceTimeout, "runtime-service-timeout", 300*time.Second, "Timeout when trying to connect to a runtime service.")
6262
flag.IntVar(&TestContext.Number, "number", 5, "Number of PodSandbox/container in listing benchmark test.")
6363
}

0 commit comments

Comments
 (0)