mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-21 13:23:09 +01:00
lint: fix deprecated
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
@@ -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] == "<none>:<none>" && len(image.RepoDigests) == 1 && image.RepoDigests[0] == "<none>@<none>"
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user