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

c8d: Various images/json API fixes #46034

Merged
merged 4 commits into from Jul 26, 2023
Merged

Conversation

rumpl
Copy link
Member

@rumpl rumpl commented Jul 20, 2023

- What I did

  • Added more tests for the image list filters
  • Added the image labels to the image list
  • Sort the images by creation date
  • Populate RepoTags with all the tags pointing to an image instead of having multiple objects of the same image in the array.

Fixes #43848
Fixes #43852
Also partially fix*s #43861, I didn't touch RepoDigests

- How I did it

...

- How to verify it

Run

  • make DOCKER_GRAPHDRIVER=overlayfs TEST_FILTER=TestAPIImagesFilter TEST_INTEGRATION_USE_SNAPSHOTTER=1 test-integration
  • make DOCKER_GRAPHDRIVER=overlayfs TEST_FILTER=TestImagesFilterMultiReference TEST_INTEGRATION_USE_SNAPSHOTTER=1 test-integration

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@rumpl rumpl added area/api status/2-code-review area/images containerd-integration Issues and PRs related to containerd integration labels Jul 20, 2023
@rumpl rumpl changed the title integration-cli: Add more checks to images filter c8d: Various images/json API fixes Jul 20, 2023
integration-cli/docker_api_images_test.go Outdated Show resolved Hide resolved
integration-cli/docker_api_images_test.go Outdated Show resolved Hide resolved
integration-cli/docker_api_images_test.go Outdated Show resolved Hide resolved
integration-cli/docker_api_images_test.go Outdated Show resolved Hide resolved
integration-cli/docker_api_images_test.go Outdated Show resolved Hide resolved
daemon/containerd/image_list.go Show resolved Hide resolved
daemon/containerd/image_list.go Outdated Show resolved Hide resolved
Comment on lines +37 to +50
// byCreated is a temporary type used to sort a list of images by creation
// time.
type byCreated []*types.ImageSummary

func (r byCreated) Len() int { return len(r) }
func (r byCreated) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
func (r byCreated) Less(i, j int) bool { return r[i].Created < r[j].Created }
Copy link
Member

Choose a reason for hiding this comment

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

Not a blocker, but starting to wonder if we need to move this somewhere central (I was planning to move the image types from types to types/image, so perhaps that's a good opportunity).

Also considering that sorting may at some point be something we want on the client side as well

return nil, nil, err
}
var cfg configLabels
if err := readConfig(ctx, contentStore, cfgDesc, &cfg); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

LOL, very unrelated, but I was curious if we make use of the Data field anywhere in our code; https://github.com/opencontainers/image-spec/blob/v1.1.0-rc4/specs-go/v1/descriptor.go#L38-L41

	// Data is an embedding of the targeted content. This is encoded as a base64
	// string when marshalled to JSON (automatically, by encoding/json). If
	// present, Data can be used directly to avoid fetching the targeted content.
	Data []byte `json:"data,omitempty"`

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't seen any code using that yet TBH. Let me check, if it can be used that would be great actually

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't seem to be set by containerd, we might want to take a note of this and see if it can be used really

Copy link
Member

Choose a reason for hiding this comment

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

Yup! I could see something along the lines of

if desc.Data != nil {
  // fast path
}

That said; I wonder if the Spec is clear enough on verifying Data matches the referenced data (would be fun if there's no such check and Data would return something very different from the referenced file 😂)

Copy link
Member Author

@rumpl rumpl Jul 26, 2023

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Nice, so yes, looks like we can start looking into using that

@thaJeztah
Copy link
Member

Some failures on Windows, which look related;

=== Failed
=== FAIL: github.com/docker/docker/integration-cli TestDockerAPISuite/TestAPIImagesFilter/all_images (0.01s)
    docker_api_images_test.go:103: assertion failed: 2 (int) != 7 (testcase.expectedImages int)

=== FAIL: github.com/docker/docker/integration-cli TestDockerAPISuite/TestAPIImagesFilter/dangling_images (0.00s)
    docker_api_images_test.go:103: assertion failed: 0 (int) != 1 (testcase.expectedImages int)

=== FAIL: github.com/docker/docker/integration-cli TestDockerAPISuite/TestAPIImagesFilter (0.24s)

=== FAIL: github.com/docker/docker/integration-cli TestDockerAPISuite (1.39s)
panic: runtime error: index out of range [0] with length 0 [recovered]
	panic: runtime error: index out of range [0] with length 0

goroutine 78 [running]:
testing.tRunner.func1.2({0x13a12c0, 0xc00090ea38})
	C:/hostedtoolcache/windows/go/1.20.6/x64/src/testing/testing.go:1526 +0x24e
testing.tRunner.func1()
	C:/hostedtoolcache/windows/go/1.20.6/x64/src/testing/testing.go:1529 +0x39f
panic({0x13a12c0, 0xc00090ea38})
	C:/hostedtoolcache/windows/go/1.20.6/x64/src/runtime/panic.go:884 +0x213
github.com/docker/docker/integration-cli.(*DockerAPISuite).TestAPIImagesFilter.func1(0x0?)
	D:/a/moby/moby/go/src/github.com/docker/docker/integration-cli/docker_api_images_test.go:105 +0x2c5
testing.tRunner(0xc000846ea0, 0xc000909b78)
	C:/hostedtoolcache/windows/go/1.20.6/x64/src/testing/testing.go:1576 +0x10b
created by testing.(*T).Run
	C:/hostedtoolcache/windows/go/1.20.6/x64/src/testing/testing.go:1629 +0x3ea

DONE 16 tests, 2 skipped, 4 failures in 99.924s

@rumpl rumpl force-pushed the c8d-image-list branch 2 times, most recently from b74fff4 to 5308d40 Compare July 20, 2023 13:29
integration/image/list_test.go Outdated Show resolved Hide resolved
daemon/containerd/image_list.go Outdated Show resolved Hide resolved
daemon/containerd/image_list.go Outdated Show resolved Hide resolved
daemon/containerd/image_list.go Outdated Show resolved Hide resolved
daemon/containerd/image_list.go Show resolved Hide resolved
daemon/containerd/image_list.go Outdated Show resolved Hide resolved
daemon/containerd/image_list.go Outdated Show resolved Hide resolved
daemon/containerd/image_list.go Outdated Show resolved Hide resolved
integration/image/list_test.go Outdated Show resolved Hide resolved
integration/image/list_test.go Outdated Show resolved Hide resolved
integration/image/list_test.go Outdated Show resolved Hide resolved
@rumpl rumpl force-pushed the c8d-image-list branch 4 times, most recently from b0576bc to bd86b37 Compare July 25, 2023 08:40
@rumpl rumpl requested a review from vvoland July 25, 2023 08:49
Copy link
Contributor

@vvoland vvoland left a comment

Choose a reason for hiding this comment

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

Overall LGTM, just have one performance nit.

daemon/containerd/image_list.go Outdated Show resolved Hide resolved
Copy link
Member

@laurazard laurazard left a comment

Choose a reason for hiding this comment

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

LGTM

@rumpl rumpl added this to the 25.0.0 milestone Jul 26, 2023
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

left some nits (you know me 😂), but not blockers, so up to you if you want to address them ❤️

daemon/containerd/image_list.go Outdated Show resolved Hide resolved
integration/image/list_test.go Outdated Show resolved Hide resolved
integration/image/list_test.go Outdated Show resolved Hide resolved
return nil, nil, err
}
var cfg configLabels
if err := readConfig(ctx, contentStore, cfgDesc, &cfg); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Nice, so yes, looks like we can start looking into using that

- use assert.Check to continue the test even if a check fails
- assert the total number of images returned, not only their RepoTags
- use subtests

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
Aggregate same images into one object and add the list of tags pointing
to it to the RepoTags array

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM!

@thaJeztah
Copy link
Member

Aaaaaaaand.... all green

@thaJeztah thaJeztah merged commit 7a44e4c into moby:master Jul 26, 2023
103 checks passed
@thaJeztah thaJeztah deleted the c8d-image-list branch July 26, 2023 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api area/images containerd-integration Issues and PRs related to containerd integration status/4-merge
Projects
None yet
4 participants