kubelet/api: update cri to protobuf v3

This commit is contained in:
Pengfei Ni
2017-01-20 09:54:28 +08:00
parent 9cab3b4a07
commit 97fff6a7cf
3 changed files with 35 additions and 39 deletions

View File

@@ -57,8 +57,8 @@ func NewFakeImageService() *FakeImageService {
func (r *FakeImageService) makeFakeImage(image string) *runtimeapi.Image { func (r *FakeImageService) makeFakeImage(image string) *runtimeapi.Image {
return &runtimeapi.Image{ return &runtimeapi.Image{
Id: &image, Id: image,
Size_: &r.FakeImageSize, Size_: r.FakeImageSize,
RepoTags: []string{image}, RepoTags: []string{image},
} }
} }
@@ -72,7 +72,7 @@ func (r *FakeImageService) ListImages(filter *runtimeapi.ImageFilter) ([]*runtim
images := make([]*runtimeapi.Image, 0) images := make([]*runtimeapi.Image, 0)
for _, img := range r.Images { for _, img := range r.Images {
if filter != nil && filter.Image != nil { if filter != nil && filter.Image != nil {
if !sliceutils.StringInSlice(filter.Image.GetImage(), img.RepoTags) { if !sliceutils.StringInSlice(filter.Image.Image, img.RepoTags) {
continue continue
} }
} }
@@ -88,7 +88,7 @@ func (r *FakeImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimeapi
r.Called = append(r.Called, "ImageStatus") r.Called = append(r.Called, "ImageStatus")
return r.Images[image.GetImage()], nil return r.Images[image.Image], nil
} }
func (r *FakeImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig) (string, error) { func (r *FakeImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig) (string, error) {
@@ -99,9 +99,9 @@ func (r *FakeImageService) PullImage(image *runtimeapi.ImageSpec, auth *runtimea
// ImageID should be randomized for real container runtime, but here just use // ImageID should be randomized for real container runtime, but here just use
// image's name for easily making fake images. // image's name for easily making fake images.
imageID := image.GetImage() imageID := image.Image
if _, ok := r.Images[imageID]; !ok { if _, ok := r.Images[imageID]; !ok {
r.Images[imageID] = r.makeFakeImage(image.GetImage()) r.Images[imageID] = r.makeFakeImage(image.Image)
} }
return imageID, nil return imageID, nil
@@ -114,7 +114,7 @@ func (r *FakeImageService) RemoveImage(image *runtimeapi.ImageSpec) error {
r.Called = append(r.Called, "RemoveImage") r.Called = append(r.Called, "RemoveImage")
// Remove the image // Remove the image
delete(r.Images, image.GetImage()) delete(r.Images, image.Image)
return nil return nil
} }

View File

@@ -61,7 +61,7 @@ func (r *FakeRuntimeService) SetFakeSandboxes(sandboxes []*FakePodSandbox) {
r.Sandboxes = make(map[string]*FakePodSandbox) r.Sandboxes = make(map[string]*FakePodSandbox)
for _, sandbox := range sandboxes { for _, sandbox := range sandboxes {
sandboxID := sandbox.GetId() sandboxID := sandbox.Id
r.Sandboxes[sandboxID] = sandbox r.Sandboxes[sandboxID] = sandbox
} }
} }
@@ -72,7 +72,7 @@ func (r *FakeRuntimeService) SetFakeContainers(containers []*FakeContainer) {
r.Containers = make(map[string]*FakeContainer) r.Containers = make(map[string]*FakeContainer)
for _, c := range containers { for _, c := range containers {
containerID := c.GetId() containerID := c.Id
r.Containers[containerID] = c r.Containers[containerID] = c
} }
@@ -103,10 +103,10 @@ func (r *FakeRuntimeService) Version(apiVersion string) (*runtimeapi.VersionResp
r.Called = append(r.Called, "Version") r.Called = append(r.Called, "Version")
return &runtimeapi.VersionResponse{ return &runtimeapi.VersionResponse{
Version: &version, Version: version,
RuntimeName: &FakeRuntimeName, RuntimeName: FakeRuntimeName,
RuntimeVersion: &version, RuntimeVersion: version,
RuntimeApiVersion: &version, RuntimeApiVersion: version,
}, nil }, nil
} }
@@ -129,15 +129,14 @@ func (r *FakeRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig)
// fixed name from BuildSandboxName() for easily making fake sandboxes. // fixed name from BuildSandboxName() for easily making fake sandboxes.
podSandboxID := BuildSandboxName(config.Metadata) podSandboxID := BuildSandboxName(config.Metadata)
createdAt := time.Now().Unix() createdAt := time.Now().Unix()
readyState := runtimeapi.PodSandboxState_SANDBOX_READY
r.Sandboxes[podSandboxID] = &FakePodSandbox{ r.Sandboxes[podSandboxID] = &FakePodSandbox{
PodSandboxStatus: runtimeapi.PodSandboxStatus{ PodSandboxStatus: runtimeapi.PodSandboxStatus{
Id: &podSandboxID, Id: podSandboxID,
Metadata: config.Metadata, Metadata: config.Metadata,
State: &readyState, State: runtimeapi.PodSandboxState_SANDBOX_READY,
CreatedAt: &createdAt, CreatedAt: createdAt,
Network: &runtimeapi.PodSandboxNetworkStatus{ Network: &runtimeapi.PodSandboxNetworkStatus{
Ip: &FakePodSandboxIP, Ip: FakePodSandboxIP,
}, },
Labels: config.Labels, Labels: config.Labels,
Annotations: config.Annotations, Annotations: config.Annotations,
@@ -153,9 +152,8 @@ func (r *FakeRuntimeService) StopPodSandbox(podSandboxID string) error {
r.Called = append(r.Called, "StopPodSandbox") r.Called = append(r.Called, "StopPodSandbox")
notReadyState := runtimeapi.PodSandboxState_SANDBOX_NOTREADY
if s, ok := r.Sandboxes[podSandboxID]; ok { if s, ok := r.Sandboxes[podSandboxID]; ok {
s.State = &notReadyState s.State = runtimeapi.PodSandboxState_SANDBOX_NOTREADY
} else { } else {
return fmt.Errorf("pod sandbox %s not found", podSandboxID) return fmt.Errorf("pod sandbox %s not found", podSandboxID)
} }
@@ -199,10 +197,10 @@ func (r *FakeRuntimeService) ListPodSandbox(filter *runtimeapi.PodSandboxFilter)
result := make([]*runtimeapi.PodSandbox, 0) result := make([]*runtimeapi.PodSandbox, 0)
for id, s := range r.Sandboxes { for id, s := range r.Sandboxes {
if filter != nil { if filter != nil {
if filter.Id != nil && filter.GetId() != id { if filter.Id != "" && filter.Id != id {
continue continue
} }
if filter.State != nil && filter.GetState() != s.GetState() { if filter.State != nil && filter.GetState().State != s.State {
continue continue
} }
if filter.LabelSelector != nil && !filterInLabels(filter.LabelSelector, s.GetLabels()) { if filter.LabelSelector != nil && !filterInLabels(filter.LabelSelector, s.GetLabels()) {
@@ -242,15 +240,15 @@ func (r *FakeRuntimeService) CreateContainer(podSandboxID string, config *runtim
containerID := BuildContainerName(config.Metadata, podSandboxID) containerID := BuildContainerName(config.Metadata, podSandboxID)
createdAt := time.Now().Unix() createdAt := time.Now().Unix()
createdState := runtimeapi.ContainerState_CONTAINER_CREATED createdState := runtimeapi.ContainerState_CONTAINER_CREATED
imageRef := config.Image.GetImage() imageRef := config.Image.Image
r.Containers[containerID] = &FakeContainer{ r.Containers[containerID] = &FakeContainer{
ContainerStatus: runtimeapi.ContainerStatus{ ContainerStatus: runtimeapi.ContainerStatus{
Id: &containerID, Id: containerID,
Metadata: config.Metadata, Metadata: config.Metadata,
Image: config.Image, Image: config.Image,
ImageRef: &imageRef, ImageRef: imageRef,
CreatedAt: &createdAt, CreatedAt: createdAt,
State: &createdState, State: createdState,
Labels: config.Labels, Labels: config.Labels,
Annotations: config.Annotations, Annotations: config.Annotations,
}, },
@@ -272,10 +270,8 @@ func (r *FakeRuntimeService) StartContainer(containerID string) error {
} }
// Set container to running. // Set container to running.
startedAt := time.Now().Unix() c.State = runtimeapi.ContainerState_CONTAINER_RUNNING
runningState := runtimeapi.ContainerState_CONTAINER_RUNNING c.StartedAt = time.Now().Unix()
c.State = &runningState
c.StartedAt = &startedAt
return nil return nil
} }
@@ -294,8 +290,8 @@ func (r *FakeRuntimeService) StopContainer(containerID string, timeout int64) er
// Set container to exited state. // Set container to exited state.
finishedAt := time.Now().Unix() finishedAt := time.Now().Unix()
exitedState := runtimeapi.ContainerState_CONTAINER_EXITED exitedState := runtimeapi.ContainerState_CONTAINER_EXITED
c.State = &exitedState c.State = exitedState
c.FinishedAt = &finishedAt c.FinishedAt = finishedAt
return nil return nil
} }
@@ -321,13 +317,13 @@ func (r *FakeRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter)
result := make([]*runtimeapi.Container, 0) result := make([]*runtimeapi.Container, 0)
for _, s := range r.Containers { for _, s := range r.Containers {
if filter != nil { if filter != nil {
if filter.Id != nil && filter.GetId() != s.GetId() { if filter.Id != "" && filter.Id != s.Id {
continue continue
} }
if filter.PodSandboxId != nil && filter.GetPodSandboxId() != s.SandboxID { if filter.PodSandboxId != "" && filter.PodSandboxId != s.SandboxID {
continue continue
} }
if filter.State != nil && filter.GetState() != s.GetState() { if filter.State != nil && filter.GetState().State != s.State {
continue continue
} }
if filter.LabelSelector != nil && !filterInLabels(filter.LabelSelector, s.GetLabels()) { if filter.LabelSelector != nil && !filterInLabels(filter.LabelSelector, s.GetLabels()) {
@@ -338,7 +334,7 @@ func (r *FakeRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter)
result = append(result, &runtimeapi.Container{ result = append(result, &runtimeapi.Container{
Id: s.Id, Id: s.Id,
CreatedAt: s.CreatedAt, CreatedAt: s.CreatedAt,
PodSandboxId: &s.SandboxID, PodSandboxId: s.SandboxID,
Metadata: s.Metadata, Metadata: s.Metadata,
State: s.State, State: s.State,
Image: s.Image, Image: s.Image,

View File

@@ -24,11 +24,11 @@ import (
func BuildContainerName(metadata *runtimeapi.ContainerMetadata, sandboxID string) string { func BuildContainerName(metadata *runtimeapi.ContainerMetadata, sandboxID string) string {
// include the sandbox ID to make the container ID unique. // include the sandbox ID to make the container ID unique.
return fmt.Sprintf("%s_%s_%d", sandboxID, metadata.GetName(), metadata.GetAttempt()) return fmt.Sprintf("%s_%s_%d", sandboxID, metadata.Name, metadata.Attempt)
} }
func BuildSandboxName(metadata *runtimeapi.PodSandboxMetadata) string { func BuildSandboxName(metadata *runtimeapi.PodSandboxMetadata) string {
return fmt.Sprintf("%s_%s_%s_%d", metadata.GetName(), metadata.GetNamespace(), metadata.GetUid(), metadata.GetAttempt()) return fmt.Sprintf("%s_%s_%s_%d", metadata.Name, metadata.Namespace, metadata.Uid, metadata.Attempt)
} }
func filterInLabels(filter, labels map[string]string) bool { func filterInLabels(filter, labels map[string]string) bool {