Merge pull request #35930 from Random-Liu/handle-empty-container-name
Automatic merge from submit-queue CRI: Handle empty container name in dockershim. Fixes https://github.com/kubernetes/kubernetes/issues/35924. Dead container may have no name, we should handle this properly. @yujuhong @bprashanth
This commit is contained in:
		@@ -77,6 +77,9 @@ func toPullableImageID(id string, image *dockertypes.ImageInspect) string {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func toRuntimeAPIContainer(c *dockertypes.Container) (*runtimeApi.Container, error) {
 | 
					func toRuntimeAPIContainer(c *dockertypes.Container) (*runtimeApi.Container, error) {
 | 
				
			||||||
	state := toRuntimeAPIContainerState(c.Status)
 | 
						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])
 | 
						metadata, err := parseContainerName(c.Names[0])
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
@@ -141,6 +144,9 @@ func toRuntimeAPISandboxState(state string) runtimeApi.PodSandboxState {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func toRuntimeAPISandbox(c *dockertypes.Container) (*runtimeApi.PodSandbox, error) {
 | 
					func toRuntimeAPISandbox(c *dockertypes.Container) (*runtimeApi.PodSandbox, error) {
 | 
				
			||||||
	state := toRuntimeAPISandboxState(c.Status)
 | 
						state := toRuntimeAPISandboxState(c.Status)
 | 
				
			||||||
 | 
						if len(c.Names) == 0 {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("unexpected empty sandbox name: %+v", c)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	metadata, err := parseSandboxName(c.Names[0])
 | 
						metadata, err := parseSandboxName(c.Names[0])
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -69,7 +69,7 @@ func (ds *dockerService) ListContainers(filter *runtimeApi.ContainerFilter) ([]*
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		converted, err := toRuntimeAPIContainer(&c)
 | 
							converted, err := toRuntimeAPIContainer(&c)
 | 
				
			||||||
		if err != nil {
 | 
							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
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -274,7 +274,7 @@ func (ds *dockerService) ListPodSandbox(filter *runtimeApi.PodSandboxFilter) ([]
 | 
				
			|||||||
		c := containers[i]
 | 
							c := containers[i]
 | 
				
			||||||
		converted, err := toRuntimeAPISandbox(&c)
 | 
							converted, err := toRuntimeAPISandbox(&c)
 | 
				
			||||||
		if err != nil {
 | 
							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
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if filterOutReadySandboxes && converted.GetState() == runtimeApi.PodSandboxState_SANDBOX_READY {
 | 
							if filterOutReadySandboxes && converted.GetState() == runtimeApi.PodSandboxState_SANDBOX_READY {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user