imagewalker

package
v2.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Found

type Found struct {
	Image          images.Image
	Req            string // The raw request string. name, short ID, or long ID.
	MatchIndex     int    // Begins with 0, up to MatchCount - 1.
	MatchCount     int    // 1 on exact match. > 1 on ambiguous match. Never be <= 0.
	UniqueImages   int    // Number of unique images in all found images.
	NameMatchIndex int    // Image index with a name matching the argument for `nerdctl rmi`.
}

type ImageWalker

type ImageWalker struct {
	Client       *containerd.Client
	OnFound      OnFound
	OnFoundCriRm OnFoundCriRm
}

func (*ImageWalker) Walk

func (w *ImageWalker) Walk(ctx context.Context, req string) (int, error)

Walk walks images and calls w.OnFound . Req is name, short ID, or long ID. Returns the number of the found entries.

func (*ImageWalker) WalkAll

func (w *ImageWalker) WalkAll(ctx context.Context, reqs []string, forceAll bool) error

WalkAll calls `Walk` for each req in `reqs`.

It can be used when the matchCount is not important (e.g., only care if there is any error or if matchCount == 0 (not found error) when walking all reqs). If `forceAll`, it calls `Walk` on every req and return all errors joined by `\n`. If not `forceAll`, it returns the first error encountered while calling `Walk`.

func (*ImageWalker) WalkCriRm added in v2.0.3

func (w *ImageWalker) WalkCriRm(ctx context.Context, req string) (int, error)

WalkCriRm walks images and calls w.OnFoundCriRm . Only effective when in the k8s.io namespace and kube-hide-dupe is enabled. The WalkCriRm deletes non-repo:tag items such as repo:digest when in the no-other-repo:tag scenario.

type OnFound

type OnFound func(ctx context.Context, found Found) error

type OnFoundCriRm added in v2.0.3

type OnFoundCriRm func(ctx context.Context, found Found) (bool, error)

In order to resolve the issue with OnFoundCriRm, the same imageId under k8s.io is showing multiple results: repo:tag, repo:digest, configID. We expect to display only repo:tag, consistent with other namespaces and CRI. e.g.

nerdctl -n k8s.io images
REPOSITORY    TAG       IMAGE ID        CREATED        PLATFORM       SIZE         BLOB SIZE
centos        7         be65f488b776    3 hours ago    linux/amd64    211.5 MiB    72.6 MiB
centos        <none>    be65f488b776    3 hours ago    linux/amd64    211.5 MiB    72.6 MiB
<none>        <none>    be65f488b776    3 hours ago    linux/amd64    211.5 MiB    72.6 MiB

The boolean value will return true only when the repo:tag is successfully deleted for each image. Once all repo:tag entries are deleted, it is necessary to clean up the remaining repo:digest and configID.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL