From 528d96d417e95d859e3ef7e6933fd66828d885da Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Sun, 3 Aug 2025 16:58:04 +0200 Subject: [PATCH] lint: fix deprecated --- internal/provider/docker/container.go | 18 +++++++++--------- pkg/docker/container.go | 3 +-- pkg/docker/image.go | 16 ++++++++-------- pkg/docker/service.go | 3 +-- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/internal/provider/docker/container.go b/internal/provider/docker/container.go index bf3b0375..e3e795f4 100644 --- a/internal/provider/docker/container.go +++ b/internal/provider/docker/container.go @@ -9,7 +9,7 @@ import ( "github.com/crazy-max/diun/v4/internal/model" "github.com/crazy-max/diun/v4/internal/provider" "github.com/crazy-max/diun/v4/pkg/docker" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/filters" "github.com/docker/go-units" ) @@ -43,7 +43,7 @@ func (c *Client) listContainerImage() []model.Image { var list []model.Image for _, ctn := range ctns { imageName := ctn.Image - imageRaw, err := cli.ImageInspectWithRaw(imageName) + imageInfo, err := cli.ImageInspect(imageName) if err != nil { c.logger.Error().Err(err). Str("ctn_id", ctn.ID). @@ -52,7 +52,7 @@ func (c *Client) listContainerImage() []model.Image { continue } - if local := cli.IsLocalImage(imageRaw); local { + if local := cli.IsLocalImage(imageInfo); local { c.logger.Debug(). Str("ctn_id", ctn.ID). Str("ctn_image", imageName). @@ -60,7 +60,7 @@ func (c *Client) listContainerImage() []model.Image { continue } - if dangling := cli.IsDanglingImage(imageRaw); dangling { + if dangling := cli.IsDanglingImage(imageInfo); dangling { c.logger.Debug(). Str("ctn_id", ctn.ID). Str("ctn_image", imageName). @@ -69,18 +69,18 @@ func (c *Client) listContainerImage() []model.Image { } if cli.IsDigest(imageName) { - if len(imageRaw.RepoDigests) > 0 { + if len(imageInfo.RepoDigests) > 0 { c.logger.Debug(). Str("ctn_id", ctn.ID). Str("ctn_image", imageName). - Strs("img_repodigests", imageRaw.RepoDigests). + Strs("img_repodigests", imageInfo.RepoDigests). Msg("Using first image repo digest available as image name") - imageName = imageRaw.RepoDigests[0] + imageName = imageInfo.RepoDigests[0] } else { c.logger.Debug(). Str("ctn_id", ctn.ID). Str("ctn_image", imageName). - Strs("img_repodigests", imageRaw.RepoDigests). + Strs("img_repodigests", imageInfo.RepoDigests). Msg("Skip unknown image digest ref") continue } @@ -115,7 +115,7 @@ func (c *Client) listContainerImage() []model.Image { return list } -func metadata(ctn types.Container) map[string]string { +func metadata(ctn container.Summary) map[string]string { return map[string]string{ "ctn_id": ctn.ID, "ctn_names": formatNames(ctn.Names), diff --git a/pkg/docker/container.go b/pkg/docker/container.go index 0640db7d..624c32d8 100644 --- a/pkg/docker/container.go +++ b/pkg/docker/container.go @@ -3,13 +3,12 @@ package docker import ( "sort" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/filters" ) // ContainerList returns Docker containers -func (c *Client) ContainerList(filterArgs filters.Args) ([]types.Container, error) { +func (c *Client) ContainerList(filterArgs filters.Args) ([]container.Summary, error) { containers, err := c.API.ContainerList(c.ctx, container.ListOptions{ Filters: filterArgs, }) diff --git a/pkg/docker/image.go b/pkg/docker/image.go index 84b8e686..519ebc2a 100644 --- a/pkg/docker/image.go +++ b/pkg/docker/image.go @@ -3,11 +3,12 @@ package docker import ( "regexp" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/image" ) // ContainerInspect returns the container information. -func (c *Client) ContainerInspect(containerID string) (types.ContainerJSON, error) { +func (c *Client) ContainerInspect(containerID string) (container.InspectResponse, error) { return c.API.ContainerInspect(c.ctx, containerID) } @@ -16,20 +17,19 @@ func (c *Client) IsDigest(imageID string) bool { return regexp.MustCompile(`^(@|sha256:|@sha256:)([0-9a-f]{64})$`).MatchString(imageID) } -// ImageInspectWithRaw returns the image information and its raw representation. -func (c *Client) ImageInspectWithRaw(imageID string) (types.ImageInspect, error) { - imageRaw, _, err := c.API.ImageInspectWithRaw(c.ctx, imageID) - return imageRaw, err +// ImageInspect returns the image information. +func (c *Client) ImageInspect(imageID string) (image.InspectResponse, error) { + return c.API.ImageInspect(c.ctx, imageID) } // IsLocalImage checks if the image has been built locally -func (c *Client) IsLocalImage(image types.ImageInspect) bool { +func (c *Client) IsLocalImage(image image.InspectResponse) bool { return len(image.RepoDigests) == 0 } // IsDanglingImage returns whether the given image is "dangling" which means // that there are no repository references to the given image and it has no // child images -func (c *Client) IsDanglingImage(image types.ImageInspect) bool { +func (c *Client) IsDanglingImage(image image.InspectResponse) bool { return len(image.RepoTags) == 1 && image.RepoTags[0] == ":" && len(image.RepoDigests) == 1 && image.RepoDigests[0] == "@" } diff --git a/pkg/docker/service.go b/pkg/docker/service.go index 2649667c..e863f823 100644 --- a/pkg/docker/service.go +++ b/pkg/docker/service.go @@ -3,14 +3,13 @@ package docker import ( "sort" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/swarm" ) // ServiceList returns Swarm services func (c *Client) ServiceList(filterArgs filters.Args) ([]swarm.Service, error) { - services, err := c.API.ServiceList(c.ctx, types.ServiceListOptions{ + services, err := c.API.ServiceList(c.ctx, swarm.ServiceListOptions{ Filters: filterArgs, }) if err != nil {