mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 02:43:36 +00:00
vendor files
This commit is contained in:
57
vendor/k8s.io/kubernetes/pkg/kubelet/remote/BUILD
generated
vendored
Normal file
57
vendor/k8s.io/kubernetes/pkg/kubelet/remote/BUILD
generated
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"doc.go",
|
||||
"remote_image.go",
|
||||
"remote_runtime.go",
|
||||
"utils.go",
|
||||
],
|
||||
importpath = "k8s.io/kubernetes/pkg/kubelet/remote",
|
||||
deps = [
|
||||
"//pkg/kubelet/apis/cri:go_default_library",
|
||||
"//pkg/kubelet/apis/cri/v1alpha1/runtime:go_default_library",
|
||||
"//pkg/kubelet/util:go_default_library",
|
||||
"//vendor/github.com/golang/glog: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",
|
||||
"//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",
|
||||
],
|
||||
)
|
2
vendor/k8s.io/kubernetes/pkg/kubelet/remote/OWNERS
generated
vendored
Normal file
2
vendor/k8s.io/kubernetes/pkg/kubelet/remote/OWNERS
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
approvers:
|
||||
- feiskyer
|
19
vendor/k8s.io/kubernetes/pkg/kubelet/remote/doc.go
generated
vendored
Normal file
19
vendor/k8s.io/kubernetes/pkg/kubelet/remote/doc.go
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
Copyright 2016 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 contains gRPC implementation of internalapi.RuntimeService
|
||||
// and internalapi.ImageManagerService.
|
||||
package remote
|
46
vendor/k8s.io/kubernetes/pkg/kubelet/remote/fake/BUILD
generated
vendored
Normal file
46
vendor/k8s.io/kubernetes/pkg/kubelet/remote/fake/BUILD
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
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"],
|
||||
)
|
19
vendor/k8s.io/kubernetes/pkg/kubelet/remote/fake/doc.go
generated
vendored
Normal file
19
vendor/k8s.io/kubernetes/pkg/kubelet/remote/fake/doc.go
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
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
|
28
vendor/k8s.io/kubernetes/pkg/kubelet/remote/fake/endpoint.go
generated
vendored
Normal file
28
vendor/k8s.io/kubernetes/pkg/kubelet/remote/fake/endpoint.go
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
// +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
|
||||
}
|
40
vendor/k8s.io/kubernetes/pkg/kubelet/remote/fake/endpoint_windows.go
generated
vendored
Normal file
40
vendor/k8s.io/kubernetes/pkg/kubelet/remote/fake/endpoint_windows.go
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
// +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
|
||||
}
|
80
vendor/k8s.io/kubernetes/pkg/kubelet/remote/fake/fake_image_service.go
generated
vendored
Normal file
80
vendor/k8s.io/kubernetes/pkg/kubelet/remote/fake/fake_image_service.go
generated
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
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
|
||||
}
|
285
vendor/k8s.io/kubernetes/pkg/kubelet/remote/fake/fake_runtime.go
generated
vendored
Normal file
285
vendor/k8s.io/kubernetes/pkg/kubelet/remote/fake/fake_runtime.go
generated
vendored
Normal file
@ -0,0 +1,285 @@
|
||||
/*
|
||||
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"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
apitest "k8s.io/kubernetes/pkg/kubelet/apis/cri/testing"
|
||||
kubeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
||||
"k8s.io/kubernetes/pkg/kubelet/util"
|
||||
utilexec "k8s.io/utils/exec"
|
||||
)
|
||||
|
||||
// RemoteRuntime represents a fake remote container runtime.
|
||||
type RemoteRuntime struct {
|
||||
server *grpc.Server
|
||||
// Fake runtime service.
|
||||
RuntimeService *apitest.FakeRuntimeService
|
||||
// Fake image service.
|
||||
ImageService *apitest.FakeImageService
|
||||
}
|
||||
|
||||
// NewFakeRemoteRuntime creates a new RemoteRuntime.
|
||||
func NewFakeRemoteRuntime() *RemoteRuntime {
|
||||
fakeRuntimeService := apitest.NewFakeRuntimeService()
|
||||
fakeImageService := apitest.NewFakeImageService()
|
||||
|
||||
f := &RemoteRuntime{
|
||||
server: grpc.NewServer(),
|
||||
RuntimeService: fakeRuntimeService,
|
||||
ImageService: fakeImageService,
|
||||
}
|
||||
kubeapi.RegisterRuntimeServiceServer(f.server, f)
|
||||
kubeapi.RegisterImageServiceServer(f.server, f)
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
// Start starts the fake remote runtime.
|
||||
func (f *RemoteRuntime) Start(endpoint string) error {
|
||||
l, err := util.CreateListener(endpoint)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to listen on %q: %v", endpoint, err)
|
||||
}
|
||||
|
||||
return f.server.Serve(l)
|
||||
}
|
||||
|
||||
// Stop stops the fake remote runtime.
|
||||
func (f *RemoteRuntime) Stop() {
|
||||
f.server.Stop()
|
||||
}
|
||||
|
||||
// Version returns the runtime name, runtime version, and runtime API version.
|
||||
func (f *RemoteRuntime) Version(ctx context.Context, req *kubeapi.VersionRequest) (*kubeapi.VersionResponse, error) {
|
||||
return f.RuntimeService.Version(req.Version)
|
||||
}
|
||||
|
||||
// RunPodSandbox creates and starts a pod-level sandbox. Runtimes must ensure
|
||||
// the sandbox is in the ready state on success.
|
||||
func (f *RemoteRuntime) RunPodSandbox(ctx context.Context, req *kubeapi.RunPodSandboxRequest) (*kubeapi.RunPodSandboxResponse, error) {
|
||||
sandboxID, err := f.RuntimeService.RunPodSandbox(req.Config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &kubeapi.RunPodSandboxResponse{PodSandboxId: sandboxID}, nil
|
||||
}
|
||||
|
||||
// StopPodSandbox stops any running process that is part of the sandbox and
|
||||
// reclaims network resources (e.g., IP addresses) allocated to the sandbox.
|
||||
// If there are any running containers in the sandbox, they must be forcibly
|
||||
// terminated.
|
||||
func (f *RemoteRuntime) StopPodSandbox(ctx context.Context, req *kubeapi.StopPodSandboxRequest) (*kubeapi.StopPodSandboxResponse, error) {
|
||||
err := f.RuntimeService.StopPodSandbox(req.PodSandboxId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &kubeapi.StopPodSandboxResponse{}, nil
|
||||
}
|
||||
|
||||
// RemovePodSandbox removes the sandbox. If there are any running containers
|
||||
// in the sandbox, they must be forcibly terminated and removed.
|
||||
// This call is idempotent, and must not return an error if the sandbox has
|
||||
// already been removed.
|
||||
func (f *RemoteRuntime) RemovePodSandbox(ctx context.Context, req *kubeapi.RemovePodSandboxRequest) (*kubeapi.RemovePodSandboxResponse, error) {
|
||||
err := f.RuntimeService.StopPodSandbox(req.PodSandboxId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &kubeapi.RemovePodSandboxResponse{}, nil
|
||||
}
|
||||
|
||||
// PodSandboxStatus returns the status of the PodSandbox. If the PodSandbox is not
|
||||
// present, returns an error.
|
||||
func (f *RemoteRuntime) PodSandboxStatus(ctx context.Context, req *kubeapi.PodSandboxStatusRequest) (*kubeapi.PodSandboxStatusResponse, error) {
|
||||
podStatus, err := f.RuntimeService.PodSandboxStatus(req.PodSandboxId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &kubeapi.PodSandboxStatusResponse{Status: podStatus}, nil
|
||||
}
|
||||
|
||||
// ListPodSandbox returns a list of PodSandboxes.
|
||||
func (f *RemoteRuntime) ListPodSandbox(ctx context.Context, req *kubeapi.ListPodSandboxRequest) (*kubeapi.ListPodSandboxResponse, error) {
|
||||
items, err := f.RuntimeService.ListPodSandbox(req.Filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &kubeapi.ListPodSandboxResponse{Items: items}, nil
|
||||
}
|
||||
|
||||
// CreateContainer creates a new container in specified PodSandbox
|
||||
func (f *RemoteRuntime) CreateContainer(ctx context.Context, req *kubeapi.CreateContainerRequest) (*kubeapi.CreateContainerResponse, error) {
|
||||
containerID, err := f.RuntimeService.CreateContainer(req.PodSandboxId, req.Config, req.SandboxConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &kubeapi.CreateContainerResponse{ContainerId: containerID}, nil
|
||||
}
|
||||
|
||||
// StartContainer starts the container.
|
||||
func (f *RemoteRuntime) StartContainer(ctx context.Context, req *kubeapi.StartContainerRequest) (*kubeapi.StartContainerResponse, error) {
|
||||
err := f.RuntimeService.StartContainer(req.ContainerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &kubeapi.StartContainerResponse{}, nil
|
||||
}
|
||||
|
||||
// StopContainer stops a running container with a grace period (i.e., timeout).
|
||||
// This call is idempotent, and must not return an error if the container has
|
||||
// already been stopped.
|
||||
func (f *RemoteRuntime) StopContainer(ctx context.Context, req *kubeapi.StopContainerRequest) (*kubeapi.StopContainerResponse, error) {
|
||||
err := f.RuntimeService.StopContainer(req.ContainerId, req.Timeout)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &kubeapi.StopContainerResponse{}, nil
|
||||
}
|
||||
|
||||
// RemoveContainer removes the container. If the container is running, the
|
||||
// container must be forcibly removed.
|
||||
// This call is idempotent, and must not return an error if the container has
|
||||
// already been removed.
|
||||
func (f *RemoteRuntime) RemoveContainer(ctx context.Context, req *kubeapi.RemoveContainerRequest) (*kubeapi.RemoveContainerResponse, error) {
|
||||
err := f.RuntimeService.RemoveContainer(req.ContainerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &kubeapi.RemoveContainerResponse{}, nil
|
||||
}
|
||||
|
||||
// ListContainers lists all containers by filters.
|
||||
func (f *RemoteRuntime) ListContainers(ctx context.Context, req *kubeapi.ListContainersRequest) (*kubeapi.ListContainersResponse, error) {
|
||||
items, err := f.RuntimeService.ListContainers(req.Filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &kubeapi.ListContainersResponse{Containers: items}, nil
|
||||
}
|
||||
|
||||
// ContainerStatus returns status of the container. If the container is not
|
||||
// present, returns an error.
|
||||
func (f *RemoteRuntime) ContainerStatus(ctx context.Context, req *kubeapi.ContainerStatusRequest) (*kubeapi.ContainerStatusResponse, error) {
|
||||
status, err := f.RuntimeService.ContainerStatus(req.ContainerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &kubeapi.ContainerStatusResponse{Status: status}, nil
|
||||
}
|
||||
|
||||
// ExecSync runs a command in a container synchronously.
|
||||
func (f *RemoteRuntime) ExecSync(ctx context.Context, req *kubeapi.ExecSyncRequest) (*kubeapi.ExecSyncResponse, error) {
|
||||
var exitCode int32
|
||||
stdout, stderr, err := f.RuntimeService.ExecSync(req.ContainerId, req.Cmd, time.Duration(req.Timeout)*time.Second)
|
||||
if err != nil {
|
||||
exitError, ok := err.(utilexec.ExitError)
|
||||
if !ok {
|
||||
return nil, err
|
||||
}
|
||||
exitCode = int32(exitError.ExitStatus())
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &kubeapi.ExecSyncResponse{
|
||||
Stdout: stdout,
|
||||
Stderr: stderr,
|
||||
ExitCode: exitCode,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Exec prepares a streaming endpoint to execute a command in the container.
|
||||
func (f *RemoteRuntime) Exec(ctx context.Context, req *kubeapi.ExecRequest) (*kubeapi.ExecResponse, error) {
|
||||
return f.RuntimeService.Exec(req)
|
||||
}
|
||||
|
||||
// Attach prepares a streaming endpoint to attach to a running container.
|
||||
func (f *RemoteRuntime) Attach(ctx context.Context, req *kubeapi.AttachRequest) (*kubeapi.AttachResponse, error) {
|
||||
return f.RuntimeService.Attach(req)
|
||||
}
|
||||
|
||||
// PortForward prepares a streaming endpoint to forward ports from a PodSandbox.
|
||||
func (f *RemoteRuntime) PortForward(ctx context.Context, req *kubeapi.PortForwardRequest) (*kubeapi.PortForwardResponse, error) {
|
||||
return f.RuntimeService.PortForward(req)
|
||||
}
|
||||
|
||||
// ContainerStats returns stats of the container. If the container does not
|
||||
// exist, the call returns an error.
|
||||
func (f *RemoteRuntime) ContainerStats(ctx context.Context, req *kubeapi.ContainerStatsRequest) (*kubeapi.ContainerStatsResponse, error) {
|
||||
stats, err := f.RuntimeService.ContainerStats(req.ContainerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &kubeapi.ContainerStatsResponse{Stats: stats}, nil
|
||||
}
|
||||
|
||||
// ListContainerStats returns stats of all running containers.
|
||||
func (f *RemoteRuntime) ListContainerStats(ctx context.Context, req *kubeapi.ListContainerStatsRequest) (*kubeapi.ListContainerStatsResponse, error) {
|
||||
stats, err := f.RuntimeService.ListContainerStats(req.Filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &kubeapi.ListContainerStatsResponse{Stats: stats}, nil
|
||||
}
|
||||
|
||||
// UpdateRuntimeConfig updates the runtime configuration based on the given request.
|
||||
func (f *RemoteRuntime) UpdateRuntimeConfig(ctx context.Context, req *kubeapi.UpdateRuntimeConfigRequest) (*kubeapi.UpdateRuntimeConfigResponse, error) {
|
||||
err := f.RuntimeService.UpdateRuntimeConfig(req.RuntimeConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &kubeapi.UpdateRuntimeConfigResponse{}, nil
|
||||
}
|
||||
|
||||
// Status returns the status of the runtime.
|
||||
func (f *RemoteRuntime) Status(ctx context.Context, req *kubeapi.StatusRequest) (*kubeapi.StatusResponse, error) {
|
||||
status, err := f.RuntimeService.Status()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &kubeapi.StatusResponse{Status: status}, nil
|
||||
}
|
||||
|
||||
// UpdateContainerResources updates ContainerConfig of the container.
|
||||
func (f *RemoteRuntime) UpdateContainerResources(ctx context.Context, req *kubeapi.UpdateContainerResourcesRequest) (*kubeapi.UpdateContainerResourcesResponse, error) {
|
||||
err := f.RuntimeService.UpdateContainerResources(req.ContainerId, req.Linux)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &kubeapi.UpdateContainerResourcesResponse{}, nil
|
||||
}
|
150
vendor/k8s.io/kubernetes/pkg/kubelet/remote/remote_image.go
generated
vendored
Normal file
150
vendor/k8s.io/kubernetes/pkg/kubelet/remote/remote_image.go
generated
vendored
Normal file
@ -0,0 +1,150 @@
|
||||
/*
|
||||
Copyright 2016 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 (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
internalapi "k8s.io/kubernetes/pkg/kubelet/apis/cri"
|
||||
runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
||||
"k8s.io/kubernetes/pkg/kubelet/util"
|
||||
)
|
||||
|
||||
// RemoteImageService is a gRPC implementation of internalapi.ImageManagerService.
|
||||
type RemoteImageService struct {
|
||||
timeout time.Duration
|
||||
imageClient runtimeapi.ImageServiceClient
|
||||
}
|
||||
|
||||
// NewRemoteImageService creates a new internalapi.ImageManagerService.
|
||||
func NewRemoteImageService(endpoint string, connectionTimeout time.Duration) (internalapi.ImageManagerService, error) {
|
||||
glog.V(3).Infof("Connecting to image service %s", endpoint)
|
||||
addr, dailer, err := util.GetAddressAndDialer(endpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
conn, err := grpc.Dial(addr, grpc.WithInsecure(), grpc.WithTimeout(connectionTimeout), grpc.WithDialer(dailer))
|
||||
if err != nil {
|
||||
glog.Errorf("Connect remote image service %s failed: %v", addr, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &RemoteImageService{
|
||||
timeout: connectionTimeout,
|
||||
imageClient: runtimeapi.NewImageServiceClient(conn),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ListImages lists available images.
|
||||
func (r *RemoteImageService) ListImages(filter *runtimeapi.ImageFilter) ([]*runtimeapi.Image, error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.imageClient.ListImages(ctx, &runtimeapi.ListImagesRequest{
|
||||
Filter: filter,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("ListImages with filter %+v from image service failed: %v", filter, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.Images, nil
|
||||
}
|
||||
|
||||
// ImageStatus returns the status of the image.
|
||||
func (r *RemoteImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimeapi.Image, error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.imageClient.ImageStatus(ctx, &runtimeapi.ImageStatusRequest{
|
||||
Image: image,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("ImageStatus %q from image service failed: %v", image.Image, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.Image != nil {
|
||||
if resp.Image.Id == "" || resp.Image.Size_ == 0 {
|
||||
errorMessage := fmt.Sprintf("Id or size of image %q is not set", image.Image)
|
||||
glog.Errorf("ImageStatus failed: %s", errorMessage)
|
||||
return nil, errors.New(errorMessage)
|
||||
}
|
||||
}
|
||||
|
||||
return resp.Image, nil
|
||||
}
|
||||
|
||||
// PullImage pulls an image with authentication config.
|
||||
func (r *RemoteImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig) (string, error) {
|
||||
ctx, cancel := getContextWithCancel()
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.imageClient.PullImage(ctx, &runtimeapi.PullImageRequest{
|
||||
Image: image,
|
||||
Auth: auth,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("PullImage %q from image service failed: %v", image.Image, err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
if resp.ImageRef == "" {
|
||||
errorMessage := fmt.Sprintf("imageRef of image %q is not set", image.Image)
|
||||
glog.Errorf("PullImage failed: %s", errorMessage)
|
||||
return "", errors.New(errorMessage)
|
||||
}
|
||||
|
||||
return resp.ImageRef, nil
|
||||
}
|
||||
|
||||
// RemoveImage removes the image.
|
||||
func (r *RemoteImageService) RemoveImage(image *runtimeapi.ImageSpec) error {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
_, err := r.imageClient.RemoveImage(ctx, &runtimeapi.RemoveImageRequest{
|
||||
Image: image,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("RemoveImage %q from image service failed: %v", image.Image, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ImageFsInfo returns information of the filesystem that is used to store images.
|
||||
func (r *RemoteImageService) ImageFsInfo() ([]*runtimeapi.FilesystemUsage, error) {
|
||||
// Do not set timeout, because `ImageFsInfo` takes time.
|
||||
// TODO(random-liu): Should we assume runtime should cache the result, and set timeout here?
|
||||
ctx, cancel := getContextWithCancel()
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.imageClient.ImageFsInfo(ctx, &runtimeapi.ImageFsInfoRequest{})
|
||||
if err != nil {
|
||||
glog.Errorf("ImageFsInfo from image service failed: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
return resp.GetImageFilesystems(), nil
|
||||
}
|
478
vendor/k8s.io/kubernetes/pkg/kubelet/remote/remote_runtime.go
generated
vendored
Normal file
478
vendor/k8s.io/kubernetes/pkg/kubelet/remote/remote_runtime.go
generated
vendored
Normal file
@ -0,0 +1,478 @@
|
||||
/*
|
||||
Copyright 2016 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 (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
internalapi "k8s.io/kubernetes/pkg/kubelet/apis/cri"
|
||||
runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
||||
"k8s.io/kubernetes/pkg/kubelet/util"
|
||||
utilexec "k8s.io/utils/exec"
|
||||
)
|
||||
|
||||
// RemoteRuntimeService is a gRPC implementation of internalapi.RuntimeService.
|
||||
type RemoteRuntimeService struct {
|
||||
timeout time.Duration
|
||||
runtimeClient runtimeapi.RuntimeServiceClient
|
||||
}
|
||||
|
||||
// NewRemoteRuntimeService creates a new internalapi.RuntimeService.
|
||||
func NewRemoteRuntimeService(endpoint string, connectionTimeout time.Duration) (internalapi.RuntimeService, error) {
|
||||
glog.Infof("Connecting to runtime service %s", endpoint)
|
||||
addr, dailer, err := util.GetAddressAndDialer(endpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
conn, err := grpc.Dial(addr, grpc.WithInsecure(), grpc.WithTimeout(connectionTimeout), grpc.WithDialer(dailer))
|
||||
if err != nil {
|
||||
glog.Errorf("Connect remote runtime %s failed: %v", addr, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &RemoteRuntimeService{
|
||||
timeout: connectionTimeout,
|
||||
runtimeClient: runtimeapi.NewRuntimeServiceClient(conn),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Version returns the runtime name, runtime version and runtime API version.
|
||||
func (r *RemoteRuntimeService) Version(apiVersion string) (*runtimeapi.VersionResponse, error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
typedVersion, err := r.runtimeClient.Version(ctx, &runtimeapi.VersionRequest{
|
||||
Version: apiVersion,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("Version from runtime service failed: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if typedVersion.Version == "" || typedVersion.RuntimeName == "" || typedVersion.RuntimeApiVersion == "" || typedVersion.RuntimeVersion == "" {
|
||||
return nil, fmt.Errorf("not all fields are set in VersionResponse (%q)", *typedVersion)
|
||||
}
|
||||
|
||||
return typedVersion, err
|
||||
}
|
||||
|
||||
// RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure
|
||||
// the sandbox is in ready state.
|
||||
func (r *RemoteRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig) (string, error) {
|
||||
// Use 2 times longer timeout for sandbox operation (4 mins by default)
|
||||
// TODO: Make the pod sandbox timeout configurable.
|
||||
ctx, cancel := getContextWithTimeout(r.timeout * 2)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.RunPodSandbox(ctx, &runtimeapi.RunPodSandboxRequest{
|
||||
Config: config,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("RunPodSandbox from runtime service failed: %v", err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
if resp.PodSandboxId == "" {
|
||||
errorMessage := fmt.Sprintf("PodSandboxId is not set for sandbox %q", config.GetMetadata())
|
||||
glog.Errorf("RunPodSandbox failed: %s", errorMessage)
|
||||
return "", errors.New(errorMessage)
|
||||
}
|
||||
|
||||
return resp.PodSandboxId, nil
|
||||
}
|
||||
|
||||
// StopPodSandbox stops the sandbox. If there are any running containers in the
|
||||
// sandbox, they should be forced to termination.
|
||||
func (r *RemoteRuntimeService) StopPodSandbox(podSandBoxID string) error {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
_, err := r.runtimeClient.StopPodSandbox(ctx, &runtimeapi.StopPodSandboxRequest{
|
||||
PodSandboxId: podSandBoxID,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("StopPodSandbox %q from runtime service failed: %v", podSandBoxID, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovePodSandbox removes the sandbox. If there are any containers in the
|
||||
// sandbox, they should be forcibly removed.
|
||||
func (r *RemoteRuntimeService) RemovePodSandbox(podSandBoxID string) error {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
_, err := r.runtimeClient.RemovePodSandbox(ctx, &runtimeapi.RemovePodSandboxRequest{
|
||||
PodSandboxId: podSandBoxID,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("RemovePodSandbox %q from runtime service failed: %v", podSandBoxID, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// PodSandboxStatus returns the status of the PodSandbox.
|
||||
func (r *RemoteRuntimeService) PodSandboxStatus(podSandBoxID string) (*runtimeapi.PodSandboxStatus, error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.PodSandboxStatus(ctx, &runtimeapi.PodSandboxStatusRequest{
|
||||
PodSandboxId: podSandBoxID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.Status != nil {
|
||||
if err := verifySandboxStatus(resp.Status); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return resp.Status, nil
|
||||
}
|
||||
|
||||
// ListPodSandbox returns a list of PodSandboxes.
|
||||
func (r *RemoteRuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.ListPodSandbox(ctx, &runtimeapi.ListPodSandboxRequest{
|
||||
Filter: filter,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("ListPodSandbox with filter %+v from runtime service failed: %v", filter, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.Items, nil
|
||||
}
|
||||
|
||||
// CreateContainer creates a new container in the specified PodSandbox.
|
||||
func (r *RemoteRuntimeService) CreateContainer(podSandBoxID string, config *runtimeapi.ContainerConfig, sandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.CreateContainer(ctx, &runtimeapi.CreateContainerRequest{
|
||||
PodSandboxId: podSandBoxID,
|
||||
Config: config,
|
||||
SandboxConfig: sandboxConfig,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("CreateContainer in sandbox %q from runtime service failed: %v", podSandBoxID, err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
if resp.ContainerId == "" {
|
||||
errorMessage := fmt.Sprintf("ContainerId is not set for container %q", config.GetMetadata())
|
||||
glog.Errorf("CreateContainer failed: %s", errorMessage)
|
||||
return "", errors.New(errorMessage)
|
||||
}
|
||||
|
||||
return resp.ContainerId, nil
|
||||
}
|
||||
|
||||
// StartContainer starts the container.
|
||||
func (r *RemoteRuntimeService) StartContainer(containerID string) error {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
_, err := r.runtimeClient.StartContainer(ctx, &runtimeapi.StartContainerRequest{
|
||||
ContainerId: containerID,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("StartContainer %q from runtime service failed: %v", containerID, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// StopContainer stops a running container with a grace period (i.e., timeout).
|
||||
func (r *RemoteRuntimeService) StopContainer(containerID string, timeout int64) error {
|
||||
// Use timeout + default timeout (2 minutes) as timeout to leave extra time
|
||||
// for SIGKILL container and request latency.
|
||||
t := r.timeout + time.Duration(timeout)*time.Second
|
||||
ctx, cancel := getContextWithTimeout(t)
|
||||
defer cancel()
|
||||
|
||||
_, err := r.runtimeClient.StopContainer(ctx, &runtimeapi.StopContainerRequest{
|
||||
ContainerId: containerID,
|
||||
Timeout: timeout,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("StopContainer %q from runtime service failed: %v", containerID, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveContainer removes the container. If the container is running, the container
|
||||
// should be forced to removal.
|
||||
func (r *RemoteRuntimeService) RemoveContainer(containerID string) error {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
_, err := r.runtimeClient.RemoveContainer(ctx, &runtimeapi.RemoveContainerRequest{
|
||||
ContainerId: containerID,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("RemoveContainer %q from runtime service failed: %v", containerID, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListContainers lists containers by filters.
|
||||
func (r *RemoteRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.ListContainers(ctx, &runtimeapi.ListContainersRequest{
|
||||
Filter: filter,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("ListContainers with filter %+v from runtime service failed: %v", filter, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.Containers, nil
|
||||
}
|
||||
|
||||
// ContainerStatus returns the container status.
|
||||
func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.ContainerStatus, error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.ContainerStatus(ctx, &runtimeapi.ContainerStatusRequest{
|
||||
ContainerId: containerID,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("ContainerStatus %q from runtime service failed: %v", containerID, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.Status != nil {
|
||||
if err := verifyContainerStatus(resp.Status); err != nil {
|
||||
glog.Errorf("ContainerStatus of %q failed: %v", containerID, err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return resp.Status, nil
|
||||
}
|
||||
|
||||
// UpdateContainerResources updates a containers resource config
|
||||
func (r *RemoteRuntimeService) UpdateContainerResources(containerID string, resources *runtimeapi.LinuxContainerResources) error {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
_, err := r.runtimeClient.UpdateContainerResources(ctx, &runtimeapi.UpdateContainerResourcesRequest{
|
||||
ContainerId: containerID,
|
||||
Linux: resources,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("UpdateContainerResources %q from runtime service failed: %v", containerID, err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExecSync executes a command in the container, and returns the stdout output.
|
||||
// If command exits with a non-zero exit code, an error is returned.
|
||||
func (r *RemoteRuntimeService) ExecSync(containerID string, cmd []string, timeout time.Duration) (stdout []byte, stderr []byte, err error) {
|
||||
// Do not set timeout when timeout is 0.
|
||||
var ctx context.Context
|
||||
var cancel context.CancelFunc
|
||||
if timeout != 0 {
|
||||
// Use timeout + default timeout (2 minutes) as timeout to leave some time for
|
||||
// the runtime to do cleanup.
|
||||
ctx, cancel = getContextWithTimeout(r.timeout + timeout)
|
||||
} else {
|
||||
ctx, cancel = getContextWithCancel()
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
timeoutSeconds := int64(timeout.Seconds())
|
||||
req := &runtimeapi.ExecSyncRequest{
|
||||
ContainerId: containerID,
|
||||
Cmd: cmd,
|
||||
Timeout: timeoutSeconds,
|
||||
}
|
||||
resp, err := r.runtimeClient.ExecSync(ctx, req)
|
||||
if err != nil {
|
||||
glog.Errorf("ExecSync %s '%s' from runtime service failed: %v", containerID, strings.Join(cmd, " "), err)
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
err = nil
|
||||
if resp.ExitCode != 0 {
|
||||
err = utilexec.CodeExitError{
|
||||
Err: fmt.Errorf("command '%s' exited with %d: %s", strings.Join(cmd, " "), resp.ExitCode, resp.Stderr),
|
||||
Code: int(resp.ExitCode),
|
||||
}
|
||||
}
|
||||
|
||||
return resp.Stdout, resp.Stderr, err
|
||||
}
|
||||
|
||||
// Exec prepares a streaming endpoint to execute a command in the container, and returns the address.
|
||||
func (r *RemoteRuntimeService) Exec(req *runtimeapi.ExecRequest) (*runtimeapi.ExecResponse, error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.Exec(ctx, req)
|
||||
if err != nil {
|
||||
glog.Errorf("Exec %s '%s' from runtime service failed: %v", req.ContainerId, strings.Join(req.Cmd, " "), err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.Url == "" {
|
||||
errorMessage := "URL is not set"
|
||||
glog.Errorf("Exec failed: %s", errorMessage)
|
||||
return nil, errors.New(errorMessage)
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// Attach prepares a streaming endpoint to attach to a running container, and returns the address.
|
||||
func (r *RemoteRuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeapi.AttachResponse, error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.Attach(ctx, req)
|
||||
if err != nil {
|
||||
glog.Errorf("Attach %s from runtime service failed: %v", req.ContainerId, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.Url == "" {
|
||||
errorMessage := "URL is not set"
|
||||
glog.Errorf("Exec failed: %s", errorMessage)
|
||||
return nil, errors.New(errorMessage)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// PortForward prepares a streaming endpoint to forward ports from a PodSandbox, and returns the address.
|
||||
func (r *RemoteRuntimeService) PortForward(req *runtimeapi.PortForwardRequest) (*runtimeapi.PortForwardResponse, error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.PortForward(ctx, req)
|
||||
if err != nil {
|
||||
glog.Errorf("PortForward %s from runtime service failed: %v", req.PodSandboxId, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.Url == "" {
|
||||
errorMessage := "URL is not set"
|
||||
glog.Errorf("Exec failed: %s", errorMessage)
|
||||
return nil, errors.New(errorMessage)
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// UpdateRuntimeConfig updates the config of a runtime service. The only
|
||||
// update payload currently supported is the pod CIDR assigned to a node,
|
||||
// and the runtime service just proxies it down to the network plugin.
|
||||
func (r *RemoteRuntimeService) UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig) error {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
// Response doesn't contain anything of interest. This translates to an
|
||||
// Event notification to the network plugin, which can't fail, so we're
|
||||
// really looking to surface destination unreachable.
|
||||
_, err := r.runtimeClient.UpdateRuntimeConfig(ctx, &runtimeapi.UpdateRuntimeConfigRequest{
|
||||
RuntimeConfig: runtimeConfig,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Status returns the status of the runtime.
|
||||
func (r *RemoteRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.Status(ctx, &runtimeapi.StatusRequest{})
|
||||
if err != nil {
|
||||
glog.Errorf("Status from runtime service failed: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.Status == nil || len(resp.Status.Conditions) < 2 {
|
||||
errorMessage := "RuntimeReady or NetworkReady condition are not set"
|
||||
glog.Errorf("Status failed: %s", errorMessage)
|
||||
return nil, errors.New(errorMessage)
|
||||
}
|
||||
|
||||
return resp.Status, nil
|
||||
}
|
||||
|
||||
// ContainerStats returns the stats of the container.
|
||||
func (r *RemoteRuntimeService) ContainerStats(containerID string) (*runtimeapi.ContainerStats, error) {
|
||||
ctx, cancel := getContextWithTimeout(r.timeout)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.ContainerStats(ctx, &runtimeapi.ContainerStatsRequest{
|
||||
ContainerId: containerID,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("ContainerStatus %q from runtime service failed: %v", containerID, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.GetStats(), nil
|
||||
}
|
||||
|
||||
func (r *RemoteRuntimeService) ListContainerStats(filter *runtimeapi.ContainerStatsFilter) ([]*runtimeapi.ContainerStats, error) {
|
||||
// Do not set timeout, because writable layer stats collection takes time.
|
||||
// TODO(random-liu): Should we assume runtime should cache the result, and set timeout here?
|
||||
ctx, cancel := getContextWithCancel()
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.runtimeClient.ListContainerStats(ctx, &runtimeapi.ListContainerStatsRequest{
|
||||
Filter: filter,
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("ListContainerStats with filter %+v from runtime service failed: %v", filter, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.GetStats(), nil
|
||||
}
|
69
vendor/k8s.io/kubernetes/pkg/kubelet/remote/remote_runtime_test.go
generated
vendored
Normal file
69
vendor/k8s.io/kubernetes/pkg/kubelet/remote/remote_runtime_test.go
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
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)
|
||||
}
|
88
vendor/k8s.io/kubernetes/pkg/kubelet/remote/utils.go
generated
vendored
Normal file
88
vendor/k8s.io/kubernetes/pkg/kubelet/remote/utils.go
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
Copyright 2016 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 (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
||||
)
|
||||
|
||||
// getContextWithTimeout returns a context with timeout.
|
||||
func getContextWithTimeout(timeout time.Duration) (context.Context, context.CancelFunc) {
|
||||
return context.WithTimeout(context.Background(), timeout)
|
||||
}
|
||||
|
||||
// getContextWithCancel returns a context with cancel.
|
||||
func getContextWithCancel() (context.Context, context.CancelFunc) {
|
||||
return context.WithCancel(context.Background())
|
||||
}
|
||||
|
||||
// verifySandboxStatus verified whether all required fields are set in PodSandboxStatus.
|
||||
func verifySandboxStatus(status *runtimeapi.PodSandboxStatus) error {
|
||||
if status.Id == "" {
|
||||
return fmt.Errorf("Id is not set")
|
||||
}
|
||||
|
||||
if status.Metadata == nil {
|
||||
return fmt.Errorf("Metadata is not set")
|
||||
}
|
||||
|
||||
metadata := status.Metadata
|
||||
if metadata.Name == "" || metadata.Namespace == "" || metadata.Uid == "" {
|
||||
return fmt.Errorf("Name, Namespace or Uid is not in metadata %q", metadata)
|
||||
}
|
||||
|
||||
if status.CreatedAt == 0 {
|
||||
return fmt.Errorf("CreatedAt is not set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// verifyContainerStatus verified whether all required fields are set in ContainerStatus.
|
||||
func verifyContainerStatus(status *runtimeapi.ContainerStatus) error {
|
||||
if status.Id == "" {
|
||||
return fmt.Errorf("Id is not set")
|
||||
}
|
||||
|
||||
if status.Metadata == nil {
|
||||
return fmt.Errorf("Metadata is not set")
|
||||
}
|
||||
|
||||
metadata := status.Metadata
|
||||
if metadata.Name == "" {
|
||||
return fmt.Errorf("Name is not in metadata %q", metadata)
|
||||
}
|
||||
|
||||
if status.CreatedAt == 0 {
|
||||
return fmt.Errorf("CreatedAt is not set")
|
||||
}
|
||||
|
||||
if status.Image == nil || status.Image.Image == "" {
|
||||
return fmt.Errorf("Image is not set")
|
||||
}
|
||||
|
||||
if status.ImageRef == "" {
|
||||
return fmt.Errorf("ImageRef is not set")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user