Skip to content

Commit bd487e2

Browse files
authored
Merge pull request #225 from feiskyer/windows
Fix building on Windows
2 parents f346707 + 94c4988 commit bd487e2

File tree

10 files changed

+280
-225
lines changed

10 files changed

+280
-225
lines changed

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ clean:
5555
find . -name \*~ -delete
5656
find . -name \#\* -delete
5757

58+
cross: check-gopath
59+
GOOS=windows $(GO) build -o $(CURDIR)/_output/critest.exe \
60+
$(PROJECT)/cmd/critest
61+
GOOS=windows $(GO) build -o $(CURDIR)/_output/crictl.exe \
62+
$(PROJECT)/cmd/crictl
63+
5864
binaries: critest crictl
5965

6066
install: check-gopath

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
}

pkg/validate/container.go

-203
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ import (
2222
"fmt"
2323
"io/ioutil"
2424
"os"
25-
"path"
2625
"path/filepath"
2726
"strings"
2827
"time"
2928

3029
"github.com/docker/docker/pkg/jsonlog"
3130
"github.com/kubernetes-incubator/cri-tools/pkg/framework"
32-
"golang.org/x/sys/unix"
3331
internalapi "k8s.io/kubernetes/pkg/kubelet/apis/cri"
3432
runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
3533

@@ -225,123 +223,6 @@ var _ = framework.KubeDescribe("Container", func() {
225223
})
226224
})
227225

228-
Context("runtime should support mount propagation", func() {
229-
var podID string
230-
var podConfig *runtimeapi.PodSandboxConfig
231-
232-
BeforeEach(func() {
233-
podID, podConfig = createPrivilegedPodSandbox(rc, true)
234-
})
235-
236-
AfterEach(func() {
237-
By("stop PodSandbox")
238-
rc.StopPodSandbox(podID)
239-
By("delete PodSandbox")
240-
rc.RemovePodSandbox(podID)
241-
})
242-
243-
It("mount with 'rprivate' should not support propagation", func() {
244-
By("create host path and flag file")
245-
mntSource, propagationSrcDir, propagationMntPoint, clearHostPath := createHostPathForMountPropagation(podID, runtimeapi.MountPropagation_PROPAGATION_PRIVATE)
246-
defer clearHostPath() // clean up the TempDir
247-
248-
By("create container with volume")
249-
containerID := createMountPropagationContainer(rc, ic, "mount-propagation-test-", podID, podConfig, mntSource, runtimeapi.MountPropagation_PROPAGATION_PRIVATE)
250-
251-
By("test start container with volume")
252-
testStartContainer(rc, containerID)
253-
254-
By("create a propatation mount point in host")
255-
createPropagationMountPoint(propagationSrcDir, propagationMntPoint)
256-
257-
By("check whether propagationMntPoint contains file or dir in container")
258-
command := []string{"ls", "-A", propagationMntPoint}
259-
output := execSyncContainer(rc, containerID, command)
260-
Expect(len(output)).To(BeZero(), "len(output) should be zero.")
261-
262-
By("create a directory named containerMntPoint as a mount point in container")
263-
containerMntPoint := path.Join(mntSource, "containerMntPoint")
264-
command = []string{"sh", "-c", "mkdir -p " + containerMntPoint}
265-
execSyncContainer(rc, containerID, command)
266-
267-
By("mount /etc to the mount point in container")
268-
command = []string{"sh", "-c", "mount --bind /etc " + containerMntPoint}
269-
execSyncContainer(rc, containerID, command)
270-
271-
By("check whether containerMntPoint contains file or dir in host")
272-
fileInfo, err := ioutil.ReadDir(containerMntPoint)
273-
framework.ExpectNoError(err, "failed to ReadDir %q in Host", containerMntPoint)
274-
Expect(len(fileInfo)).To(BeZero(), "len(fileInfo) should be zero.")
275-
})
276-
277-
It("mount with 'rshared' should support propagation from host to container and vice versa", func() {
278-
By("create host path and flag file")
279-
mntSource, propagationSrcDir, propagationMntPoint, clearHostPath := createHostPathForMountPropagation(podID, runtimeapi.MountPropagation_PROPAGATION_BIDIRECTIONAL)
280-
defer clearHostPath() // clean up the TempDir
281-
282-
By("create container with volume")
283-
containerID := createMountPropagationContainer(rc, ic, "mount-propagation-test-", podID, podConfig, mntSource, runtimeapi.MountPropagation_PROPAGATION_BIDIRECTIONAL)
284-
285-
By("test start container with volume")
286-
testStartContainer(rc, containerID)
287-
288-
By("create a propatation mount point in host")
289-
createPropagationMountPoint(propagationSrcDir, propagationMntPoint)
290-
291-
By("check whether propagationMntPoint contains file or dir in container")
292-
command := []string{"ls", "-A", propagationMntPoint}
293-
output := execSyncContainer(rc, containerID, command)
294-
Expect(len(output)).NotTo(BeZero(), "len(output) should not be zero.")
295-
296-
By("create a directory named containerMntPoint as a mount point in container")
297-
containerMntPoint := path.Join(mntSource, "containerMntPoint")
298-
command = []string{"sh", "-c", "mkdir -p " + containerMntPoint}
299-
execSyncContainer(rc, containerID, command)
300-
301-
By("mount /etc to the mount point in container")
302-
command = []string{"sh", "-c", "mount --bind /etc " + containerMntPoint}
303-
execSyncContainer(rc, containerID, command)
304-
305-
By("check whether containerMntPoint contains file or dir in host")
306-
fileInfo, err := ioutil.ReadDir(containerMntPoint)
307-
framework.ExpectNoError(err, "failed to ReadDir %q in Host", containerMntPoint)
308-
Expect(len(fileInfo)).NotTo(BeZero(), "len(fileInfo) should not be zero.")
309-
})
310-
311-
It("mount with 'rslave' should support propagation from host to container", func() {
312-
By("create host path and flag file")
313-
mntSource, propagationSrcDir, propagationMntPoint, clearHostPath := createHostPathForMountPropagation(podID, runtimeapi.MountPropagation_PROPAGATION_HOST_TO_CONTAINER)
314-
defer clearHostPath() // clean up the TempDir
315-
316-
By("create container with volume")
317-
containerID := createMountPropagationContainer(rc, ic, "mount-propagation-test-", podID, podConfig, mntSource, runtimeapi.MountPropagation_PROPAGATION_HOST_TO_CONTAINER)
318-
319-
By("test start container with volume")
320-
testStartContainer(rc, containerID)
321-
322-
By("create a propatation mount point in host")
323-
createPropagationMountPoint(propagationSrcDir, propagationMntPoint)
324-
325-
By("check whether propagationMntPoint contains file or dir in container")
326-
command := []string{"ls", "-A", propagationMntPoint}
327-
output := execSyncContainer(rc, containerID, command)
328-
Expect(len(output)).NotTo(BeZero(), "len(output) should not be zero.")
329-
330-
By("create a directory named containerMntPoint as a mount point in container")
331-
containerMntPoint := path.Join(mntSource, "containerMntPoint")
332-
command = []string{"sh", "-c", "mkdir -p " + containerMntPoint}
333-
execSyncContainer(rc, containerID, command)
334-
335-
By("mount /etc to the mount point in container")
336-
command = []string{"sh", "-c", "mount --bind /etc " + containerMntPoint}
337-
execSyncContainer(rc, containerID, command)
338-
339-
By("check whether containerMntPoint contains file or dir in host")
340-
fileInfo, err := ioutil.ReadDir(containerMntPoint)
341-
framework.ExpectNoError(err, "failed to ReadDir %q in Host", containerMntPoint)
342-
Expect(len(fileInfo)).To(BeZero(), "len(fileInfo) should be zero.")
343-
})
344-
})
345226
})
346227

