Skip to content

Conversation

@neersighted
Copy link
Contributor

@neersighted neersighted commented Sep 27, 2023

By aligning with the mediatypes.go helpers, there is a single source of truth for the mediatype checks in the images/ package tree, and we can remove some case statements. By dropping case statements, branching logic can be simplified and made more obvious, with less nesting.

@k8s-ci-robot
Copy link

Hi @neersighted. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@thaJeztah
Copy link
Member

Looks like a linter is complaining about an empty "else" branch (despite the comment in it); could either continue using a switch, or perhaps add a comment above the if statement (if it clarifies things)

Screenshot 2023-09-27 at 17 26 30

@neersighted
Copy link
Contributor Author

neersighted commented Sep 27, 2023

I've contained this to the images/ package tree for now; however if this is palatable, I'll likely send a follow-up that alters the rest of the codebase, making these helpers the canonical source of 'what is an image index' etc.

Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
@AkihiroSuda
Copy link
Member

/ok-to-test

for _, desc := range eo.manifests {
switch desc.MediaType {
case images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest:
if images.IsManifestType(desc.MediaType) {
Copy link
Member

Choose a reason for hiding this comment

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

Alternatively, you could keep a switch, and use the boolean checks in it (I personally find those to be slightly more readable as the condition is more "in plain sight"), but that's really a bike-shed, so just leaving the comment for consideration 😄

switch {
case images.IsManifestType(desc.MediaType):
    // ...
case images.IsIndexType(desc.MediaType):
    // ...
default:
    // ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tend to prefer the if and braces style for relatively dense blocks like this; unless another review prefers this, I think I'd like to leave this how I have it.

@estesp estesp merged commit 61a8905 into containerd:main Sep 27, 2023
@neersighted neersighted deleted the image_cleanup branch September 27, 2023 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants