Skip to content

Commit

Permalink
Merge pull request #46251 from Random-Liu/automated-cherry-pick-of-#4…
Browse files Browse the repository at this point in the history
…6121-upstream-release-1.6

Automatic merge from submit-queue

Automated cherry pick of #46121

Cherry pick of #46121 on release-1.6.

#46121: Fix kuberuntime GetPods.
  • Loading branch information
Kubernetes Submit Queue committed May 23, 2017
2 parents 70a5c83 + 8f0585a commit 37b7193
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/kubelet/kuberuntime/helpers.go
Expand Up @@ -104,14 +104,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().Name,
ImageID: c.ImageRef,
Image: c.Image.Image,
Hash: annotatedInfo.Hash,
State: toKubeContainerState(c.State),
}, nil
}

Expand Down
36 changes: 36 additions & 0 deletions pkg/kubelet/kuberuntime/helpers_test.go
Expand Up @@ -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/api/testing"
runtimeapi "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
)

func TestStableKey(t *testing.T) {
Expand All @@ -46,3 +49,36 @@ func TestStableKey(t *testing.T) {
newKey := getStableKey(pod, container)
assert.NotEqual(t, oldKey, newKey)
}

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)
}

0 comments on commit 37b7193

Please sign in to comment.