Skip to content

Commit

Permalink
Merge pull request moby#47116 from thaJeztah/minor_nits
Browse files Browse the repository at this point in the history
assorted minor linting issues
  • Loading branch information
thaJeztah authored Jan 19, 2024
2 parents 67de5c8 + 35789fc commit d35e923
Show file tree
Hide file tree
Showing 22 changed files with 130 additions and 123 deletions.
6 changes: 3 additions & 3 deletions api/server/router/distribution/distribution_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func (s *distributionRouter) getDistributionInfo(ctx context.Context, w http.Res

w.Header().Set("Content-Type", "application/json")

image := vars["name"]
imgName := vars["name"]

// TODO why is reference.ParseAnyReference() / reference.ParseNormalizedNamed() not using the reference.ErrTagInvalidFormat (and so on) errors?
ref, err := reference.ParseAnyReference(image)
ref, err := reference.ParseAnyReference(imgName)
if err != nil {
return errdefs.InvalidParameter(err)
}
Expand All @@ -37,7 +37,7 @@ func (s *distributionRouter) getDistributionInfo(ctx context.Context, w http.Res
// full image ID
return errors.Errorf("no manifest found for full image ID")
}
return errdefs.InvalidParameter(errors.Errorf("unknown image reference format: %s", image))
return errdefs.InvalidParameter(errors.Errorf("unknown image reference format: %s", imgName))
}

// For a search it is not an error if no auth was given. Ignore invalid
Expand Down
4 changes: 2 additions & 2 deletions api/server/router/image/image_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ func (ir *imageRouter) postImagesCreate(ctx context.Context, w http.ResponseWrit
// Special case: "pull -a" may send an image name with a
// trailing :. This is ugly, but let's not break API
// compatibility.
image := strings.TrimSuffix(img, ":")
imgName := strings.TrimSuffix(img, ":")

ref, err := reference.ParseNormalizedNamed(image)
ref, err := reference.ParseNormalizedNamed(imgName)
if err != nil {
return errdefs.InvalidParameter(err)
}
Expand Down
8 changes: 4 additions & 4 deletions client/distribution_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
)

// DistributionInspect returns the image digest with the full manifest.
func (cli *Client) DistributionInspect(ctx context.Context, image, encodedRegistryAuth string) (registry.DistributionInspect, error) {
func (cli *Client) DistributionInspect(ctx context.Context, imageRef, encodedRegistryAuth string) (registry.DistributionInspect, error) {
// Contact the registry to retrieve digest and platform information
var distributionInspect registry.DistributionInspect
if image == "" {
return distributionInspect, objectNotFoundError{object: "distribution", id: image}
if imageRef == "" {
return distributionInspect, objectNotFoundError{object: "distribution", id: imageRef}
}

if err := cli.NewVersionError(ctx, "1.30", "distribution inspect"); err != nil {
Expand All @@ -28,7 +28,7 @@ func (cli *Client) DistributionInspect(ctx context.Context, image, encodedRegist
}
}

resp, err := cli.get(ctx, "/distribution/"+image+"/json", url.Values{}, headers)
resp, err := cli.get(ctx, "/distribution/"+imageRef+"/json", url.Values{}, headers)
defer ensureReaderClosed(resp)
if err != nil {
return distributionInspect, err
Expand Down
8 changes: 4 additions & 4 deletions daemon/cluster/convert/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ func TestServiceConvertToGRPCGenericRuntimePlugin(t *testing.T) {
}

func TestServiceConvertToGRPCContainerRuntime(t *testing.T) {
image := "alpine:latest"
const imgName = "alpine:latest"
s := swarmtypes.ServiceSpec{
TaskTemplate: swarmtypes.TaskSpec{
ContainerSpec: &swarmtypes.ContainerSpec{
Image: image,
Image: imgName,
},
},
Mode: swarmtypes.ServiceMode{
Expand All @@ -131,8 +131,8 @@ func TestServiceConvertToGRPCContainerRuntime(t *testing.T) {
t.Fatal("expected type swarmapi.TaskSpec_Container")
}

if v.Container.Image != image {
t.Fatalf("expected image %s; received %s", image, v.Container.Image)
if v.Container.Image != imgName {
t.Fatalf("expected image %s; received %s", imgName, v.Container.Image)
}
}

Expand Down
4 changes: 2 additions & 2 deletions daemon/containerd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func (i *ImageService) GetImage(ctx context.Context, refOrID string, options ima
sort.SliceStable(presentImages, func(i, j int) bool {
return platform.Less(presentImages[i].Platform, presentImages[j].Platform)
})
ociimage := presentImages[0]
ociImage := presentImages[0]

img := dockerOciImageToDockerImagePartial(image.ID(desc.Target.Digest), ociimage)
img := dockerOciImageToDockerImagePartial(image.ID(desc.Target.Digest), ociImage)

parent, err := i.getImageLabelByDigest(ctx, desc.Target.Digest, imageLabelClassicBuilderParent)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions daemon/containerd/image_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func (i *ImageService) ImageHistory(ctx context.Context, name string) ([]*imaget
if err != nil {
return err
}
var ociimage ocispec.Image
if err := readConfig(ctx, cs, conf, &ociimage); err != nil {
var ociImage ocispec.Image
if err := readConfig(ctx, cs, conf, &ociImage); err != nil {
return err
}
presentImages = append(presentImages, ociimage)
presentImages = append(presentImages, ociImage)
return nil
})
if err != nil {
Expand All @@ -53,15 +53,15 @@ func (i *ImageService) ImageHistory(ctx context.Context, name string) ([]*imaget
sort.SliceStable(presentImages, func(i, j int) bool {
return platform.Less(presentImages[i].Platform, presentImages[j].Platform)
})
ociimage := presentImages[0]
ociImage := presentImages[0]

var (
history []*imagetype.HistoryResponseItem
sizes []int64
)
s := i.client.SnapshotService(i.snapshotter)

diffIDs := ociimage.RootFS.DiffIDs
diffIDs := ociImage.RootFS.DiffIDs
for i := range diffIDs {
chainID := identity.ChainID(diffIDs[0 : i+1]).String()

Expand All @@ -73,7 +73,7 @@ func (i *ImageService) ImageHistory(ctx context.Context, name string) ([]*imaget
sizes = append(sizes, use.Size)
}

for _, h := range ociimage.History {
for _, h := range ociImage.History {
size := int64(0)
if !h.EmptyLayer {
if len(sizes) == 0 {
Expand Down
23 changes: 15 additions & 8 deletions daemon/images/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ func (i *ImageService) PrepareSnapshot(ctx context.Context, id string, parentIma
}

func (i *ImageService) manifestMatchesPlatform(ctx context.Context, img *image.Image, platform ocispec.Platform) (bool, error) {
logger := log.G(ctx).WithField("image", img.ID).WithField("desiredPlatform", platforms.Format(platform))

ls, err := i.leases.ListResources(ctx, leases.Lease{ID: imageKey(img.ID().String())})
if err != nil {
if cerrdefs.IsNotFound(err) {
return false, nil
}
logger.WithError(err).Error("Error looking up image leases")
log.G(ctx).WithFields(log.Fields{
"error": err,
"image": img.ID,
"desiredPlatform": platforms.Format(platform),
}).Error("Error looking up image leases")
return false, err
}

Expand All @@ -77,7 +79,12 @@ func (i *ImageService) manifestMatchesPlatform(ctx context.Context, img *image.I
}

for _, r := range ls {
logger := logger.WithField("resourceID", r.ID).WithField("resourceType", r.Type)
logger := log.G(ctx).WithFields(log.Fields{
"image": img.ID,
"desiredPlatform": platforms.Format(platform),
"resourceID": r.ID,
"resourceType": r.Type,
})
logger.Debug("Checking lease resource for platform match")
if r.Type != "content" {
continue
Expand Down Expand Up @@ -241,12 +248,12 @@ func (i *ImageService) getImage(ctx context.Context, refOrID string, options ima
if !ok {
digested, ok := ref.(reference.Digested)
if !ok {
return nil, ErrImageDoesNotExist{ref}
return nil, ErrImageDoesNotExist{Ref: ref}
}
if img, err := i.imageStore.Get(image.ID(digested.Digest())); err == nil {
return img, nil
}
return nil, ErrImageDoesNotExist{ref}
return nil, ErrImageDoesNotExist{Ref: ref}
}

if dgst, err := i.referenceStore.Get(namedRef); err == nil {
Expand All @@ -260,12 +267,12 @@ func (i *ImageService) getImage(ctx context.Context, refOrID string, options ima
if id, err := i.imageStore.Search(refOrID); err == nil {
img, err := i.imageStore.Get(id)
if err != nil {
return nil, ErrImageDoesNotExist{ref}
return nil, ErrImageDoesNotExist{Ref: ref}
}
return img, nil
}

return nil, ErrImageDoesNotExist{ref}
return nil, ErrImageDoesNotExist{Ref: ref}
}

// OnlyPlatformWithFallback uses `platforms.Only` with a fallback to handle the case where the platform
Expand Down
8 changes: 4 additions & 4 deletions integration-cli/docker_api_images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ func (s *DockerAPISuite) TestAPIImagesSizeCompatibility(c *testing.T) {
images, err := apiclient.ImageList(testutil.GetContext(c), types.ImageListOptions{})
assert.NilError(c, err)
assert.Assert(c, len(images) != 0)
for _, image := range images {
assert.Assert(c, image.Size != int64(-1))
for _, img := range images {
assert.Assert(c, img.Size != int64(-1))
}

apiclient, err = client.NewClientWithOpts(client.FromEnv, client.WithVersion("v1.24"))
Expand All @@ -143,7 +143,7 @@ func (s *DockerAPISuite) TestAPIImagesSizeCompatibility(c *testing.T) {
v124Images, err := apiclient.ImageList(testutil.GetContext(c), types.ImageListOptions{})
assert.NilError(c, err)
assert.Assert(c, len(v124Images) != 0)
for _, image := range v124Images {
assert.Assert(c, image.Size != int64(-1))
for _, img := range v124Images {
assert.Assert(c, img.Size != int64(-1))
}
}
12 changes: 6 additions & 6 deletions integration-cli/docker_cli_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6044,22 +6044,22 @@ func (s *DockerCLIBuildSuite) TestBuildWindowsEnvCaseInsensitive(c *testing.T) {

// Test case for 29667
func (s *DockerCLIBuildSuite) TestBuildWorkdirImageCmd(c *testing.T) {
image := "testworkdirimagecmd"
buildImageSuccessfully(c, image, build.WithDockerfile(`
imgName := "testworkdirimagecmd"
buildImageSuccessfully(c, imgName, build.WithDockerfile(`
FROM busybox
WORKDIR /foo/bar
`))
out := cli.DockerCmd(c, "inspect", "--format", "{{ json .Config.Cmd }}", image).Stdout()
out := cli.DockerCmd(c, "inspect", "--format", "{{ json .Config.Cmd }}", imgName).Stdout()
assert.Equal(c, strings.TrimSpace(out), `["sh"]`)

image = "testworkdirlabelimagecmd"
buildImageSuccessfully(c, image, build.WithDockerfile(`
imgName = "testworkdirlabelimagecmd"
buildImageSuccessfully(c, imgName, build.WithDockerfile(`
FROM busybox
WORKDIR /foo/bar
LABEL a=b
`))

out = cli.DockerCmd(c, "inspect", "--format", "{{ json .Config.Cmd }}", image).Stdout()
out = cli.DockerCmd(c, "inspect", "--format", "{{ json .Config.Cmd }}", imgName).Stdout()
assert.Equal(c, strings.TrimSpace(out), `["sh"]`)
}

Expand Down
6 changes: 3 additions & 3 deletions integration-cli/docker_cli_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ func (s *DockerCLICreateSuite) TestCreateLabelFromImage(c *testing.T) {
}

func (s *DockerCLICreateSuite) TestCreateHostnameWithNumber(c *testing.T) {
image := "busybox"
imgName := "busybox"
// Busybox on Windows does not implement hostname command
if testEnv.DaemonInfo.OSType == "windows" {
image = testEnv.PlatformDefaults.BaseImage
imgName = testEnv.PlatformDefaults.BaseImage
}
out := cli.DockerCmd(c, "run", "-h", "web.0", image, "hostname").Combined()
out := cli.DockerCmd(c, "run", "-h", "web.0", imgName, "hostname").Combined()
assert.Equal(c, strings.TrimSpace(out), "web.0", "hostname not set, expected `web.0`, got: %s", out)
}

Expand Down
12 changes: 6 additions & 6 deletions integration-cli/docker_cli_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func (s *DockerCLIEventSuite) TestEventsTimestampFormats(c *testing.T) {
}

func (s *DockerCLIEventSuite) TestEventsUntag(c *testing.T) {
image := "busybox"
cli.DockerCmd(c, "tag", image, "utest:tag1")
cli.DockerCmd(c, "tag", image, "utest:tag2")
const imgName = "busybox"
cli.DockerCmd(c, "tag", imgName, "utest:tag1")
cli.DockerCmd(c, "tag", imgName, "utest:tag2")
cli.DockerCmd(c, "rmi", "utest:tag1")
cli.DockerCmd(c, "rmi", "utest:tag2")

Expand Down Expand Up @@ -143,8 +143,8 @@ func (s *DockerCLIEventSuite) TestEventsContainerEventsSinceUnixEpoch(c *testing
func (s *DockerCLIEventSuite) TestEventsImageTag(c *testing.T) {
time.Sleep(1 * time.Second) // because API has seconds granularity
since := daemonUnixTime(c)
image := "testimageevents:tag"
cli.DockerCmd(c, "tag", "busybox", image)
const imgName = "testimageevents:tag"
cli.DockerCmd(c, "tag", "busybox", imgName)

out := cli.DockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c)).Stdout()

Expand All @@ -153,7 +153,7 @@ func (s *DockerCLIEventSuite) TestEventsImageTag(c *testing.T) {
event := strings.TrimSpace(events[0])

matches := eventstestutils.ScanMap(event)
assert.Assert(c, matchEventID(matches, image), "matches: %v\nout:\n%s", matches, out)
assert.Assert(c, matchEventID(matches, imgName), "matches: %v\nout:\n%s", matches, out)
assert.Equal(c, matches["action"], "tag")
}

Expand Down
4 changes: 2 additions & 2 deletions integration-cli/docker_cli_images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ func (s *DockerCLIImagesSuite) TestImagesFilterSpaceTrimCase(c *testing.T) {
if idx < 4 && !reflect.DeepEqual(listing, imageListings[idx+1]) {
for idx, errListing := range imageListings {
fmt.Printf("out %d\n", idx)
for _, image := range errListing {
fmt.Print(image)
for _, img := range errListing {
fmt.Print(img)
}
fmt.Print("")
}
Expand Down
22 changes: 11 additions & 11 deletions integration-cli/docker_cli_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (s *DockerCLIImportSuite) TestImportDisplay(c *testing.T) {

assert.Assert(c, strings.Count(out, "\n") == 1, "display is expected 1 '\\n' but didn't")

image := strings.TrimSpace(out)
out = cli.DockerCmd(c, "run", "--rm", image, "true").Combined()
imgRef := strings.TrimSpace(out)
out = cli.DockerCmd(c, "run", "--rm", imgRef, "true").Combined()
assert.Equal(c, out, "", "command output should've been nothing.")
}

Expand Down Expand Up @@ -71,9 +71,9 @@ func (s *DockerCLIImportSuite) TestImportFile(c *testing.T) {

out := cli.DockerCmd(c, "import", temporaryFile.Name()).Combined()
assert.Assert(c, strings.Count(out, "\n") == 1, "display is expected 1 '\\n' but didn't")
image := strings.TrimSpace(out)
imgRef := strings.TrimSpace(out)

out = cli.DockerCmd(c, "run", "--rm", image, "true").Combined()
out = cli.DockerCmd(c, "run", "--rm", imgRef, "true").Combined()
assert.Equal(c, out, "", "command output should've been nothing.")
}

Expand All @@ -94,9 +94,9 @@ func (s *DockerCLIImportSuite) TestImportGzipped(c *testing.T) {
temporaryFile.Close()
out := cli.DockerCmd(c, "import", temporaryFile.Name()).Combined()
assert.Assert(c, strings.Count(out, "\n") == 1, "display is expected 1 '\\n' but didn't")
image := strings.TrimSpace(out)
imgRef := strings.TrimSpace(out)

out = cli.DockerCmd(c, "run", "--rm", image, "true").Combined()
out = cli.DockerCmd(c, "run", "--rm", imgRef, "true").Combined()
assert.Equal(c, out, "", "command output should've been nothing.")
}

Expand All @@ -116,9 +116,9 @@ func (s *DockerCLIImportSuite) TestImportFileWithMessage(c *testing.T) {
message := "Testing commit message"
out := cli.DockerCmd(c, "import", "-m", message, temporaryFile.Name()).Combined()
assert.Assert(c, strings.Count(out, "\n") == 1, "display is expected 1 '\\n' but didn't")
image := strings.TrimSpace(out)
imgRef := strings.TrimSpace(out)

out = cli.DockerCmd(c, "history", image).Combined()
out = cli.DockerCmd(c, "history", imgRef).Combined()
split := strings.Split(out, "\n")

assert.Equal(c, len(split), 3, "expected 3 lines from image history")
Expand All @@ -127,7 +127,7 @@ func (s *DockerCLIImportSuite) TestImportFileWithMessage(c *testing.T) {

assert.Equal(c, message, split[3], "didn't get expected value in commit message")

out = cli.DockerCmd(c, "run", "--rm", image, "true").Combined()
out = cli.DockerCmd(c, "run", "--rm", imgRef, "true").Combined()
assert.Equal(c, out, "", "command output should've been nothing")
}

Expand All @@ -147,8 +147,8 @@ func (s *DockerCLIImportSuite) TestImportWithQuotedChanges(c *testing.T) {
cli.Docker(cli.Args("export", "test-import"), cli.WithStdout(bufio.NewWriter(temporaryFile))).Assert(c, icmd.Success)

result := cli.DockerCmd(c, "import", "-c", `ENTRYPOINT ["/bin/sh", "-c"]`, temporaryFile.Name())
image := strings.TrimSpace(result.Stdout())
imgRef := strings.TrimSpace(result.Stdout())

result = cli.DockerCmd(c, "run", "--rm", image, "true")
result = cli.DockerCmd(c, "run", "--rm", imgRef, "true")
result.Assert(c, icmd.Expected{Out: icmd.None})
}
Loading

0 comments on commit d35e923

Please sign in to comment.