Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add show pinned information for images #1247

Merged
merged 2 commits into from
Aug 23, 2023

Conversation

Iceber
Copy link
Contributor

@Iceber Iceber commented Aug 21, 2023

What type of PR is this?

/kind feature

What this PR does / why we need it:

Add showing of pinned information when using the crictl images command.

  1. crictl images -v prints Pinned when image is pinned
$ crictl images -v
// ignore some print...

ID: sha256:e6f1816883972d4be47bd48879a08919b96afcd344132622e4d444987919323c
RepoTags: k8s.m.daocloud.io/pause:3.9
RepoDigests: k8s.m.daocloud.io/pause@sha256:7031c1b283388d2c2e09b57badb803c05ebed362dc88d84b480cc47f72a21097
Size: 321520
Uid: &Int64Value{Value:65535,}

ID: sha256:261e6f4fa9213ab2648fe05c7c0abefe50a3ddd561dfa4547a415cd62d8e5fe2
RepoTags: quay.io/tigera/operator:v1.30.4
RepoDigests: quay.io/tigera/operator@sha256:780eeab342e62bd200e533a960b548216b23b8bde7a672c4527f29eec9ce2d79
Size: 21216944
Uid: &Int64Value{Value:10001,}

ID: sha256:ed210e3e4a5bae1237f1bb44d72a05a2f1e5c6bfe7a7e73da179e2534269c459
RepoTags: registry.aliyuncs.com/google_containers/pause:3.5
RepoDigests: registry.aliyuncs.com/google_containers/pause@sha256:1ff6c18fbef2045af6b9c16bf034cc421a29027b800e4f9b68ae9b1cb3e9ae07
Size: 301416
Uid: &Int64Value{Value:65535,}
Pinned: true
  1. add --pinned flag for crictl images
$ crictl images --pinned
IMAGE                                               TAG                 IMAGE ID            SIZE                PINNED
// ignore some print ....
k8s.m.daocloud.io/kube-scheduler                    v1.27.4             98ef2570f3cde       18.2MB              false
k8s.m.daocloud.io/pause                             3.9                 e6f1816883972       322kB               false
quay.io/tigera/operator                             v1.30.4             261e6f4fa9213       21.2MB              false
registry.aliyuncs.com/google_containers/pause       3.5                 ed210e3e4a5ba       301kB               true
crictl images --digests --pinned
IMAGE                                               TAG                 DIGEST              IMAGE ID            SIZE                PINNED
k8s.m.daocloud.io/kube-proxy                        v1.27.4             4bcb707da9898       6848d7eda0341       23.9MB              false
k8s.m.daocloud.io/kube-scheduler                    v1.27.4             5897d7a97d23d       98ef2570f3cde       18.2MB              false
k8s.m.daocloud.io/pause                             3.9                 7031c1b283388       e6f1816883972       322kB               false
quay.io/tigera/operator                             v1.30.4             780eeab342e62       261e6f4fa9213       21.2MB              false
registry.aliyuncs.com/google_containers/pause       3.5                 1ff6c18fbef20       ed210e3e4a5ba       301kB               true

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Add showing of pinned information when using the `crictl images` command.

Signed-off-by: Iceber Gu <caiwei95@hotmail.com>
@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Aug 21, 2023
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 21, 2023
Copy link
Member

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM

Can we add a release note to the body of this PR to document the change?

@Iceber
Copy link
Contributor Author

Iceber commented Aug 21, 2023

@saschagrunert updated, ptal

@saschagrunert
Copy link
Member

/approve

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 21, 2023
@afbjorklund
Copy link
Contributor

There is a"typo" in the description and commits, it says ctr images (containerd) when it means crictl images?

Verified that it also works with Docker, presuming that Mirantis/cri-dockerd#194 is patched into cri-dockerd first.

ID: sha256:e6f1816883972d4be47bd48879a08919b96afcd344132622e4d444987919323c
RepoTags: registry.k8s.io/pause:3.9
RepoDigests: registry.k8s.io/pause@sha256:7031c1b283388d2c2e09b57badb803c05ebed362dc88d84b480cc47f72a21097
Size: 743952
Pinned: true

@Iceber Iceber force-pushed the list_image_pinned branch from 89b5d79 to a248040 Compare August 21, 2023 09:46
@Iceber
Copy link
Contributor Author

Iceber commented Aug 21, 2023

There is a"typo" in the description and commits, it says ctr images (containerd) when it means crictl images?

Sorry, I misspelled the name of the command.

showDigest := c.Bool("digests")
quiet := c.Bool("quiet")
noTrunc := c.Bool("no-trunc")
if !verbose && !quiet {
row := []string{columnImage, columnTag}
if showPinned {
row = append(row, columnPinned)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a new column to the end? The column is not that important and in most cases will only be true for a single image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking is that when the user passes the --pinned flag, maybe he is trying to view the pinned information, so I put this column in front of it.
if I put it at the end this is what it would look like, one more line of code:

			row := []string{columnImage, columnTag}
			if showPinned {
				row = append(row, columnPinned)
			}
			row = append(row, columnImageID, columnSize)      
			if showDigest {
				row = append(row, columnDigest)
			}
			display.AddRow(row)

Of course, I'm keeping an open mind about the placement of this column, if you suggest putting it at the end , then I'll update this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to understand the history here. I think the --digests was added to match docker cli. And docker has it because there were no digests for older images: https://docs.docker.com/engine/reference/commandline/images/#digests

If we want to keep compatibility with docker, having an additional flag and not changing the default output makes sense.

It may be a good idea to create a test for this and explicitly mention that the ordering of columns and the default list of columns is driven by compatibility with the docker cli.

Ordering-wise I really don't like the idea of inserting column in the middle. If customer wants it - they can use template to specify the exact order of columns.

My suggestion will be to put pinned to be the last column.

@@ -155,6 +155,10 @@ var listImageCommand = &cli.Command{
Name: "no-trunc",
Usage: "Show output without truncating the ID",
},
&cli.BoolFlag{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why wouldn't we just output it by default without an explicit flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think this field was that important, so I left the default output format unchanged.

Of course I'm not particularly sure, I'll take everyone's advice on this

Signed-off-by: Iceber Gu <caiwei95@hotmail.com>
@Iceber Iceber force-pushed the list_image_pinned branch from a248040 to 7d7fd9b Compare August 23, 2023 04:12
@Iceber
Copy link
Contributor Author

Iceber commented Aug 23, 2023

@SergeyKanzhelev I've updated the description and code, PTAL, Thanks

Copy link
Member

@SergeyKanzhelev SergeyKanzhelev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 23, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Iceber, saschagrunert, SergeyKanzhelev

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit c6907c8 into kubernetes-sigs:master Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants