Skip to content
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

A few fixes to defaults on Windows. #374

Merged
merged 2 commits into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions cmd/crictl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,16 @@ import (
"google.golang.org/grpc"
"k8s.io/kubernetes/pkg/kubelet/apis/cri"
"k8s.io/kubernetes/pkg/kubelet/remote"
"k8s.io/kubernetes/pkg/kubelet/util"

"github.com/kubernetes-sigs/cri-tools/pkg/version"
)

const (
defaultConfigPath = "/etc/crictl.yaml"
defaultTimeout = 10 * time.Second
defaultTimeout = 10 * time.Second
)

var (
// RuntimeEndpoint is CRI server runtime endpoint (default: "unix:///var/run/dockershim.sock")
// RuntimeEndpoint is CRI server runtime endpoint
RuntimeEndpoint string
// ImageEndpoint is CRI server image endpoint, default same as runtime endpoint
ImageEndpoint string
Expand All @@ -54,7 +52,7 @@ func getRuntimeClientConnection(context *cli.Context) (*grpc.ClientConn, error)
return nil, fmt.Errorf("--runtime-endpoint is not set")
}

addr, dialer, err := util.GetAddressAndDialer(RuntimeEndpoint)
addr, dialer, err := GetAddressAndDialer(RuntimeEndpoint)
if err != nil {
return nil, err
}
Expand All @@ -74,7 +72,7 @@ func getImageClientConnection(context *cli.Context) (*grpc.ClientConn, error) {
ImageEndpoint = RuntimeEndpoint
}

addr, dialer, err := util.GetAddressAndDialer(ImageEndpoint)
addr, dialer, err := GetAddressAndDialer(ImageEndpoint)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -138,7 +136,7 @@ func main() {
cli.StringFlag{
Name: "runtime-endpoint, r",
EnvVar: "CONTAINER_RUNTIME_ENDPOINT",
Value: "unix:///var/run/dockershim.sock",
Value: defaultRuntimeEndpoint,
Usage: "Endpoint of CRI container runtime service",
},
cli.StringFlag{
Expand Down
47 changes: 47 additions & 0 deletions cmd/crictl/main_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// +build !windows

/*
Copyright 2017 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"net"
"time"

"k8s.io/kubernetes/pkg/kubelet/util"
)

const (
defaultConfigPath = "/etc/crictl.yaml"
defaultRuntimeEndpoint = "unix:///var/run/dockershim.sock"
)

// GetAddressAndDialer returns the address and a dialer for the endpoint
// protocol.
//
// On Unix supported protocols are unix sockets.
//
// Examples:
//
// An endpoint of "unix:///var/run/dockershim.sock" returns address
// "/var/run/dockershim.sock" and a unix socket dialer for this address.
//
// An endpoint of "/var/run/dockershim.sock" returns address
// "/var/run/dockershim.sock" and a unix socket dialer for this address.
func GetAddressAndDialer(endpoint string) (string, func(addr string, timeout time.Duration) (net.Conn, error), error) {
return util.GetAddressAndDialer(endpoint)
}
63 changes: 63 additions & 0 deletions cmd/crictl/main_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// +build windows

/*
Copyright 2017 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"net"
"os"
"path/filepath"
"strings"
"time"

"github.com/Microsoft/go-winio"
"k8s.io/kubernetes/pkg/kubelet/util"
)

const (
defaultRuntimeEndpoint = "tcp://localhost:3735"
)

var defaultConfigPath string

func init() {
defaultConfigPath = filepath.Join(os.Getenv("USERPROFILE"), ".crictl", "crictl.yaml")
}

// GetAddressAndDialer returns the address and a dialer for the endpoint
// protocol.
//
// On Windows supported protocols are Windows named pipes and tcp.
//
// Examples:
//
// An endpoint of "tcp://localhost:3735" returns address "localhost:3735" and a
// tcp socket dialer for this address.
//
// An endpoint of "\\.\pipe\name" returns an address of "\\.\pipe\name" and a
// Windows named pipe dialer for this address.
func GetAddressAndDialer(endpoint string) (string, func(addr string, timeout time.Duration) (net.Conn, error), error) {
if strings.HasPrefix(endpoint, "\\\\.\\pipe") {
return endpoint, dial, nil
}
return util.GetAddressAndDialer(endpoint)
}

func dial(addr string, timeout time.Duration) (net.Conn, error) {
return winio.DialPipe(addr, &timeout)
}
6 changes: 3 additions & 3 deletions docs/benchmark.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ git clone https://github.com/kubernetes-sigs/cri-tools -b release-1.9 $GOPATH/sr

### Prerequisite

Before running the test, you need to _ensure that the CRI server under test is running and listening on a Unix socket_. Because the benchmark tests are designed to request changes (e.g., create/delete) to the containers and verify that correct status is reported, it expects to be the only user of the CRI server. Please make sure that 1) there are no existing CRI-managed containers running on the node, and 2) no other processes (e.g., Kubelet) will interfere with the tests.
Before running the test, you need to _ensure that the CRI server under test is running and listening on a Unix socket_ or a Windows tcp socket. Because the benchmark tests are designed to request changes (e.g., create/delete) to the containers and verify that correct status is reported, it expects to be the only user of the CRI server. Please make sure that 1) there are no existing CRI-managed containers running on the node, and 2) no other processes (e.g., Kubelet) will interfere with the tests.

### Run

Expand All @@ -38,12 +38,12 @@ This will
- Run the benchmark tests using `ginkgo`
- Output the test results to STDOUT

critest connects to `unix:///var/run/dockershim.sock` by default. For other runtimes, the endpoint can be set by flags `--runtime-endpoint` and `--image-endpoint`.
critest connects to Unix: `unix:///var/run/dockershim.sock` or Windows: `tcp://localhost:3735` by default. For other runtimes, the endpoint can be set by flags `--runtime-endpoint` and `--image-endpoint`.

## Additional options

- `-ginkgo.focus`: Only run the tests that match the regular expression.
- `-image-endpoint`: Set the endpoint of image service. Same with runtime-endpoint if not specified.
- `-runtime-endpoint`: Set the endpoint of runtime service. Default to `unix:///var/run/dockershim.sock`.
- `-runtime-endpoint`: Set the endpoint of runtime service. Default to Unix: `unix:///var/run/dockershim.sock` or Windows: `tcp://localhost:3735`.
- `-ginkgo.skip`: Skip the tests that match the regular expression.
- `-h`: Should help and all supported options.
13 changes: 11 additions & 2 deletions docs/crictl.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,32 @@ Subcommands includes:
- `completion`: Output bash shell completion code
- `help, h`: Shows a list of commands or help for one command

crictl connects to `unix:///var/run/dockershim.sock` by default. For other runtimes, the endpoint can be set in three ways:
crictl connects to Unix: `unix:///var/run/dockershim.sock` or Windows: `tcp://localhost:3735` by default. For other runtimes, the endpoint can be set in three ways:

- By setting flags `--runtime-endpoint` and `--image-endpoint`
- By setting environment variables `CONTAINER_RUNTIME_ENDPOINT` and `IMAGE_SERVICE_ENDPOINT`
- By setting the endpoint in the config file `--config=/etc/crictl.yaml`

Unix:
```sh
$ cat /etc/crictl.yaml
runtime-endpoint: unix:///var/run/dockershim.sock
image-endpoint: unix:///var/run/dockershim.sock
timeout: 10
debug: true
```
Windows:
```cmd
C:\> type %USERPROFILE%\.crictl\crictl.yaml
runtime-endpoint: tcp://localhost:3735
image-endpoint: tcp://localhost:3735
timeout: 10
debug: true
```

## Additional options

- `--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`
- `--runtime-endpoint`, `-r`: CRI server runtime endpoint (default: Unix: `unix:///var/run/dockershim.sock` or Windows: `tcp://localhost:3735`). 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`
- `--image-endpoint`, `-i`: CRI server image endpoint, default same as runtime endpoint.
- `--timeout`, `-t`: Timeout of connecting to server (default: 10s)
- `--debug`, `-D`: Enable debug output
Expand Down
4 changes: 2 additions & 2 deletions docs/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ This will
- Run the tests using `ginkgo`
- Output the test results to STDOUT

critest connects to `unix:///var/run/dockershim.sock` by default. For other runtimes, the endpoint can be set by flags `--runtime-endpoint` and `--image-endpoint`.
critest connects to Unix: `unix:///var/run/dockershim.sock` or Windows: `tcp://localhost:3735` by default. For other runtimes, the endpoint can be set by flags `--runtime-endpoint` and `--image-endpoint`.

## Additional options

- `-ginkgo.focus`: Only run the tests that match the regular expression.
- `-image-endpoint`: Set the endpoint of image service. Same with runtime-endpoint if not specified.
- `-runtime-endpoint`: Set the endpoint of runtime service. Default to `unix:///var/run/dockershim.sock`.
- `-runtime-endpoint`: Set the endpoint of runtime service. Default to `unix:///var/run/dockershim.sock` or Windows: `tcp://localhost:3735`.
- `-ginkgo.skip`: Skip the tests that match the regular expression.
- `-parallel`: The number of parallel test nodes to run (default 1). [ginkgo](https://github.com/onsi/ginkgo) must be installed to run parallel tests.
- `-h`: Should help and all supported options.
8 changes: 7 additions & 1 deletion pkg/framework/test_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package framework

import (
"flag"
"runtime"
"time"

"github.com/onsi/ginkgo/config"
Expand Down Expand Up @@ -57,7 +58,12 @@ func RegisterFlags() {
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.")
flag.StringVar(&TestContext.ImageServiceAddr, "image-endpoint", "", "Image service socket for client to connect.")
flag.DurationVar(&TestContext.ImageServiceTimeout, "image-service-timeout", 300*time.Second, "Timeout when trying to connect to image service.")
flag.StringVar(&TestContext.RuntimeServiceAddr, "runtime-endpoint", "unix:///var/run/dockershim.sock", "Runtime service socket for client to connect..")

svcaddr := "unix:///var/run/dockershim.sock"
if runtime.GOOS == "windows" {
svcaddr = "tcp://localhost:3735"
}
flag.StringVar(&TestContext.RuntimeServiceAddr, "runtime-endpoint", svcaddr, "Runtime service socket for client to connect..")
flag.DurationVar(&TestContext.RuntimeServiceTimeout, "runtime-service-timeout", 300*time.Second, "Timeout when trying to connect to a runtime service.")
flag.IntVar(&TestContext.Number, "number", 5, "Number of PodSandbox/container in listing benchmark test.")
}
1 change: 1 addition & 0 deletions vendor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ github.com/golang/glog 44145f04b68cf362d9c4df2182967c2275eaefed
github.com/golang/protobuf b4deda0973fb4c70b50d226b1af49f3da59f5265
github.com/google/gofuzz 44d81051d367757e1c7c6a5a86423ece9afcf63c
github.com/json-iterator/go f2b4162afba35581b6d4a50d3b8f34e33c144682
github.com/Microsoft/go-winio v0.4.11
github.com/mitchellh/go-wordwrap ad45545899c7b13c020ea92b2072220eefad42b8
github.com/modern-go/concurrent bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94
github.com/modern-go/reflect2 05fbef0ca5da472bbf96c9322b84a53edc03c9fd
Expand Down
22 changes: 22 additions & 0 deletions vendor/github.com/Microsoft/go-winio/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/github.com/Microsoft/go-winio/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading