mirror of https://github.com/k3s-io/k3s
Merge pull request #54125 from feiskyer/docker-images
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.
Fix dockershim panic when listing images
**What this PR does / why we need it**:
dockershim panic when listing containers because of `opts.Filters` not initialized:
505ccb88da/pkg/kubelet/dockershim/docker_image.go (L35-L39)
Also when imgSpec.Image is empty string, dockershim returns an empty image list which is not expected. (We should not set opts.Filters in this case).
**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #54122
**Special notes for your reviewer**:
**Release note**:
```release-note
NONE
```
pull/6/head
commit
ba66fcb63d
|
@ -21,6 +21,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
dockertypes "github.com/docker/docker/api/types"
|
dockertypes "github.com/docker/docker/api/types"
|
||||||
|
dockerfilters "github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/pkg/jsonmessage"
|
"github.com/docker/docker/pkg/jsonmessage"
|
||||||
|
|
||||||
runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
runtimeapi "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
||||||
|
@ -33,8 +34,9 @@ import (
|
||||||
func (ds *dockerService) ListImages(filter *runtimeapi.ImageFilter) ([]*runtimeapi.Image, error) {
|
func (ds *dockerService) ListImages(filter *runtimeapi.ImageFilter) ([]*runtimeapi.Image, error) {
|
||||||
opts := dockertypes.ImageListOptions{}
|
opts := dockertypes.ImageListOptions{}
|
||||||
if filter != nil {
|
if filter != nil {
|
||||||
if imgSpec := filter.GetImage(); imgSpec != nil {
|
if filter.GetImage().GetImage() != "" {
|
||||||
opts.Filters.Add("reference", imgSpec.Image)
|
opts.Filters = dockerfilters.NewArgs()
|
||||||
|
opts.Filters.Add("reference", filter.GetImage().GetImage())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue