Commit 1c8d2558 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #46121 from Random-Liu/fix-kuberuntime-getpods

Automatic merge from submit-queue (batch tested with PRs 45996, 46121, 45707, 46011, 45564) Fix kuberuntime GetPods. The `ImageID` is not populated from `GetPods` in kuberuntime. Image garbage collector is using this field, https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/images/image_gc_manager.go#L204. Without this fix, image garbage collector will try to garbage collect all images every time. Because docker will not allow that, it should be fine. However, I'm not sure whether the unnecessary remove will cause any problem, e.g. overload docker image management system and make docker hang. @dchen1107 @yujuhong @feiskyer Do you think we should cherry-pick this?
parents ee9bab11 4935e119
...@@ -105,14 +105,14 @@ func (m *kubeGenericRuntimeManager) toKubeContainer(c *runtimeapi.Container) (*k ...@@ -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") return nil, fmt.Errorf("unable to convert a nil pointer to a runtime container")
} }
labeledInfo := getContainerInfoFromLabels(c.Labels)
annotatedInfo := getContainerInfoFromAnnotations(c.Annotations) annotatedInfo := getContainerInfoFromAnnotations(c.Annotations)
return &kubecontainer.Container{ return &kubecontainer.Container{
ID: kubecontainer.ContainerID{Type: m.runtimeName, ID: c.Id}, ID: kubecontainer.ContainerID{Type: m.runtimeName, ID: c.Id},
Name: labeledInfo.ContainerName, Name: c.GetMetadata().GetName(),
Image: c.Image.Image, ImageID: c.ImageRef,
Hash: annotatedInfo.Hash, Image: c.Image.Image,
State: toKubeContainerState(c.State), Hash: annotatedInfo.Hash,
State: toKubeContainerState(c.State),
}, nil }, nil
} }
......
...@@ -22,6 +22,9 @@ import ( ...@@ -22,6 +22,9 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/api/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) { func TestStableKey(t *testing.T) {
...@@ -86,3 +89,36 @@ func TestGetSystclsFromAnnotations(t *testing.T) { ...@@ -86,3 +89,36 @@ func TestGetSystclsFromAnnotations(t *testing.T) {
assert.Equal(t, test.expectedSysctls, actualSysctls, "TestCase[%d]", i) 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)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment