Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
28f67736
Commit
28f67736
authored
Jul 28, 2017
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add fake remote runtime service
parent
94e77bd4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
599 additions
and
7 deletions
+599
-7
fake_runtime_service.go
pkg/kubelet/apis/cri/testing/fake_runtime_service.go
+4
-4
BUILD
pkg/kubelet/remote/BUILD
+19
-1
BUILD
pkg/kubelet/remote/fake/BUILD
+46
-0
doc.go
pkg/kubelet/remote/fake/doc.go
+19
-0
endpoint.go
pkg/kubelet/remote/fake/endpoint.go
+28
-0
endpoint_windows.go
pkg/kubelet/remote/fake/endpoint_windows.go
+40
-0
fake_image_service.go
pkg/kubelet/remote/fake/fake_image_service.go
+80
-0
fake_runtime.go
pkg/kubelet/remote/fake/fake_runtime.go
+285
-0
remote_runtime_test.go
pkg/kubelet/remote/remote_runtime_test.go
+69
-0
BUILD
pkg/kubelet/util/BUILD
+7
-0
util_unix.go
pkg/kubelet/util/util_unix.go
+1
-1
util_unsupported.go
pkg/kubelet/util/util_unsupported.go
+1
-1
No files found.
pkg/kubelet/apis/cri/testing/fake_runtime_service.go
View file @
28f67736
...
...
@@ -26,7 +26,7 @@ import (
)
var
(
v
ersion
=
"0.1.0"
FakeV
ersion
=
"0.1.0"
FakeRuntimeName
=
"fakeRuntime"
FakePodSandboxIP
=
"192.168.192.168"
...
...
@@ -117,10 +117,10 @@ func (r *FakeRuntimeService) Version(apiVersion string) (*runtimeapi.VersionResp
r
.
Called
=
append
(
r
.
Called
,
"Version"
)
return
&
runtimeapi
.
VersionResponse
{
Version
:
v
ersion
,
Version
:
FakeV
ersion
,
RuntimeName
:
FakeRuntimeName
,
RuntimeVersion
:
v
ersion
,
RuntimeApiVersion
:
v
ersion
,
RuntimeVersion
:
FakeV
ersion
,
RuntimeApiVersion
:
FakeV
ersion
,
},
nil
}
...
...
pkg/kubelet/remote/BUILD
View file @
28f67736
...
...
@@ -3,6 +3,7 @@ package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
...
...
@@ -34,6 +35,23 @@ filegroup(
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
srcs = [
":package-srcs",
"//pkg/kubelet/remote/fake:all-srcs",
],
tags = ["automanaged"],
)
go_test(
name = "go_default_test",
srcs = ["remote_runtime_test.go"],
importpath = "k8s.io/kubernetes/pkg/kubelet/remote",
library = ":go_default_library",
tags = ["automanaged"],
deps = [
"//pkg/kubelet/apis/cri:go_default_library",
"//pkg/kubelet/apis/cri/testing:go_default_library",
"//pkg/kubelet/remote/fake:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
],
)
pkg/kubelet/remote/fake/BUILD
0 → 100644
View file @
28f67736
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"endpoint.go",
"fake_image_service.go",
"fake_runtime.go",
] + select({
"@io_bazel_rules_go//go/platform:windows_amd64": [
"endpoint_windows.go",
],
"//conditions:default": [],
}),
importpath = "k8s.io/kubernetes/pkg/kubelet/remote/fake",
tags = ["automanaged"],
deps = [
"//pkg/kubelet/apis/cri/testing:go_default_library",
"//pkg/kubelet/apis/cri/v1alpha1/runtime:go_default_library",
"//pkg/kubelet/util:go_default_library",
"//vendor/golang.org/x/net/context:go_default_library",
"//vendor/google.golang.org/grpc:go_default_library",
"//vendor/k8s.io/utils/exec:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)
pkg/kubelet/remote/fake/doc.go
0 → 100644
View file @
28f67736
/*
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 fake containers a fake gRPC implementation of internalapi.RuntimeService
// and internalapi.ImageManagerService.
package
fake
pkg/kubelet/remote/fake/endpoint.go
0 → 100644
View file @
28f67736
// +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
fake
const
(
defaultUnixEndpoint
=
"unix:///tmp/kubelet_remote.sock"
)
// GenerateEndpoint generates a new unix socket server of grpc server.
func
GenerateEndpoint
()
(
string
,
error
)
{
return
defaultUnixEndpoint
,
nil
}
pkg/kubelet/remote/fake/endpoint_windows.go
0 → 100644
View file @
28f67736
// +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
fake
import
(
"fmt"
"net"
)
// GenerateEndpoint generates a new tcp endpoint of grpc server.
func
GenerateEndpoint
()
(
string
,
error
)
{
addr
,
err
:=
net
.
ResolveTCPAddr
(
"tcp"
,
"localhost:0"
)
if
err
!=
nil
{
return
""
,
nil
}
l
,
err
:=
net
.
ListenTCP
(
"tcp"
,
addr
)
if
err
!=
nil
{
return
""
,
err
}
defer
l
.
Close
()
return
fmt
.
Sprintf
(
"tcp://127.0.0.1:%d"
,
l
.
Addr
()
.
(
*
net
.
TCPAddr
)
.
Port
),
nil
}
pkg/kubelet/remote/fake/fake_image_service.go
0 → 100644
View file @
28f67736
/*
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
fake
import
(
"golang.org/x/net/context"
kubeapi
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
)
// ListImages lists existing images.
func
(
f
*
RemoteRuntime
)
ListImages
(
ctx
context
.
Context
,
req
*
kubeapi
.
ListImagesRequest
)
(
*
kubeapi
.
ListImagesResponse
,
error
)
{
images
,
err
:=
f
.
ImageService
.
ListImages
(
req
.
Filter
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
kubeapi
.
ListImagesResponse
{
Images
:
images
,
},
nil
}
// ImageStatus returns the status of the image. If the image is not
// present, returns a response with ImageStatusResponse.Image set to
// nil.
func
(
f
*
RemoteRuntime
)
ImageStatus
(
ctx
context
.
Context
,
req
*
kubeapi
.
ImageStatusRequest
)
(
*
kubeapi
.
ImageStatusResponse
,
error
)
{
status
,
err
:=
f
.
ImageService
.
ImageStatus
(
req
.
Image
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
kubeapi
.
ImageStatusResponse
{
Image
:
status
},
nil
}
// PullImage pulls an image with authentication config.
func
(
f
*
RemoteRuntime
)
PullImage
(
ctx
context
.
Context
,
req
*
kubeapi
.
PullImageRequest
)
(
*
kubeapi
.
PullImageResponse
,
error
)
{
image
,
err
:=
f
.
ImageService
.
PullImage
(
req
.
Image
,
req
.
Auth
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
kubeapi
.
PullImageResponse
{
ImageRef
:
image
,
},
nil
}
// RemoveImage removes the image.
// This call is idempotent, and must not return an error if the image has
// already been removed.
func
(
f
*
RemoteRuntime
)
RemoveImage
(
ctx
context
.
Context
,
req
*
kubeapi
.
RemoveImageRequest
)
(
*
kubeapi
.
RemoveImageResponse
,
error
)
{
err
:=
f
.
ImageService
.
RemoveImage
(
req
.
Image
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
kubeapi
.
RemoveImageResponse
{},
nil
}
// ImageFsInfo returns information of the filesystem that is used to store images.
func
(
f
*
RemoteRuntime
)
ImageFsInfo
(
ctx
context
.
Context
,
req
*
kubeapi
.
ImageFsInfoRequest
)
(
*
kubeapi
.
ImageFsInfoResponse
,
error
)
{
fsUsage
,
err
:=
f
.
ImageService
.
ImageFsInfo
()
if
err
!=
nil
{
return
nil
,
err
}
return
&
kubeapi
.
ImageFsInfoResponse
{
ImageFilesystems
:
fsUsage
},
nil
}
pkg/kubelet/remote/fake/fake_runtime.go
0 → 100644
View file @
28f67736
This diff is collapsed.
Click to expand it.
pkg/kubelet/remote/remote_runtime_test.go
0 → 100644
View file @
28f67736
/*
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
remote
import
(
"testing"
"time"
"github.com/stretchr/testify/assert"
internalapi
"k8s.io/kubernetes/pkg/kubelet/apis/cri"
apitest
"k8s.io/kubernetes/pkg/kubelet/apis/cri/testing"
fakeremote
"k8s.io/kubernetes/pkg/kubelet/remote/fake"
)
const
(
defaultConnectionTimeout
=
15
*
time
.
Second
)
// createAndStartFakeRemoteRuntime creates and starts fakeremote.RemoteRuntime.
// It returns the RemoteRuntime, endpoint on success.
// Users should call fakeRuntime.Stop() to cleanup the server.
func
createAndStartFakeRemoteRuntime
(
t
*
testing
.
T
)
(
*
fakeremote
.
RemoteRuntime
,
string
)
{
endpoint
,
err
:=
fakeremote
.
GenerateEndpoint
()
assert
.
NoError
(
t
,
err
)
fakeRuntime
:=
fakeremote
.
NewFakeRemoteRuntime
()
go
fakeRuntime
.
Start
(
endpoint
)
return
fakeRuntime
,
endpoint
}
func
createRemoteRuntimeService
(
endpoint
string
,
t
*
testing
.
T
)
internalapi
.
RuntimeService
{
runtimeService
,
err
:=
NewRemoteRuntimeService
(
endpoint
,
defaultConnectionTimeout
)
assert
.
NoError
(
t
,
err
)
return
runtimeService
}
func
createRemoteImageService
(
endpoint
string
,
t
*
testing
.
T
)
internalapi
.
ImageManagerService
{
imageService
,
err
:=
NewRemoteImageService
(
endpoint
,
defaultConnectionTimeout
)
assert
.
NoError
(
t
,
err
)
return
imageService
}
func
TestVersion
(
t
*
testing
.
T
)
{
fakeRuntime
,
endpoint
:=
createAndStartFakeRemoteRuntime
(
t
)
defer
fakeRuntime
.
Stop
()
r
:=
createRemoteRuntimeService
(
endpoint
,
t
)
version
,
err
:=
r
.
Version
(
apitest
.
FakeVersion
)
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
apitest
.
FakeVersion
,
version
.
Version
)
assert
.
Equal
(
t
,
apitest
.
FakeRuntimeName
,
version
.
RuntimeName
)
}
pkg/kubelet/util/BUILD
View file @
28f67736
...
...
@@ -21,6 +21,9 @@ go_library(
"util.go",
"util_unsupported.go",
] + select({
"@io_bazel_rules_go//go/platform:darwin_amd64": [
"util_unix.go",
],
"@io_bazel_rules_go//go/platform:linux_amd64": [
"util_unix.go",
],
...
...
@@ -33,6 +36,10 @@ go_library(
deps = [
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
] + select({
"@io_bazel_rules_go//go/platform:darwin_amd64": [
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:linux_amd64": [
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/golang.org/x/sys/unix:go_default_library",
...
...
pkg/kubelet/util/util_unix.go
View file @
28f67736
// +build freebsd linux
// +build freebsd linux
darwin
/*
Copyright 2017 The Kubernetes Authors.
...
...
pkg/kubelet/util/util_unsupported.go
View file @
28f67736
// +build !freebsd,!linux,!windows
// +build !freebsd,!linux,!windows
,!darwin
/*
Copyright 2017 The Kubernetes Authors.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment