2016-08-01 22:13:36 +00:00
|
|
|
/*
|
|
|
|
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 testing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-10-14 18:52:18 +00:00
|
|
|
"reflect"
|
2016-08-02 01:53:29 +00:00
|
|
|
"sync"
|
|
|
|
"time"
|
2016-08-01 22:13:36 +00:00
|
|
|
|
2017-06-07 08:54:28 +00:00
|
|
|
runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
2016-08-01 22:13:36 +00:00
|
|
|
)
|
|
|
|
|
2016-08-02 01:53:29 +00:00
|
|
|
var (
|
|
|
|
version = "0.1.0"
|
|
|
|
|
2016-08-13 07:12:40 +00:00
|
|
|
FakeRuntimeName = "fakeRuntime"
|
|
|
|
FakePodSandboxIP = "192.168.192.168"
|
2016-08-02 01:53:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type FakePodSandbox struct {
|
2016-08-17 08:04:25 +00:00
|
|
|
// PodSandboxStatus contains the runtime information for a sandbox.
|
2016-11-30 07:27:27 +00:00
|
|
|
runtimeapi.PodSandboxStatus
|
2016-08-01 22:13:36 +00:00
|
|
|
}
|
|
|
|
|
2016-08-02 01:53:29 +00:00
|
|
|
type FakeContainer struct {
|
|
|
|
// ContainerStatus contains the runtime information for a container.
|
2016-11-30 07:27:27 +00:00
|
|
|
runtimeapi.ContainerStatus
|
2016-08-02 01:53:29 +00:00
|
|
|
|
|
|
|
// the sandbox id of this container
|
|
|
|
SandboxID string
|
2016-08-01 22:13:36 +00:00
|
|
|
}
|
|
|
|
|
2016-08-02 01:53:29 +00:00
|
|
|
type FakeRuntimeService struct {
|
|
|
|
sync.Mutex
|
|
|
|
|
|
|
|
Called []string
|
|
|
|
|
2017-08-31 22:37:04 +00:00
|
|
|
FakeStatus *runtimeapi.RuntimeStatus
|
|
|
|
Containers map[string]*FakeContainer
|
|
|
|
Sandboxes map[string]*FakePodSandbox
|
|
|
|
FakeContainerStats map[string]*runtimeapi.ContainerStats
|
2016-08-01 22:13:36 +00:00
|
|
|
}
|
|
|
|
|
2017-06-15 00:42:01 +00:00
|
|
|
func (r *FakeRuntimeService) GetContainerID(sandboxID, name string, attempt uint32) (string, error) {
|
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
for id, c := range r.Containers {
|
|
|
|
if c.SandboxID == sandboxID && c.Metadata.Name == name && c.Metadata.Attempt == attempt {
|
|
|
|
return id, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "", fmt.Errorf("container (name, attempt, sandboxID)=(%q, %d, %q) not found", name, attempt, sandboxID)
|
|
|
|
}
|
|
|
|
|
2016-08-02 01:53:29 +00:00
|
|
|
func (r *FakeRuntimeService) SetFakeSandboxes(sandboxes []*FakePodSandbox) {
|
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Sandboxes = make(map[string]*FakePodSandbox)
|
|
|
|
for _, sandbox := range sandboxes {
|
2017-01-20 01:54:28 +00:00
|
|
|
sandboxID := sandbox.Id
|
2016-08-02 01:53:29 +00:00
|
|
|
r.Sandboxes[sandboxID] = sandbox
|
|
|
|
}
|
2016-08-01 22:13:36 +00:00
|
|
|
}
|
|
|
|
|
2016-08-02 01:53:29 +00:00
|
|
|
func (r *FakeRuntimeService) SetFakeContainers(containers []*FakeContainer) {
|
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Containers = make(map[string]*FakeContainer)
|
|
|
|
for _, c := range containers {
|
2017-01-20 01:54:28 +00:00
|
|
|
containerID := c.Id
|
2016-08-02 01:53:29 +00:00
|
|
|
r.Containers[containerID] = c
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-10-14 18:52:18 +00:00
|
|
|
func (r *FakeRuntimeService) AssertCalls(calls []string) error {
|
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(calls, r.Called) {
|
|
|
|
return fmt.Errorf("expected %#v, got %#v", calls, r.Called)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-02 01:53:29 +00:00
|
|
|
func NewFakeRuntimeService() *FakeRuntimeService {
|
|
|
|
return &FakeRuntimeService{
|
2017-08-31 22:37:04 +00:00
|
|
|
Called: make([]string, 0),
|
|
|
|
Containers: make(map[string]*FakeContainer),
|
|
|
|
Sandboxes: make(map[string]*FakePodSandbox),
|
|
|
|
FakeContainerStats: make(map[string]*runtimeapi.ContainerStats),
|
2016-08-02 01:53:29 +00:00
|
|
|
}
|
2016-08-01 22:13:36 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 07:27:27 +00:00
|
|
|
func (r *FakeRuntimeService) Version(apiVersion string) (*runtimeapi.VersionResponse, error) {
|
2016-08-02 01:53:29 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Called = append(r.Called, "Version")
|
|
|
|
|
2016-11-30 07:27:27 +00:00
|
|
|
return &runtimeapi.VersionResponse{
|
2017-01-20 01:54:28 +00:00
|
|
|
Version: version,
|
|
|
|
RuntimeName: FakeRuntimeName,
|
|
|
|
RuntimeVersion: version,
|
|
|
|
RuntimeApiVersion: version,
|
2016-08-02 01:53:29 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2016-11-30 07:27:27 +00:00
|
|
|
func (r *FakeRuntimeService) Status() (*runtimeapi.RuntimeStatus, error) {
|
2016-11-02 03:20:13 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Called = append(r.Called, "Status")
|
|
|
|
|
|
|
|
return r.FakeStatus, nil
|
|
|
|
}
|
|
|
|
|
2016-11-30 07:27:27 +00:00
|
|
|
func (r *FakeRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig) (string, error) {
|
2016-08-02 01:53:29 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
2016-09-07 13:38:56 +00:00
|
|
|
r.Called = append(r.Called, "RunPodSandbox")
|
2016-08-02 01:53:29 +00:00
|
|
|
|
|
|
|
// PodSandboxID should be randomized for real container runtime, but here just use
|
2016-08-17 08:04:25 +00:00
|
|
|
// fixed name from BuildSandboxName() for easily making fake sandboxes.
|
|
|
|
podSandboxID := BuildSandboxName(config.Metadata)
|
2016-12-28 14:31:56 +00:00
|
|
|
createdAt := time.Now().UnixNano()
|
2016-08-02 01:53:29 +00:00
|
|
|
r.Sandboxes[podSandboxID] = &FakePodSandbox{
|
2016-11-30 07:27:27 +00:00
|
|
|
PodSandboxStatus: runtimeapi.PodSandboxStatus{
|
2017-01-20 01:54:28 +00:00
|
|
|
Id: podSandboxID,
|
2016-10-17 09:22:42 +00:00
|
|
|
Metadata: config.Metadata,
|
2017-01-20 01:54:28 +00:00
|
|
|
State: runtimeapi.PodSandboxState_SANDBOX_READY,
|
|
|
|
CreatedAt: createdAt,
|
2016-11-30 07:27:27 +00:00
|
|
|
Network: &runtimeapi.PodSandboxNetworkStatus{
|
2017-01-20 01:54:28 +00:00
|
|
|
Ip: FakePodSandboxIP,
|
2016-10-17 09:22:42 +00:00
|
|
|
},
|
2016-08-17 08:04:25 +00:00
|
|
|
Labels: config.Labels,
|
|
|
|
Annotations: config.Annotations,
|
2016-08-02 01:53:29 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return podSandboxID, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *FakeRuntimeService) StopPodSandbox(podSandboxID string) error {
|
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Called = append(r.Called, "StopPodSandbox")
|
|
|
|
|
|
|
|
if s, ok := r.Sandboxes[podSandboxID]; ok {
|
2017-01-20 01:54:28 +00:00
|
|
|
s.State = runtimeapi.PodSandboxState_SANDBOX_NOTREADY
|
2016-08-02 01:53:29 +00:00
|
|
|
} else {
|
|
|
|
return fmt.Errorf("pod sandbox %s not found", podSandboxID)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-03 22:08:10 +00:00
|
|
|
func (r *FakeRuntimeService) RemovePodSandbox(podSandboxID string) error {
|
2016-08-02 01:53:29 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
2016-08-03 22:08:10 +00:00
|
|
|
r.Called = append(r.Called, "RemovePodSandbox")
|
2016-08-02 01:53:29 +00:00
|
|
|
|
|
|
|
// Remove the pod sandbox
|
|
|
|
delete(r.Sandboxes, podSandboxID)
|
|
|
|
|
|
|
|
return nil
|
2016-08-01 22:13:36 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 07:27:27 +00:00
|
|
|
func (r *FakeRuntimeService) PodSandboxStatus(podSandboxID string) (*runtimeapi.PodSandboxStatus, error) {
|
2016-08-02 01:53:29 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Called = append(r.Called, "PodSandboxStatus")
|
|
|
|
|
|
|
|
s, ok := r.Sandboxes[podSandboxID]
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("pod sandbox %q not found", podSandboxID)
|
|
|
|
}
|
|
|
|
|
2016-10-17 09:22:42 +00:00
|
|
|
status := s.PodSandboxStatus
|
|
|
|
return &status, nil
|
2016-08-01 22:13:36 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 07:27:27 +00:00
|
|
|
func (r *FakeRuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error) {
|
2016-08-02 01:53:29 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Called = append(r.Called, "ListPodSandbox")
|
|
|
|
|
2016-11-30 07:27:27 +00:00
|
|
|
result := make([]*runtimeapi.PodSandbox, 0)
|
2016-08-02 01:53:29 +00:00
|
|
|
for id, s := range r.Sandboxes {
|
|
|
|
if filter != nil {
|
2017-01-20 01:54:28 +00:00
|
|
|
if filter.Id != "" && filter.Id != id {
|
2016-08-02 01:53:29 +00:00
|
|
|
continue
|
|
|
|
}
|
2017-01-20 01:54:28 +00:00
|
|
|
if filter.State != nil && filter.GetState().State != s.State {
|
2016-08-02 01:53:29 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if filter.LabelSelector != nil && !filterInLabels(filter.LabelSelector, s.GetLabels()) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-30 07:27:27 +00:00
|
|
|
result = append(result, &runtimeapi.PodSandbox{
|
2016-09-23 09:37:32 +00:00
|
|
|
Id: s.Id,
|
|
|
|
Metadata: s.Metadata,
|
|
|
|
State: s.State,
|
|
|
|
CreatedAt: s.CreatedAt,
|
|
|
|
Labels: s.Labels,
|
|
|
|
Annotations: s.Annotations,
|
2016-08-02 01:53:29 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
2016-08-01 22:13:36 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 07:27:27 +00:00
|
|
|
func (r *FakeRuntimeService) PortForward(*runtimeapi.PortForwardRequest) (*runtimeapi.PortForwardResponse, error) {
|
2016-10-26 23:34:45 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Called = append(r.Called, "PortForward")
|
2016-11-30 07:27:27 +00:00
|
|
|
return &runtimeapi.PortForwardResponse{}, nil
|
2016-10-26 23:34:45 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 07:27:27 +00:00
|
|
|
func (r *FakeRuntimeService) CreateContainer(podSandboxID string, config *runtimeapi.ContainerConfig, sandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
|
2016-08-02 01:53:29 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Called = append(r.Called, "CreateContainer")
|
|
|
|
|
|
|
|
// ContainerID should be randomized for real container runtime, but here just use
|
2016-08-17 08:04:25 +00:00
|
|
|
// fixed BuildContainerName() for easily making fake containers.
|
2016-10-17 09:22:42 +00:00
|
|
|
containerID := BuildContainerName(config.Metadata, podSandboxID)
|
2016-12-28 14:31:56 +00:00
|
|
|
createdAt := time.Now().UnixNano()
|
2016-11-30 07:27:27 +00:00
|
|
|
createdState := runtimeapi.ContainerState_CONTAINER_CREATED
|
2017-01-20 01:54:28 +00:00
|
|
|
imageRef := config.Image.Image
|
2016-08-02 01:53:29 +00:00
|
|
|
r.Containers[containerID] = &FakeContainer{
|
2016-11-30 07:27:27 +00:00
|
|
|
ContainerStatus: runtimeapi.ContainerStatus{
|
2017-01-20 01:54:28 +00:00
|
|
|
Id: containerID,
|
2016-08-17 08:04:25 +00:00
|
|
|
Metadata: config.Metadata,
|
2016-08-02 01:53:29 +00:00
|
|
|
Image: config.Image,
|
2017-01-20 01:54:28 +00:00
|
|
|
ImageRef: imageRef,
|
|
|
|
CreatedAt: createdAt,
|
|
|
|
State: createdState,
|
2016-08-02 01:53:29 +00:00
|
|
|
Labels: config.Labels,
|
|
|
|
Annotations: config.Annotations,
|
|
|
|
},
|
|
|
|
SandboxID: podSandboxID,
|
|
|
|
}
|
|
|
|
|
|
|
|
return containerID, nil
|
2016-08-01 22:13:36 +00:00
|
|
|
}
|
|
|
|
|
2016-08-05 23:26:47 +00:00
|
|
|
func (r *FakeRuntimeService) StartContainer(containerID string) error {
|
2016-08-02 01:53:29 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Called = append(r.Called, "StartContainer")
|
|
|
|
|
2016-08-05 23:26:47 +00:00
|
|
|
c, ok := r.Containers[containerID]
|
2016-08-02 01:53:29 +00:00
|
|
|
if !ok {
|
2016-08-05 23:26:47 +00:00
|
|
|
return fmt.Errorf("container %s not found", containerID)
|
2016-08-02 01:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set container to running.
|
2017-01-20 01:54:28 +00:00
|
|
|
c.State = runtimeapi.ContainerState_CONTAINER_RUNNING
|
2016-12-28 14:31:56 +00:00
|
|
|
c.StartedAt = time.Now().UnixNano()
|
2016-08-02 01:53:29 +00:00
|
|
|
|
|
|
|
return nil
|
2016-08-01 22:13:36 +00:00
|
|
|
}
|
|
|
|
|
2016-08-05 23:26:47 +00:00
|
|
|
func (r *FakeRuntimeService) StopContainer(containerID string, timeout int64) error {
|
2016-08-02 01:53:29 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Called = append(r.Called, "StopContainer")
|
|
|
|
|
2016-08-05 23:26:47 +00:00
|
|
|
c, ok := r.Containers[containerID]
|
2016-08-02 01:53:29 +00:00
|
|
|
if !ok {
|
2016-08-05 23:26:47 +00:00
|
|
|
return fmt.Errorf("container %q not found", containerID)
|
2016-08-02 01:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set container to exited state.
|
2016-12-28 14:31:56 +00:00
|
|
|
finishedAt := time.Now().UnixNano()
|
2016-11-30 07:27:27 +00:00
|
|
|
exitedState := runtimeapi.ContainerState_CONTAINER_EXITED
|
2017-01-20 01:54:28 +00:00
|
|
|
c.State = exitedState
|
|
|
|
c.FinishedAt = finishedAt
|
2016-08-02 01:53:29 +00:00
|
|
|
|
|
|
|
return nil
|
2016-08-01 22:13:36 +00:00
|
|
|
}
|
|
|
|
|
2016-08-05 23:26:47 +00:00
|
|
|
func (r *FakeRuntimeService) RemoveContainer(containerID string) error {
|
2016-08-02 01:53:29 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Called = append(r.Called, "RemoveContainer")
|
|
|
|
|
|
|
|
// Remove the container
|
2016-08-05 23:26:47 +00:00
|
|
|
delete(r.Containers, containerID)
|
2016-08-02 01:53:29 +00:00
|
|
|
|
|
|
|
return nil
|
2016-08-01 22:13:36 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 07:27:27 +00:00
|
|
|
func (r *FakeRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error) {
|
2016-08-02 01:53:29 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Called = append(r.Called, "ListContainers")
|
|
|
|
|
2016-11-30 07:27:27 +00:00
|
|
|
result := make([]*runtimeapi.Container, 0)
|
2016-08-02 01:53:29 +00:00
|
|
|
for _, s := range r.Containers {
|
|
|
|
if filter != nil {
|
2017-01-20 01:54:28 +00:00
|
|
|
if filter.Id != "" && filter.Id != s.Id {
|
2016-08-02 01:53:29 +00:00
|
|
|
continue
|
|
|
|
}
|
2017-01-20 01:54:28 +00:00
|
|
|
if filter.PodSandboxId != "" && filter.PodSandboxId != s.SandboxID {
|
2016-08-02 01:53:29 +00:00
|
|
|
continue
|
|
|
|
}
|
2017-01-20 01:54:28 +00:00
|
|
|
if filter.State != nil && filter.GetState().State != s.State {
|
2016-08-02 01:53:29 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if filter.LabelSelector != nil && !filterInLabels(filter.LabelSelector, s.GetLabels()) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-30 07:27:27 +00:00
|
|
|
result = append(result, &runtimeapi.Container{
|
2016-08-24 04:48:13 +00:00
|
|
|
Id: s.Id,
|
|
|
|
CreatedAt: s.CreatedAt,
|
2017-01-20 01:54:28 +00:00
|
|
|
PodSandboxId: s.SandboxID,
|
2016-08-24 04:48:13 +00:00
|
|
|
Metadata: s.Metadata,
|
|
|
|
State: s.State,
|
|
|
|
Image: s.Image,
|
|
|
|
ImageRef: s.ImageRef,
|
|
|
|
Labels: s.Labels,
|
2016-09-23 09:37:32 +00:00
|
|
|
Annotations: s.Annotations,
|
2016-08-02 01:53:29 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
2016-08-01 22:13:36 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 07:27:27 +00:00
|
|
|
func (r *FakeRuntimeService) ContainerStatus(containerID string) (*runtimeapi.ContainerStatus, error) {
|
2016-08-02 01:53:29 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Called = append(r.Called, "ContainerStatus")
|
|
|
|
|
2016-08-05 23:26:47 +00:00
|
|
|
c, ok := r.Containers[containerID]
|
2016-08-02 01:53:29 +00:00
|
|
|
if !ok {
|
2016-08-05 23:26:47 +00:00
|
|
|
return nil, fmt.Errorf("container %q not found", containerID)
|
2016-08-02 01:53:29 +00:00
|
|
|
}
|
|
|
|
|
2016-10-17 09:22:42 +00:00
|
|
|
status := c.ContainerStatus
|
|
|
|
return &status, nil
|
2016-08-01 22:13:36 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 17:20:11 +00:00
|
|
|
func (r *FakeRuntimeService) UpdateContainerResources(string, *runtimeapi.LinuxContainerResources) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-10-26 23:34:45 +00:00
|
|
|
func (r *FakeRuntimeService) ExecSync(containerID string, cmd []string, timeout time.Duration) (stdout []byte, stderr []byte, err error) {
|
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Called = append(r.Called, "ExecSync")
|
|
|
|
return nil, nil, nil
|
|
|
|
}
|
|
|
|
|
2016-11-30 07:27:27 +00:00
|
|
|
func (r *FakeRuntimeService) Exec(*runtimeapi.ExecRequest) (*runtimeapi.ExecResponse, error) {
|
2016-08-02 01:53:29 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Called = append(r.Called, "Exec")
|
2016-11-30 07:27:27 +00:00
|
|
|
return &runtimeapi.ExecResponse{}, nil
|
2016-10-26 23:34:45 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 07:27:27 +00:00
|
|
|
func (r *FakeRuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeapi.AttachResponse, error) {
|
2016-10-26 23:34:45 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Called = append(r.Called, "Attach")
|
2016-11-30 07:27:27 +00:00
|
|
|
return &runtimeapi.AttachResponse{}, nil
|
2016-08-01 22:13:36 +00:00
|
|
|
}
|
2016-10-07 19:32:57 +00:00
|
|
|
|
2016-11-30 07:27:27 +00:00
|
|
|
func (r *FakeRuntimeService) UpdateRuntimeConfig(runtimeCOnfig *runtimeapi.RuntimeConfig) error {
|
2016-10-07 19:32:57 +00:00
|
|
|
return nil
|
|
|
|
}
|
2017-05-24 19:57:21 +00:00
|
|
|
|
2017-08-31 22:37:04 +00:00
|
|
|
func (r *FakeRuntimeService) SetFakeContainerStats(containerStats []*runtimeapi.ContainerStats) {
|
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.FakeContainerStats = make(map[string]*runtimeapi.ContainerStats)
|
|
|
|
for _, s := range containerStats {
|
|
|
|
r.FakeContainerStats[s.Attributes.Id] = s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-18 06:41:07 +00:00
|
|
|
func (r *FakeRuntimeService) ContainerStats(containerID string) (*runtimeapi.ContainerStats, error) {
|
2017-08-31 22:37:04 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Called = append(r.Called, "ContainerStats")
|
|
|
|
|
2017-09-18 06:41:07 +00:00
|
|
|
s, found := r.FakeContainerStats[containerID]
|
2017-08-31 22:37:04 +00:00
|
|
|
if !found {
|
2017-09-18 06:41:07 +00:00
|
|
|
return nil, fmt.Errorf("no stats for container %q", containerID)
|
2017-08-31 22:37:04 +00:00
|
|
|
}
|
2017-09-18 06:41:07 +00:00
|
|
|
return s, nil
|
2017-05-24 19:57:21 +00:00
|
|
|
}
|
|
|
|
|
2017-09-18 06:41:07 +00:00
|
|
|
func (r *FakeRuntimeService) ListContainerStats(filter *runtimeapi.ContainerStatsFilter) ([]*runtimeapi.ContainerStats, error) {
|
2017-08-31 22:37:04 +00:00
|
|
|
r.Lock()
|
|
|
|
defer r.Unlock()
|
|
|
|
|
|
|
|
r.Called = append(r.Called, "ListContainerStats")
|
|
|
|
|
|
|
|
var result []*runtimeapi.ContainerStats
|
|
|
|
for _, c := range r.Containers {
|
2017-09-18 06:41:07 +00:00
|
|
|
if filter != nil {
|
|
|
|
if filter.Id != "" && filter.Id != c.Id {
|
2017-08-31 22:37:04 +00:00
|
|
|
continue
|
|
|
|
}
|
2017-09-18 06:41:07 +00:00
|
|
|
if filter.PodSandboxId != "" && filter.PodSandboxId != c.SandboxID {
|
2017-08-31 22:37:04 +00:00
|
|
|
continue
|
|
|
|
}
|
2017-09-18 06:41:07 +00:00
|
|
|
if filter.LabelSelector != nil && !filterInLabels(filter.LabelSelector, c.GetLabels()) {
|
2017-08-31 22:37:04 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s, found := r.FakeContainerStats[c.Id]
|
|
|
|
if !found {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
result = append(result, s)
|
|
|
|
}
|
|
|
|
|
2017-09-18 06:41:07 +00:00
|
|
|
return result, nil
|
2017-05-24 19:57:21 +00:00
|
|
|
}
|