mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 08:17:26 +00:00
Small bug fixes in fake docker client.
This commit is contained in:
parent
de922962de
commit
201866af20
@ -51,7 +51,7 @@ func imageToRuntimeAPIImage(image *dockertypes.Image) (*runtimeapi.Image, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func imageInspectToRuntimeAPIImage(image *dockertypes.ImageInspect) (*runtimeapi.Image, error) {
|
func imageInspectToRuntimeAPIImage(image *dockertypes.ImageInspect) (*runtimeapi.Image, error) {
|
||||||
if image == nil {
|
if image == nil || image.Config == nil {
|
||||||
return nil, fmt.Errorf("unable to convert a nil pointer to a runtime API image")
|
return nil, fmt.Errorf("unable to convert a nil pointer to a runtime API image")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ func (ds *dockerService) createContainerLogSymlink(containerID string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get container %q log path: %v", containerID, err)
|
return fmt.Errorf("failed to get container %q log path: %v", containerID, err)
|
||||||
}
|
}
|
||||||
if path != "" {
|
if path != "" && realPath != "" {
|
||||||
// Only create the symlink when container log path is specified.
|
// Only create the symlink when container log path is specified.
|
||||||
if err = ds.os.Symlink(realPath, path); err != nil {
|
if err = ds.os.Symlink(realPath, path); err != nil {
|
||||||
return fmt.Errorf("failed to create symbolic link %q to the container log file %q for container %q: %v",
|
return fmt.Errorf("failed to create symbolic link %q to the container log file %q for container %q: %v",
|
||||||
|
@ -73,9 +73,13 @@ type FakeDockerClient struct {
|
|||||||
ImageHistoryMap map[string][]dockertypes.ImageHistory
|
ImageHistoryMap map[string][]dockertypes.ImageHistory
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't check docker version now, just set the docker version of fake docker client to 1.8.1.
|
const (
|
||||||
// Notice that if someday we also have minimum docker version requirement, this should also be updated.
|
// We don't check docker version now, just set the docker version of fake docker client to 1.8.1.
|
||||||
const fakeDockerVersion = "1.8.1"
|
// Notice that if someday we also have minimum docker version requirement, this should also be updated.
|
||||||
|
fakeDockerVersion = "1.8.1"
|
||||||
|
|
||||||
|
fakeImageSize = 1024
|
||||||
|
)
|
||||||
|
|
||||||
func NewFakeDockerClient() *FakeDockerClient {
|
func NewFakeDockerClient() *FakeDockerClient {
|
||||||
return &FakeDockerClient{
|
return &FakeDockerClient{
|
||||||
@ -373,30 +377,57 @@ func (f *FakeDockerClient) ListContainers(options dockertypes.ContainerListOptio
|
|||||||
// TODO(random-liu): Is a fully sorted array needed?
|
// TODO(random-liu): Is a fully sorted array needed?
|
||||||
containerList = append(containerList, f.ExitedContainerList...)
|
containerList = append(containerList, f.ExitedContainerList...)
|
||||||
}
|
}
|
||||||
// TODO: Support other filters.
|
// Filter containers with id, only support 1 id.
|
||||||
|
idFilters := options.Filter.Get("id")
|
||||||
|
if len(idFilters) != 0 {
|
||||||
|
var filtered []dockertypes.Container
|
||||||
|
for _, container := range containerList {
|
||||||
|
for _, idFilter := range idFilters {
|
||||||
|
if container.ID == idFilter {
|
||||||
|
filtered = append(filtered, container)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
containerList = filtered
|
||||||
|
}
|
||||||
|
// Filter containers with status, only support 1 status.
|
||||||
|
statusFilters := options.Filter.Get("status")
|
||||||
|
if len(statusFilters) == 1 {
|
||||||
|
var filtered []dockertypes.Container
|
||||||
|
for _, container := range containerList {
|
||||||
|
for _, statusFilter := range statusFilters {
|
||||||
|
if container.Status == statusFilter {
|
||||||
|
filtered = append(filtered, container)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
containerList = filtered
|
||||||
|
}
|
||||||
// Filter containers with label filter.
|
// Filter containers with label filter.
|
||||||
labelFilters := options.Filter.Get("label")
|
labelFilters := options.Filter.Get("label")
|
||||||
if len(labelFilters) == 0 {
|
if len(labelFilters) != 0 {
|
||||||
return containerList, err
|
var filtered []dockertypes.Container
|
||||||
}
|
for _, container := range containerList {
|
||||||
var filtered []dockertypes.Container
|
match := true
|
||||||
for _, container := range containerList {
|
for _, labelFilter := range labelFilters {
|
||||||
match := true
|
kv := strings.Split(labelFilter, "=")
|
||||||
for _, labelFilter := range labelFilters {
|
if len(kv) != 2 {
|
||||||
kv := strings.Split(labelFilter, "=")
|
return nil, fmt.Errorf("invalid label filter %q", labelFilter)
|
||||||
if len(kv) != 2 {
|
}
|
||||||
return nil, fmt.Errorf("invalid label filter %q", labelFilter)
|
if container.Labels[kv[0]] != kv[1] {
|
||||||
|
match = false
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if container.Labels[kv[0]] != kv[1] {
|
if match {
|
||||||
match = false
|
filtered = append(filtered, container)
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if match {
|
containerList = filtered
|
||||||
filtered = append(filtered, container)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return filtered, err
|
return containerList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// InspectContainer is a test-spy implementation of DockerInterface.InspectContainer.
|
// InspectContainer is a test-spy implementation of DockerInterface.InspectContainer.
|
||||||
@ -587,6 +618,10 @@ func (f *FakeDockerClient) PullImage(image string, auth dockertypes.AuthConfig,
|
|||||||
f.Image = &dockertypes.ImageInspect{
|
f.Image = &dockertypes.ImageInspect{
|
||||||
ID: image,
|
ID: image,
|
||||||
RepoTags: []string{image},
|
RepoTags: []string{image},
|
||||||
|
// Image size is required to be non-zero for CRI integration.
|
||||||
|
VirtualSize: fakeImageSize,
|
||||||
|
Size: fakeImageSize,
|
||||||
|
Config: &dockercontainer.Config{},
|
||||||
}
|
}
|
||||||
f.appendPulled(fmt.Sprintf("%s using %s", image, string(authJson)))
|
f.appendPulled(fmt.Sprintf("%s using %s", image, string(authJson)))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user