Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRI: Handle empty container name in dockershim. #35930

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/kubelet/dockershim/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func toPullableImageID(id string, image *dockertypes.ImageInspect) string {

func toRuntimeAPIContainer(c *dockertypes.Container) (*runtimeApi.Container, error) {
state := toRuntimeAPIContainerState(c.Status)
if len(c.Names) == 0 {
return nil, fmt.Errorf("unexpected empty container name: %+v", c)
}
metadata, err := parseContainerName(c.Names[0])
if err != nil {
return nil, err
Expand Down Expand Up @@ -141,6 +144,9 @@ func toRuntimeAPISandboxState(state string) runtimeApi.PodSandBoxState {

func toRuntimeAPISandbox(c *dockertypes.Container) (*runtimeApi.PodSandbox, error) {
state := toRuntimeAPISandboxState(c.Status)
if len(c.Names) == 0 {
return nil, fmt.Errorf("unexpected empty sandbox name: %+v", c)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this lead to inconsistencies like create 2 of the same container for a given pod? if a container doesn't show up in list, it's deemed non-existent right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen a running docker container that doesn't have a name, so the likelihood should be low?
Even if we do report the container, since it's missing important metadata (name, and who knows what else) associated with the container, kubelet might not be able to recognize it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the comment in the docker issue, I think he implies that only dead container may have no name. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so never restart a reastart:never pod then? I'm not sure what "Dead" means in this context even, something was docker rm'd while it had live mounts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Dead": it's usually the result of a container failing to be stopped/removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so never restart a reastart:never pod then?

It's possible that kubelet will restart a restart:never pod in this case, since it cannot recognize the container anymore.
The last time I encountered this bug (#21085 (comment)), it was with docker v1.9. Haven't seen it happen on a newer docker version.
This stackoverflow question/answer has more information.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SG, might be worth plumbing through as an event or log, so we know it hits when we debug.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think logs might be better in this case. We can log the content of dockertypes.Container.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR includes types.Container in the error, and the error is logged in the caller.

However, I found the log in the caller is V(5). I'll change it to V(4).

}
metadata, err := parseSandboxName(c.Names[0])
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/dockershim/docker_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (ds *dockerService) ListContainers(filter *runtimeApi.ContainerFilter) ([]*

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

Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/dockershim/docker_sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (ds *dockerService) ListPodSandbox(filter *runtimeApi.PodSandboxFilter) ([]
c := containers[i]
converted, err := toRuntimeAPISandbox(&c)
if err != nil {
glog.V(5).Infof("Unable to convert docker to runtime API sandbox: %v", err)
glog.V(4).Infof("Unable to convert docker to runtime API sandbox: %v", err)
continue
}
if filterOutReadySandboxes && converted.GetState() == runtimeApi.PodSandBoxState_READY {
Expand Down