github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/edge/pkg/edged/apis/types.go (about)

     1  package apis
     2  
     3  import (
     4  	"errors"
     5  	"time"
     6  
     7  	"github.com/docker/docker/api/types/container"
     8  	kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
     9  )
    10  
    11  const (
    12  	// NvidiaGPUStatusAnnotationKey is the key of the node annotation for GPU status
    13  	NvidiaGPUStatusAnnotationKey = "huawei.com/gpu-status"
    14  	// NvidiaGPUDecisionAnnotationKey is the key of the pod annotation for scheduler GPU decision
    15  	NvidiaGPUDecisionAnnotationKey = "huawei.com/gpu-decision"
    16  	// NvidiaGPUScalarResourceName is the device plugin resource name used for special handling
    17  	NvidiaGPUScalarResourceName = "nvidia.com/gpu"
    18  	// NvidiaGPUMaxUsage is the maximum possible usage of a GPU in millis
    19  	NvidiaGPUMaxUsage = 1000
    20  	// NvidiaGPUResource is the extend resource name
    21  	NvidiaGPUResource = "alpha.kubernetes.io/nvidia-gpu"
    22  	//StatusTag is to compare status of resources
    23  	StatusTag = "StatusTag"
    24  )
    25  
    26  // Container defines container object
    27  type Container struct {
    28  	// ID of the container.
    29  	ID string `json:"id,omitempty"`
    30  	// Status of the container.
    31  	Status  kubecontainer.ContainerState `json:"status,omitempty"`
    32  	StartAt time.Time                    `json:"startat,omitempty"`
    33  }
    34  
    35  // Device specifies a host device to mount into a container.
    36  type Device struct {
    37  	// Path of the device within the container.
    38  	ContainerPath string `json:"container_path,omitempty"`
    39  	// Path of the device on the host.
    40  	HostPath string `json:"host_path,omitempty"`
    41  	// Cgroups permissions of the device, candidates are one or more of
    42  	// * r - allows container to read from the specified device.
    43  	// * w - allows container to write to the specified device.
    44  	// * m - allows container to create device files that do not yet exist.
    45  	Permissions string `json:"permissions,omitempty"`
    46  }
    47  
    48  // ContainerConfig defines container configuration details
    49  type ContainerConfig struct {
    50  	Name       string
    51  	Config     *container.Config
    52  	HostConfig *container.HostConfig
    53  }
    54  
    55  // ContainerInspect is container inspect
    56  type ContainerInspect struct {
    57  	Status ContainerStatus `json:"Status,omitempty"`
    58  }
    59  
    60  // ContainerStatus represents the status of a container.
    61  type ContainerStatus struct {
    62  	kubecontainer.ContainerStatus
    63  	// Reference to the image in use. For most runtimes, this should be an
    64  	// image ID
    65  	ImageRef string `json:"image_ref,omitempty"`
    66  	// Key-value pairs that may be used to scope and select individual resources.
    67  	Labels map[string]string `json:"labels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
    68  	// Log path of container.
    69  	LogPath      string `json:"log_path,omitempty"`
    70  	RestartCount int32  `json:"restartCount"`
    71  }
    72  
    73  //error variables
    74  var (
    75  	ErrPodNotFound       = errors.New("PodNotFound")
    76  	ErrContainerNotFound = errors.New("ContainerNotFound")
    77  	ErrPodStartBackOff   = errors.New("PodStartBackOff")
    78  )
    79  
    80  // RuntimeService is docker runtime service
    81  type RuntimeService interface {
    82  	Version() (kubecontainer.Version, error)
    83  	CreateContainer(config *ContainerConfig) (string, error)
    84  	StartContainer(containerID string) error
    85  	StopContainer(containerID string, timeout uint32) error
    86  	DeleteContainer(containerID kubecontainer.ContainerID) error
    87  	ListContainers() ([]*Container, error)
    88  	ContainerStatus(containerID string) (*ContainerStatus, error)
    89  	InspectContainer(containerID string) (*ContainerInspect, error)
    90  }
    91  
    92  // constants for defining prefix in docker
    93  const (
    94  	DockerPrefix         = "docker://"
    95  	DockerPullablePrefix = "docker-pullable://"
    96  )