Skip to content

Commit 94c4988

Browse files
committed
Support specifying tcp endpoints
1 parent 5ee912e commit 94c4988

File tree

7 files changed

+30
-24
lines changed

7 files changed

+30
-24
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ clean:
5656
find . -name \#\* -delete
5757

5858
cross: check-gopath
59-
GOOS=windows $(GO) build -o $(CURDIR)/_output/critest.exe \
59+
GOOS=windows $(GO) build -o $(CURDIR)/_output/critest.exe \
6060
$(PROJECT)/cmd/critest
61-
GOOS=windows $(GO) build -o $(CURDIR)/_output/crictl.exe \
61+
GOOS=windows $(GO) build -o $(CURDIR)/_output/crictl.exe \
6262
$(PROJECT)/cmd/crictl
6363

6464
binaries: critest crictl

cmd/crictl/main.go

+17-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package main
1818

1919
import (
2020
"fmt"
21-
"net"
2221
"os"
2322
"sort"
2423
"time"
@@ -28,6 +27,7 @@ import (
2827
"google.golang.org/grpc"
2928
"k8s.io/kubernetes/pkg/kubelet/apis/cri"
3029
"k8s.io/kubernetes/pkg/kubelet/remote"
30+
"k8s.io/kubernetes/pkg/kubelet/util"
3131
)
3232

3333
const (
@@ -36,7 +36,7 @@ const (
3636
)
3737

3838
var (
39-
// RuntimeEndpoint is CRI server runtime endpoint (default: "/var/run/dockershim.sock")
39+
// RuntimeEndpoint is CRI server runtime endpoint (default: "unix:///var/run/dockershim.sock")
4040
RuntimeEndpoint string
4141
// ImageEndpoint is CRI server image endpoint, default same as runtime endpoint
4242
ImageEndpoint string
@@ -50,10 +50,13 @@ func getRuntimeClientConnection(context *cli.Context) (*grpc.ClientConn, error)
5050
if RuntimeEndpoint == "" {
5151
return nil, fmt.Errorf("--runtime-endpoint is not set")
5252
}
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-
}))
53+
54+
addr, dialer, err := util.GetAddressAndDialer(RuntimeEndpoint)
55+
if err != nil {
56+
return nil, err
57+
}
58+
59+
conn, err := grpc.Dial(addr, grpc.WithInsecure(), grpc.WithTimeout(Timeout), grpc.WithDialer(dialer))
5760
if err != nil {
5861
return nil, fmt.Errorf("failed to connect: %v", err)
5962
}
@@ -67,10 +70,13 @@ func getImageClientConnection(context *cli.Context) (*grpc.ClientConn, error) {
6770
}
6871
ImageEndpoint = RuntimeEndpoint
6972
}
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-
}))
73+
74+
addr, dialer, err := util.GetAddressAndDialer(ImageEndpoint)
75+
if err != nil {
76+
return nil, err
77+
}
78+
79+
conn, err := grpc.Dial(addr, grpc.WithInsecure(), grpc.WithTimeout(Timeout), grpc.WithDialer(dialer))
7480
if err != nil {
7581
return nil, fmt.Errorf("failed to connect: %v", err)
7682
}
@@ -125,7 +131,7 @@ func main() {
125131
cli.StringFlag{
126132
Name: "runtime-endpoint, r",
127133
EnvVar: "CRI_RUNTIME_ENDPOINT",
128-
Value: "/var/run/dockershim.sock",
134+
Value: "unix:///var/run/dockershim.sock",
129135
Usage: "Endpoint of CRI container runtime service",
130136
},
131137
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)