kubelet/api: update cri to protobuf v3
This commit is contained in:
		@@ -57,8 +57,8 @@ func NewFakeImageService() *FakeImageService {
 | 
			
		||||
 | 
			
		||||
func (r *FakeImageService) makeFakeImage(image string) *runtimeapi.Image {
 | 
			
		||||
	return &runtimeapi.Image{
 | 
			
		||||
		Id:       &image,
 | 
			
		||||
		Size_:    &r.FakeImageSize,
 | 
			
		||||
		Id:       image,
 | 
			
		||||
		Size_:    r.FakeImageSize,
 | 
			
		||||
		RepoTags: []string{image},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -72,7 +72,7 @@ func (r *FakeImageService) ListImages(filter *runtimeapi.ImageFilter) ([]*runtim
 | 
			
		||||
	images := make([]*runtimeapi.Image, 0)
 | 
			
		||||
	for _, img := range r.Images {
 | 
			
		||||
		if filter != nil && filter.Image != nil {
 | 
			
		||||
			if !sliceutils.StringInSlice(filter.Image.GetImage(), img.RepoTags) {
 | 
			
		||||
			if !sliceutils.StringInSlice(filter.Image.Image, img.RepoTags) {
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@@ -88,7 +88,7 @@ func (r *FakeImageService) ImageStatus(image *runtimeapi.ImageSpec) (*runtimeapi
 | 
			
		||||
 | 
			
		||||
	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) {
 | 
			
		||||
@@ -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
 | 
			
		||||
	// image's name for easily making fake images.
 | 
			
		||||
	imageID := image.GetImage()
 | 
			
		||||
	imageID := image.Image
 | 
			
		||||
	if _, ok := r.Images[imageID]; !ok {
 | 
			
		||||
		r.Images[imageID] = r.makeFakeImage(image.GetImage())
 | 
			
		||||
		r.Images[imageID] = r.makeFakeImage(image.Image)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return imageID, nil
 | 
			
		||||
@@ -114,7 +114,7 @@ func (r *FakeImageService) RemoveImage(image *runtimeapi.ImageSpec) error {
 | 
			
		||||
	r.Called = append(r.Called, "RemoveImage")
 | 
			
		||||
 | 
			
		||||
	// Remove the image
 | 
			
		||||
	delete(r.Images, image.GetImage())
 | 
			
		||||
	delete(r.Images, image.Image)
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ func (r *FakeRuntimeService) SetFakeSandboxes(sandboxes []*FakePodSandbox) {
 | 
			
		||||
 | 
			
		||||
	r.Sandboxes = make(map[string]*FakePodSandbox)
 | 
			
		||||
	for _, sandbox := range sandboxes {
 | 
			
		||||
		sandboxID := sandbox.GetId()
 | 
			
		||||
		sandboxID := sandbox.Id
 | 
			
		||||
		r.Sandboxes[sandboxID] = sandbox
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -72,7 +72,7 @@ func (r *FakeRuntimeService) SetFakeContainers(containers []*FakeContainer) {
 | 
			
		||||
 | 
			
		||||
	r.Containers = make(map[string]*FakeContainer)
 | 
			
		||||
	for _, c := range containers {
 | 
			
		||||
		containerID := c.GetId()
 | 
			
		||||
		containerID := c.Id
 | 
			
		||||
		r.Containers[containerID] = c
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -103,10 +103,10 @@ func (r *FakeRuntimeService) Version(apiVersion string) (*runtimeapi.VersionResp
 | 
			
		||||
	r.Called = append(r.Called, "Version")
 | 
			
		||||
 | 
			
		||||
	return &runtimeapi.VersionResponse{
 | 
			
		||||
		Version:           &version,
 | 
			
		||||
		RuntimeName:       &FakeRuntimeName,
 | 
			
		||||
		RuntimeVersion:    &version,
 | 
			
		||||
		RuntimeApiVersion: &version,
 | 
			
		||||
		Version:           version,
 | 
			
		||||
		RuntimeName:       FakeRuntimeName,
 | 
			
		||||
		RuntimeVersion:    version,
 | 
			
		||||
		RuntimeApiVersion: version,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -129,15 +129,14 @@ func (r *FakeRuntimeService) RunPodSandbox(config *runtimeapi.PodSandboxConfig)
 | 
			
		||||
	// fixed name from BuildSandboxName() for easily making fake sandboxes.
 | 
			
		||||
	podSandboxID := BuildSandboxName(config.Metadata)
 | 
			
		||||
	createdAt := time.Now().Unix()
 | 
			
		||||
	readyState := runtimeapi.PodSandboxState_SANDBOX_READY
 | 
			
		||||
	r.Sandboxes[podSandboxID] = &FakePodSandbox{
 | 
			
		||||
		PodSandboxStatus: runtimeapi.PodSandboxStatus{
 | 
			
		||||
			Id:        &podSandboxID,
 | 
			
		||||
			Id:        podSandboxID,
 | 
			
		||||
			Metadata:  config.Metadata,
 | 
			
		||||
			State:     &readyState,
 | 
			
		||||
			CreatedAt: &createdAt,
 | 
			
		||||
			State:     runtimeapi.PodSandboxState_SANDBOX_READY,
 | 
			
		||||
			CreatedAt: createdAt,
 | 
			
		||||
			Network: &runtimeapi.PodSandboxNetworkStatus{
 | 
			
		||||
				Ip: &FakePodSandboxIP,
 | 
			
		||||
				Ip: FakePodSandboxIP,
 | 
			
		||||
			},
 | 
			
		||||
			Labels:      config.Labels,
 | 
			
		||||
			Annotations: config.Annotations,
 | 
			
		||||
@@ -153,9 +152,8 @@ func (r *FakeRuntimeService) StopPodSandbox(podSandboxID string) error {
 | 
			
		||||
 | 
			
		||||
	r.Called = append(r.Called, "StopPodSandbox")
 | 
			
		||||
 | 
			
		||||
	notReadyState := runtimeapi.PodSandboxState_SANDBOX_NOTREADY
 | 
			
		||||
	if s, ok := r.Sandboxes[podSandboxID]; ok {
 | 
			
		||||
		s.State = ¬ReadyState
 | 
			
		||||
		s.State = runtimeapi.PodSandboxState_SANDBOX_NOTREADY
 | 
			
		||||
	} else {
 | 
			
		||||
		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)
 | 
			
		||||
	for id, s := range r.Sandboxes {
 | 
			
		||||
		if filter != nil {
 | 
			
		||||
			if filter.Id != nil && filter.GetId() != id {
 | 
			
		||||
			if filter.Id != "" && filter.Id != id {
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
			if filter.State != nil && filter.GetState() != s.GetState() {
 | 
			
		||||
			if filter.State != nil && filter.GetState().State != s.State {
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
			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)
 | 
			
		||||
	createdAt := time.Now().Unix()
 | 
			
		||||
	createdState := runtimeapi.ContainerState_CONTAINER_CREATED
 | 
			
		||||
	imageRef := config.Image.GetImage()
 | 
			
		||||
	imageRef := config.Image.Image
 | 
			
		||||
	r.Containers[containerID] = &FakeContainer{
 | 
			
		||||
		ContainerStatus: runtimeapi.ContainerStatus{
 | 
			
		||||
			Id:          &containerID,
 | 
			
		||||
			Id:          containerID,
 | 
			
		||||
			Metadata:    config.Metadata,
 | 
			
		||||
			Image:       config.Image,
 | 
			
		||||
			ImageRef:    &imageRef,
 | 
			
		||||
			CreatedAt:   &createdAt,
 | 
			
		||||
			State:       &createdState,
 | 
			
		||||
			ImageRef:    imageRef,
 | 
			
		||||
			CreatedAt:   createdAt,
 | 
			
		||||
			State:       createdState,
 | 
			
		||||
			Labels:      config.Labels,
 | 
			
		||||
			Annotations: config.Annotations,
 | 
			
		||||
		},
 | 
			
		||||
@@ -272,10 +270,8 @@ func (r *FakeRuntimeService) StartContainer(containerID string) error {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Set container to running.
 | 
			
		||||
	startedAt := time.Now().Unix()
 | 
			
		||||
	runningState := runtimeapi.ContainerState_CONTAINER_RUNNING
 | 
			
		||||
	c.State = &runningState
 | 
			
		||||
	c.StartedAt = &startedAt
 | 
			
		||||
	c.State = runtimeapi.ContainerState_CONTAINER_RUNNING
 | 
			
		||||
	c.StartedAt = time.Now().Unix()
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
@@ -294,8 +290,8 @@ func (r *FakeRuntimeService) StopContainer(containerID string, timeout int64) er
 | 
			
		||||
	// Set container to exited state.
 | 
			
		||||
	finishedAt := time.Now().Unix()
 | 
			
		||||
	exitedState := runtimeapi.ContainerState_CONTAINER_EXITED
 | 
			
		||||
	c.State = &exitedState
 | 
			
		||||
	c.FinishedAt = &finishedAt
 | 
			
		||||
	c.State = exitedState
 | 
			
		||||
	c.FinishedAt = finishedAt
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
@@ -321,13 +317,13 @@ func (r *FakeRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter)
 | 
			
		||||
	result := make([]*runtimeapi.Container, 0)
 | 
			
		||||
	for _, s := range r.Containers {
 | 
			
		||||
		if filter != nil {
 | 
			
		||||
			if filter.Id != nil && filter.GetId() != s.GetId() {
 | 
			
		||||
			if filter.Id != "" && filter.Id != s.Id {
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
			if filter.PodSandboxId != nil && filter.GetPodSandboxId() != s.SandboxID {
 | 
			
		||||
			if filter.PodSandboxId != "" && filter.PodSandboxId != s.SandboxID {
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
			if filter.State != nil && filter.GetState() != s.GetState() {
 | 
			
		||||
			if filter.State != nil && filter.GetState().State != s.State {
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
			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{
 | 
			
		||||
			Id:           s.Id,
 | 
			
		||||
			CreatedAt:    s.CreatedAt,
 | 
			
		||||
			PodSandboxId: &s.SandboxID,
 | 
			
		||||
			PodSandboxId: s.SandboxID,
 | 
			
		||||
			Metadata:     s.Metadata,
 | 
			
		||||
			State:        s.State,
 | 
			
		||||
			Image:        s.Image,
 | 
			
		||||
 
 | 
			
		||||
@@ -24,11 +24,11 @@ import (
 | 
			
		||||
 | 
			
		||||
func BuildContainerName(metadata *runtimeapi.ContainerMetadata, sandboxID string) string {
 | 
			
		||||
	// 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 {
 | 
			
		||||
	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 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user