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

[Feature] Add command to list image tags #870

Merged
merged 2 commits into from
Nov 25, 2021
Merged

Conversation

iwilltry42
Copy link
Member

@iwilltry42 iwilltry42 commented Nov 23, 2021

What

New subcommand: k3d version list

Why

Users can choose image versions when creating a k3d cluster, e.g. the K3s version via the --image flag, so we'll ease looking the available versions up for them.

Implications

No breaking changes, just some convenience functionality

Notes

  • unauthenticated request and simple JSON parsing, so probably not 100% stable/reliable
    • on the other hand, we don't pull in any extra large dependencies and hassle with credential management
    • probably fine, since it's supposedly only used by humans every now and then and not on a super regular basis (e.g. by a CI system)
  • inspired by reply to this SO answer: https://stackoverflow.com/a/39454426/6450189

Example

List K3s docker image versions, but only for the major/minor version v1.21 and exclude all possible pre-release versions. Output should be formatted in a way that can be used with the --image` flag:

$ k3d version list k3s --include "^v1.21" -e ".+(rc|engine|alpha).*" --format repo
rancher/k3s:v1.21.0-k3s1
rancher/k3s:v1.21.0-k3s1-amd64
rancher/k3s:v1.21.0-k3s1-arm
rancher/k3s:v1.21.0-k3s1-arm64
rancher/k3s:v1.21.1-k3s1
rancher/k3s:v1.21.1-k3s1-amd64
rancher/k3s:v1.21.1-k3s1-arm
rancher/k3s:v1.21.1-k3s1-arm64
rancher/k3s:v1.21.2-k3s1
rancher/k3s:v1.21.2-k3s1-amd64
rancher/k3s:v1.21.2-k3s1-arm
rancher/k3s:v1.21.2-k3s1-arm64
rancher/k3s:v1.21.3-k3s1
rancher/k3s:v1.21.3-k3s1-amd64
rancher/k3s:v1.21.3-k3s1-arm
rancher/k3s:v1.21.3-k3s1-arm64
rancher/k3s:v1.21.4-k3s1
rancher/k3s:v1.21.4-k3s1-amd64
rancher/k3s:v1.21.4-k3s1-arm
rancher/k3s:v1.21.4-k3s1-arm64
rancher/k3s:v1.21.5-k3s1
rancher/k3s:v1.21.5-k3s1-amd64
rancher/k3s:v1.21.5-k3s1-arm
rancher/k3s:v1.21.5-k3s1-arm64
rancher/k3s:v1.21.5-k3s2
rancher/k3s:v1.21.5-k3s2-amd64
rancher/k3s:v1.21.5-k3s2-arm
rancher/k3s:v1.21.5-k3s2-arm64
rancher/k3s:v1.21.6-k3s1
rancher/k3s:v1.21.6-k3s1-amd64
rancher/k3s:v1.21.6-k3s1-arm
rancher/k3s:v1.21.6-k3s1-arm64

Get k3d-proxy versions to use with the environment variable K3D_IMAGE_LOADBALANCER.
Include only versions of k3d major version 5 and exclude all potential pre-release and os-arch tagged images.

$ k3d version list k3d-proxy --include "^5" -e ".+-.*" --format repo | sort -r
rancher/k3d-proxy:5.1.0
rancher/k3d-proxy:5.1
rancher/k3d-proxy:5.0.3
rancher/k3d-proxy:5.0.2
rancher/k3d-proxy:5.0.1
rancher/k3d-proxy:5.0.0
rancher/k3d-proxy:5.0
rancher/k3d-proxy:5

Links

Fixes #846

@iwilltry42 iwilltry42 added enhancement New feature or request scope/cli Issue concerns the CLI (cmd/) labels Nov 23, 2021
@iwilltry42 iwilltry42 added this to the v5.2.0 milestone Nov 23, 2021
@iwilltry42 iwilltry42 self-assigned this Nov 23, 2021
@iwilltry42 iwilltry42 requested a review from nunix November 23, 2021 21:30
Copy link

@nunix nunix left a comment

Choose a reason for hiding this comment

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

LGTM

@nunix
Copy link

nunix commented Nov 24, 2021

That's great, thanks a lot.

I would just "change" the listing to exclude by default the rc versions and make the example of listing including them.
It would be more aligned with Rancher Desktop versioning suggestion too.

For sorting, it's open, I totally get that seeing the highest version in the end, so we don't scroll back, is good. However, compared to Rancher Desktop versions (yes it's a gui list), and other K8s distros, the order is normally reverse to the highest version is right after the command.

But again, this might really be just a matter of personal taste.

Great job, once again ⭐

@iwilltry42 iwilltry42 force-pushed the feature/list-k3s-tags branch from c260b7d to 0d707a0 Compare November 25, 2021 15:07
@iwilltry42
Copy link
Member Author

@nunix , thanks for the feedback, really good!

I added a default exclude filter and flags for sorting (asc | desc (default) | off) and limiting the output 👍

@iwilltry42 iwilltry42 merged commit 9b326c2 into main Nov 25, 2021
@iwilltry42 iwilltry42 deleted the feature/list-k3s-tags branch November 25, 2021 15:39
@iwilltry42 iwilltry42 modified the milestones: v5.3.0, v5.1.1 Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request scope/cli Issue concerns the CLI (cmd/)
Projects
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add command to list K3s image tags
2 participants