Skip to content

Commit bef915d

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#35930 from Random-Liu/handle-empty-container-name
Automatic merge from submit-queue CRI: Handle empty container name in dockershim. Fixes kubernetes#35924. Dead container may have no name, we should handle this properly. @yujuhong @bprashanth
2 parents 06f75b7 + ecd1044 commit bef915d

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

pkg/kubelet/dockershim/convert.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ func toPullableImageID(id string, image *dockertypes.ImageInspect) string {
7777

7878
func toRuntimeAPIContainer(c *dockertypes.Container) (*runtimeApi.Container, error) {
7979
state := toRuntimeAPIContainerState(c.Status)
80+
if len(c.Names) == 0 {
81+
return nil, fmt.Errorf("unexpected empty container name: %+v", c)
82+
}
8083
metadata, err := parseContainerName(c.Names[0])
8184
if err != nil {
8285
return nil, err
@@ -141,6 +144,9 @@ func toRuntimeAPISandboxState(state string) runtimeApi.PodSandboxState {
141144

142145
func toRuntimeAPISandbox(c *dockertypes.Container) (*runtimeApi.PodSandbox, error) {
143146
state := toRuntimeAPISandboxState(c.Status)
147+
if len(c.Names) == 0 {
148+
return nil, fmt.Errorf("unexpected empty sandbox name: %+v", c)
149+
}
144150
metadata, err := parseSandboxName(c.Names[0])
145151
if err != nil {
146152
return nil, err

pkg/kubelet/dockershim/docker_container.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (ds *dockerService) ListContainers(filter *runtimeApi.ContainerFilter) ([]*
6969

7070
converted, err := toRuntimeAPIContainer(&c)
7171
if err != nil {
72-
glog.V(5).Infof("Unable to convert docker to runtime API container: %v", err)
72+
glog.V(4).Infof("Unable to convert docker to runtime API container: %v", err)
7373
continue
7474
}
7575

pkg/kubelet/dockershim/docker_sandbox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func (ds *dockerService) ListPodSandbox(filter *runtimeApi.PodSandboxFilter) ([]
274274
c := containers[i]
275275
converted, err := toRuntimeAPISandbox(&c)
276276
if err != nil {
277-
glog.V(5).Infof("Unable to convert docker to runtime API sandbox: %v", err)
277+
glog.V(4).Infof("Unable to convert docker to runtime API sandbox: %v", err)
278278
continue
279279
}
280280
if filterOutReadySandboxes && converted.GetState() == runtimeApi.PodSandboxState_SANDBOX_READY {

0 commit comments

Comments
 (0)