347228
// containerFound returns whether containers is found.
@@ -601,87 +482,3 @@ func verifyLogContents(podConfig *runtimeapi.PodSandboxConfig, logPath string, e
601482
Expect(string(msg.stream)).To(Equal(string(expectedLogMessage.stream)), "Stream should be %s", string(expectedLogMessage.stream))
602483
}
603484
}
604-
605-
// createHostPath creates the hostPath for mount propagation test.
606-
func createHostPathForMountPropagation(podID string, propagationOpt runtimeapi.MountPropagation) (string, string, string, func()) {
607-
hostPath, err := ioutil.TempDir("", "/test"+podID)
608-
framework.ExpectNoError(err, "failed to create TempDir %q: %v", hostPath, err)
609-
610-
mntSource := filepath.Join(hostPath, "mnt")
611-
propagationMntPoint := filepath.Join(mntSource, "propagationMnt")
612-
err = os.MkdirAll(propagationMntPoint, 0700)
613-
framework.ExpectNoError(err, "failed to create volume dir %q: %v", propagationMntPoint, err)
614-
615-
propagationSrcDir := filepath.Join(hostPath, "propagationSrcDir")
616-
err = os.MkdirAll(propagationSrcDir, 0700)
617-
framework.ExpectNoError(err, "failed to create volume dir %q: %v", propagationSrcDir, err)
618-
619-
_, err = os.Create(filepath.Join(propagationSrcDir, "flagFile"))
620-
framework.ExpectNoError(err, "failed to create volume file \"flagFile\": %v", err)
621-
622-
switch propagationOpt {
623-
case runtimeapi.MountPropagation_PROPAGATION_PRIVATE:
624-
err := unix.Mount(mntSource, mntSource, "bind", unix.MS_BIND|unix.MS_REC, "")
625-
framework.ExpectNoError(err, "failed to mount \"mntSource\": %v", err)
626-
err = unix.Mount("", mntSource, "", unix.MS_PRIVATE|unix.MS_REC, "")
627-
framework.ExpectNoError(err, "failed to set \"mntSource\" to \"rprivate\": %v", err)
628-
case runtimeapi.MountPropagation_PROPAGATION_HOST_TO_CONTAINER,
629-
runtimeapi.MountPropagation_PROPAGATION_BIDIRECTIONAL:
630-
err := unix.Mount(mntSource, mntSource, "bind", unix.MS_BIND|unix.MS_REC, "")
631-
framework.ExpectNoError(err, "failed to mount \"mntSource\": %v", err)
632-
err = unix.Mount("", mntSource, "", unix.MS_SHARED|unix.MS_REC, "")
633-
framework.ExpectNoError(err, "failed to set \"mntSource\" to \"rprivate\": %v", err)
634-
default:
635-
err := unix.Mount(mntSource, mntSource, "bind", unix.MS_BIND|unix.MS_REC, "")
636-
framework.ExpectNoError(err, "failed to mount \"mntSource\": %v", err)
637-
err = unix.Mount("", mntSource, "", unix.MS_PRIVATE|unix.MS_REC, "")
638-
framework.ExpectNoError(err, "failed to set \"mntSource\" to \"rprivate\": %v", err)
639-
}
640-
641-
clearHostPath := func() {
642-
By("clean up the TempDir")
643-
err := unix.Unmount(propagationMntPoint, unix.MNT_DETACH)
644-
framework.ExpectNoError(err, "failed to unmount \"propagationMntPoint\": %v", err)
645-
err = unix.Unmount(mntSource, unix.MNT_DETACH)
646-
framework.ExpectNoError(err, "failed to unmount \"mntSource\": %v", err)
647-
648-
os.RemoveAll(hostPath)
649-
framework.ExpectNoError(err, "failed to remove \"hostPath\": %v", err)
650-
}
651-
652-
return mntSource, propagationSrcDir, propagationMntPoint, clearHostPath
653-
}
654-
655-
// createMountPropagationContainer creates a container with volume and Privileged and fails if it gets error.
656-
func createMountPropagationContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, prefix string, podID string,
657-
podConfig *runtimeapi.PodSandboxConfig, hostPath string, PropagationOpt runtimeapi.MountPropagation) string {
658-
By("create a container with volume and name")
659-
containerName := prefix + framework.NewUUID()
660-
containerConfig := &runtimeapi.ContainerConfig{
661-
Metadata: framework.BuildContainerMetadata(containerName, framework.DefaultAttempt),
662-
Image: &runtimeapi.ImageSpec{Image: framework.DefaultContainerImage},
663-
Command: []string{"sh", "-c", "top"},
664-
// Set Privileged in order to executing mount command in container
665-
Linux: &runtimeapi.LinuxContainerConfig{
666-
SecurityContext: &runtimeapi.LinuxContainerSecurityContext{
667-
Privileged: true,
668-
},
669-
},
670-
Mounts: []*runtimeapi.Mount{
671-
{
672-
HostPath: hostPath,
673-
ContainerPath: hostPath,
674-
Propagation: PropagationOpt,
675-
},
676-
},
677-
}
678-
679-
return framework.CreateContainer(rc, ic, containerConfig, podID, podConfig)
680-
}
681-
682-
// createPropagationMountPoint mount "propagationSrcDir" at "propagationMntPoint",
683-
// this will be used to check whether mount can be propagated from host to container or not.
684-
func createPropagationMountPoint(propagationSrcDir, propagationMntPoint string) {
685-
err := unix.Mount(propagationSrcDir, propagationMntPoint, "bind", unix.MS_BIND|unix.MS_REC, "")
686-
framework.ExpectNoError(err, "failed to mount \"propagationMntPoint\": %v", err)
687-
}

0 commit comments

Comments
 (0)