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 some format to the ListImages, such as templates or JSON #11165

Closed
afbjorklund opened this issue Apr 21, 2021 · 11 comments · Fixed by #12996
Closed

Add some format to the ListImages, such as templates or JSON #11165

afbjorklund opened this issue Apr 21, 2021 · 11 comments · Fixed by #12996
Assignees
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/backlog Higher priority than priority/awaiting-more-evidence.

Comments

@afbjorklund
Copy link
Collaborator

afbjorklund commented Apr 21, 2021

Follow-up to #10933

Currently ListImages API returns the images in a fixed text format...

        // ListImages returns a list of images managed by this container runtime
        ListImages(ListImagesOptions) ([]string, error)

minikube image ls

k8s.gcr.io/pause:3.2
k8s.gcr.io/kube-scheduler:v1.20.2
k8s.gcr.io/kube-proxy:v1.20.2
k8s.gcr.io/kube-controller-manager:v1.20.2
k8s.gcr.io/kube-apiserver:v1.20.2
k8s.gcr.io/etcd:3.4.13-0
k8s.gcr.io/coredns:1.7.0
gcr.io/k8s-minikube/storage-provisioner:v5
docker.io/library/busybox:latest
docker.io/kubernetesui/metrics-scraper:v1.0.4
docker.io/kubernetesui/dashboard:v2.1.0

NOTE: That "busybox" image came from the cache:

{
    "cache": {
        "busybox": null
    }
}

As suggested, it could be useful with other formats: #11007 (review)


crictl offers three different formats:

table (default)

minikube ssh -- sudo crictl images --output table k8s.gcr.io/pause

IMAGE               TAG                 IMAGE ID            SIZE
k8s.gcr.io/pause    3.2                 80d28bedfe5de       683kB

json

minikube ssh -- sudo crictl images --output json k8s.gcr.io/pause
{
  "images": [
    {
      "id": "sha256:80d28bedfe5dec59da9ebf8e6260224ac9008ab5c11dbbe16ee3ba3e4439ac2c",
      "repoTags": [
        "k8s.gcr.io/pause:3.2"
      ],
      "repoDigests": [
        "k8s.gcr.io/pause@sha256:927d98197ec1141a368550822d18fa1c60bdae27b78b0c004f705f548c07814f"
      ],
      "size": "682696",
      "uid": null,
      "username": ""
    }
  ]
}

yaml

minikube ssh -- sudo crictl images --output yaml k8s.gcr.io/pause

images:
- id: sha256:80d28bedfe5dec59da9ebf8e6260224ac9008ab5c11dbbe16ee3ba3e4439ac2c
  repoDigests:
  - k8s.gcr.io/pause@sha256:927d98197ec1141a368550822d18fa1c60bdae27b78b0c004f705f548c07814f
  repoTags:
  - k8s.gcr.io/pause:3.2
  size: "682696"
  uid: null
  username: ""
@afbjorklund afbjorklund added kind/feature Categorizes issue or PR as related to a new feature. priority/backlog Higher priority than priority/awaiting-more-evidence. labels Apr 21, 2021
@tharun208
Copy link
Contributor

Can we pick this once #11406 is done?

@afbjorklund
Copy link
Collaborator Author

You don't have to wait for the default to change.

@afbjorklund
Copy link
Collaborator Author

afbjorklund commented May 21, 2021

For this issue one adds something to the ListImagesOptions, and then implements it for all the different CRI in their ListImages.

// ListImagesOptions are the options to use for listing images
type ListImagesOptions struct {
    // Format is the output format
    Format string
}
       // ListImages returns a list of images managed by this container runtime
        ListImages(ListImagesOptions) ([]string, error)

Finally add it to the cmd.

@tharun208
Copy link
Contributor

@afbjorklund I like to work on this

@tharun208
Copy link
Contributor

/assign

@tharun208
Copy link
Contributor

But, in docker, there is no option to show output as yaml or json. what to do in that case?

@afbjorklund
Copy link
Collaborator Author

afbjorklund commented May 23, 2021

But, in docker, there is no option to show output as yaml or json. what to do in that case?

It is a bit hidden: docker images --format '{{json .}}'

You should probably pick one format internally (json), and then maybe add yaml to the output...

There is no need to use different output for the internal implementation, so just stick with JSON.

The idea was to have one json document per string (line).


Currently ListImages outputs the image id.

k8s.gcr.io/pause:3.2

Instead, the output should be a JSON document:

{"id":"sha256:80d28bedfe5dec59da9ebf8e6260224ac9008ab5c11dbbe16ee3ba3e4439ac2c","repoTags":["k8s.gcr.io/pause:3.2"],"repoDigests":["k8s.gcr.io/pause@sha256:927d98197ec1141a368550822d18fa1c60bdae27b78b0c004f705f548c07814f"],"size":"682696","uid":null,"username":""}

Probably skip the "uid" and "username", no ?

Maybe convert the size from string to integer.

When this feature is available in the API, it can be parsed and converted to output in the CLI.

Note that you would have to convert the output from Docker, in order to match the one from CRI.

{"Containers":"N/A","CreatedAt":"2020-02-14 19:51:50 +0100 CET","CreatedSince":"15 months ago","Digest":"\u003cnone\u003e","ID":"80d28bedfe5d","Repository":"k8s.gcr.io/pause","SharedSize":"N/A","Size":"683kB","Tag":"3.2","UniqueSize":"N/A","VirtualSize":"682.7kB"}

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 21, 2021
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Sep 20, 2021
@medyagh
Copy link
Member

medyagh commented Sep 22, 2021

@tharun208 are you still working on this ?

@medyagh medyagh added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Sep 22, 2021
@spowelljr spowelljr added lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. and removed lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. labels Oct 13, 2021
@presztak
Copy link
Member

I started working on this.
/assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/backlog Higher priority than priority/awaiting-more-evidence.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants