(ctx context.Context, client *containerd.Client, imageList []images.Image, options *types.ImageListOptions)
| 129 | } |
| 130 | |
| 131 | func printImages(ctx context.Context, client *containerd.Client, imageList []images.Image, options *types.ImageListOptions) error { |
| 132 | w := options.Stdout |
| 133 | var finalImageList []images.Image |
| 134 | /* |
| 135 | the same imageId under k8s.io is showing multiple results: repo:tag, repo:digest, configID. |
| 136 | We expect to display only repo:tag, consistent with other namespaces and CRI |
| 137 | e.g. |
| 138 | nerdctl -n k8s.io images |
| 139 | REPOSITORY TAG IMAGE ID CREATED PLATFORM SIZE BLOB SIZE |
| 140 | centos 7 be65f488b776 3 hours ago linux/amd64 211.5 MiB 72.6 MiB |
| 141 | centos <none> be65f488b776 3 hours ago linux/amd64 211.5 MiB 72.6 MiB |
| 142 | <none> <none> be65f488b776 3 hours ago linux/amd64 211.5 MiB 72.6 MiB |
| 143 | expect: |
| 144 | nerdctl --kube-hide-dupe -n k8s.io images |
| 145 | REPOSITORY TAG IMAGE ID CREATED PLATFORM SIZE BLOB SIZE |
| 146 | centos 7 be65f488b776 3 hours ago linux/amd64 211.5 MiB 72.6 MiB |
| 147 | */ |
| 148 | if options.GOptions.KubeHideDupe && options.GOptions.Namespace == "k8s.io" { |
| 149 | imageDigest := make(map[digest.Digest]bool) |
| 150 | var imageNoTag []images.Image |
| 151 | for _, img := range imageList { |
| 152 | parsed, err := referenceutil.Parse(img.Name) |
| 153 | if err != nil { |
| 154 | continue |
| 155 | } |
| 156 | if parsed.Tag != "" { |
| 157 | finalImageList = append(finalImageList, img) |
| 158 | imageDigest[img.Target.Digest] = true |
| 159 | continue |
| 160 | } |
| 161 | imageNoTag = append(imageNoTag, img) |
| 162 | } |
| 163 | //Ensure that dangling images without a repo:tag are displayed correctly. |
| 164 | for _, ima := range imageNoTag { |
| 165 | if !imageDigest[ima.Target.Digest] { |
| 166 | finalImageList = append(finalImageList, ima) |
| 167 | imageDigest[ima.Target.Digest] = true |
| 168 | } |
| 169 | } |
| 170 | } else { |
| 171 | finalImageList = imageList |
| 172 | } |
| 173 | digestsFlag := options.Digests |
| 174 | if options.Format == "wide" { |
| 175 | digestsFlag = true |
| 176 | } |
| 177 | var tmpl *template.Template |
| 178 | switch options.Format { |
| 179 | case "", "table", "wide": |
| 180 | w = tabwriter.NewWriter(w, 4, 8, 4, ' ', 0) |
| 181 | if !options.Quiet { |
| 182 | printHeader := "" |
| 183 | if options.Names { |
| 184 | printHeader += "NAME\t" |
| 185 | } else { |
| 186 | printHeader += "REPOSITORY\tTAG\t" |
| 187 | } |
| 188 | if digestsFlag { |
no test coverage detected
searching dependent graphs…