Fix kuberuntime GetPods.
This commit is contained in:
		| @@ -105,14 +105,14 @@ func (m *kubeGenericRuntimeManager) toKubeContainer(c *runtimeapi.Container) (*k | ||||
| 		return nil, fmt.Errorf("unable to convert a nil pointer to a runtime container") | ||||
| 	} | ||||
|  | ||||
| 	labeledInfo := getContainerInfoFromLabels(c.Labels) | ||||
| 	annotatedInfo := getContainerInfoFromAnnotations(c.Annotations) | ||||
| 	return &kubecontainer.Container{ | ||||
| 		ID:    kubecontainer.ContainerID{Type: m.runtimeName, ID: c.Id}, | ||||
| 		Name:  labeledInfo.ContainerName, | ||||
| 		Image: c.Image.Image, | ||||
| 		Hash:  annotatedInfo.Hash, | ||||
| 		State: toKubeContainerState(c.State), | ||||
| 		ID:      kubecontainer.ContainerID{Type: m.runtimeName, ID: c.Id}, | ||||
| 		Name:    c.GetMetadata().GetName(), | ||||
| 		ImageID: c.ImageRef, | ||||
| 		Image:   c.Image.Image, | ||||
| 		Hash:    annotatedInfo.Hash, | ||||
| 		State:   toKubeContainerState(c.State), | ||||
| 	}, nil | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -22,6 +22,9 @@ import ( | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||
| 	"k8s.io/kubernetes/pkg/api/v1" | ||||
| 	runtimetesting "k8s.io/kubernetes/pkg/kubelet/apis/cri/testing" | ||||
| 	runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1" | ||||
| 	kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" | ||||
| ) | ||||
|  | ||||
| func TestStableKey(t *testing.T) { | ||||
| @@ -86,3 +89,36 @@ func TestGetSystclsFromAnnotations(t *testing.T) { | ||||
| 		assert.Equal(t, test.expectedSysctls, actualSysctls, "TestCase[%d]", i) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestToKubeContainer(t *testing.T) { | ||||
| 	c := &runtimeapi.Container{ | ||||
| 		Id: "test-id", | ||||
| 		Metadata: &runtimeapi.ContainerMetadata{ | ||||
| 			Name:    "test-name", | ||||
| 			Attempt: 1, | ||||
| 		}, | ||||
| 		Image:    &runtimeapi.ImageSpec{Image: "test-image"}, | ||||
| 		ImageRef: "test-image-ref", | ||||
| 		State:    runtimeapi.ContainerState_CONTAINER_RUNNING, | ||||
| 		Annotations: map[string]string{ | ||||
| 			containerHashLabel: "1234", | ||||
| 		}, | ||||
| 	} | ||||
| 	expect := &kubecontainer.Container{ | ||||
| 		ID: kubecontainer.ContainerID{ | ||||
| 			Type: runtimetesting.FakeRuntimeName, | ||||
| 			ID:   "test-id", | ||||
| 		}, | ||||
| 		Name:    "test-name", | ||||
| 		ImageID: "test-image-ref", | ||||
| 		Image:   "test-image", | ||||
| 		Hash:    uint64(0x1234), | ||||
| 		State:   kubecontainer.ContainerStateRunning, | ||||
| 	} | ||||
|  | ||||
| 	_, _, m, err := createTestRuntimeManager() | ||||
| 	assert.NoError(t, err) | ||||
| 	got, err := m.toKubeContainer(c) | ||||
| 	assert.NoError(t, err) | ||||
| 	assert.Equal(t, expect, got) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Random-Liu
					Random-Liu