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 list AMIs command to clusterawsadm #2304

Merged
merged 1 commit into from
Apr 9, 2021

Conversation

sedefsavas
Copy link
Contributor

@sedefsavas sedefsavas commented Mar 15, 2021

/kind feature

What this PR does / why we need it:
This PR adds a list command to clusterawsadm to list AMIs based on OS, region, and Kubernetes version.

clusterawsadm ami list --kubernetes-version=v1.18.12 --os=ubuntu-20.04 --region=us-west-2

If none of the flags are used (clusterawsadm ami list), lists AMIs in all supported regions, OSes, and supported Kubernetes versions (N-2).

Example output:

$ clusterawsadm ami list --kubernetes-version=v1.19.3 -o json
{
  "AMIs": [
    {
      "os": "centos-7",
      "region": "ap-northeast-1",
      "amiID": "ami-08cc1e47b38d69085",
      "creationDate": "2020-11-14T21:33:51.000Z",
      "kubernetesVersion": "v1.19.3",
      "name": "capa-ami-centos-7-1.19.3-00-1605388645"
    },
    {
      "os": "ubuntu-18.04",
      "region": "ap-northeast-1",
      "amiID": "ami-006d394ac4256d33f",
      "creationDate": "2020-11-14T21:31:13.000Z",
      "kubernetesVersion": "v1.19.3",
      "name": "capa-ami-ubuntu-18.04-1.19.3-00-1605388698"
    },
 ],
}


$ clusterawsadm ami list --os=ubuntu-20.04 --region=us-west-2 -o table    
KUBERNETES-VERSION   REGION      OS             NAME                                          AMI-ID
v1.20.5              us-west-2   ubuntu-20.04   capa-ami-ubuntu-20.04-1.20.5-00-1616559327    ami-0d113dce59b31b889
v1.19.9              us-west-2   ubuntu-20.04   capa-ami-ubuntu-20.04-1.19.9-00-1616561685    ami-08d2e02e495ee1f75
v1.18.17             us-west-2   ubuntu-20.04   capa-ami-ubuntu-20.04-1.18.17-00-1616561896   ami-07ade7df8dc883555


Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #2040

Special notes for your reviewer:

Checklist:

  • squashed commits
  • includes documentation
  • adds unit tests
  • adds or updates e2e tests
Add `clusterawsadm ami list` command to list AMIs that can be filtered by region, OS, and Kubernetes version.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 15, 2021
@k8s-ci-robot k8s-ci-robot requested review from dthorsen and rudoi March 15, 2021 17:43
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 15, 2021
@sedefsavas sedefsavas mentioned this pull request Mar 19, 2021
4 tasks
@randomvariable
Copy link
Member

randomvariable commented Apr 7, 2021

The programmatic output doesn't really work if i run -o json

------------------------------------
KUBERNETES VERSION:  v1.20.5:
------------------------------------
{"kind":"Table","apiVersion":"meta.k8s.io/v1","metadata":{},"columnDefinitions":[{"name":"OS","type":"string","format":"","description":"","priority":0},{"name":"REGION","type":"string","format":"","description":"","priority":0},{"name":"AMI-ID","type":"string","format":"","description":"","priority":0}],"rows":[{"cells":["centos-7","ap-northeast-1","ami-03424c0440ed87374"],"object":null},{"cells":["centos-7","ap-northeast-2","ami-041b503198fa744e0"],"object":null},{"cells":["centos-7","ap-south-1","ami-06efc29cae4029c49"],"object":null},{"cells":["centos-7","ap-southeast-1","ami-0b51079f8bd6a2d39"],"object":null},{"cells":["centos-7","ap-northeast-2","ami-041b503198fa744e0"],"object":null},{"cells":["centos-7","ca-central-1","ami-067365ee1ab88c9bc"],"object":null},{"cells":["centos-7","eu-central-1","ami-001e143e0a7ac2eb2"],"object":null},{"cells":["centos-7","eu-west-1","ami-00c0cef018ca8cfa0"],"object":null},{"cells":["centos-7","eu-west-2","ami-094c7d76bacb3d5d2"],"object":null},{"cells":["centos-7","eu-west-3","ami-094aa699bf305f493"],"object":null},{"cells":["centos-7","sa-east-1","ami-0cd3ae610d0e7d50d"],"object":null},{"cells":["centos-7","us-east-1","ami-05e3ef28c5b540f9a"],"object":null},{"cells":["centos-7","us-east-2","ami-065544363881aca0d"],"object":null},{"cells":["centos-7","us-west-1","ami-09f6a4223114a69ed"],"object":null},{"cells":["centos-7","us-west-2","ami-0a2c2f95723c814d2"],"object":null},{"cells":["ubuntu-18.04","ap-northeast-1","ami-0e81ffe47c24b0507"],"object":null},{"cells":["ubuntu-18.04","ap-northeast-2","ami-017ce6ff84974d47f"],"object":null},{"cells":["ubuntu-18.04","ap-south-1","ami-0751f7b7235180361"],"object":null},{"cells":["ubuntu-18.04","ap-southeast-1","ami-0d861a9fa4d6dd9ce"],"object":null},{"cells":["ubuntu-18.04","ap-northeast-2","ami-017ce6ff84974d47f"],"object":null},{"cells":["ubuntu-18.04","ca-central-1","ami-0524e733a55d5eaef"],"object":null},{"cells":["ubuntu-18.04","eu-central-1","ami-0b6d4adee70d844b8"],"object":null},{"cells":["ubuntu-18.04","eu-west-1","ami-0c993941a087cf441"],"object":null},{"cells":["ubuntu-18.04","eu-west-2","ami-0a2d8123bc164f0bf"],"object":null},{"cells":["ubuntu-18.04","eu-west-3","ami-0bf88f9f752728b91"],"object":null},{"cells":["ubuntu-18.04","sa-east-1","ami-0205692a2ad5af511"],"object":null},{"cells":["ubuntu-18.04","us-east-1","ami-0c30e629d1dc49976"],"object":null},{"cells":["ubuntu-18.04","us-east-2","ami-0ffff56df5ee51ee1"],"object":null},{"cells":["ubuntu-18.04","us-west-1","ami-0cf1339fbdfa78f4a"],"object":null},{"cells":["ubuntu-18.04","us-west-2","ami-01277762e90a230f6"],"object":null},{"cells":["ubuntu-20.04","ap-northeast-1","ami-0cae4eb5ecafd4cf0"],"object":null},{"cells":["ubuntu-20.04","ap-northeast-2","ami-0ae4033c1c93e046a"],"object":null},{"cells":["ubuntu-20.04","ap-south-1","ami-01a799db01860f703"],"object":null},{"cells":["ubuntu-20.04","ap-southeast-1","ami-0c863e6be52760a14"],"object":null},{"cells":["ubuntu-20.04","ap-northeast-2","ami-0ae4033c1c93e046a"],"object":null},{"cells":["ubuntu-20.04","ca-central-1","ami-01f7acf2ea7f87330"],"object":null},{"cells":["ubuntu-20.04","eu-central-1","ami-0af6931ba94a5cf7a"],"object":null},{"cells":["ubuntu-20.04","eu-west-1","ami-0e896f9cc998184b6"],"object":null},{"cells":["ubuntu-20.04","eu-west-2","ami-07c467c9bfbcae6c5"],"object":null},{"cells":["ubuntu-20.04","eu-west-3","ami-06096520db23370ec"],"object":null},{"cells":["ubuntu-20.04","sa-east-1","ami-0b4d6bca29cdf1ad1"],"object":null},{"cells":["ubuntu-20.04","us-east-1","ami-0cb706f5d97e6873c"],"object":null},{"cells":["ubuntu-20.04","us-east-2","ami-0a823215d96a2c94d"],"object":null},{"cells":["ubuntu-20.04","us-west-1","ami-04bbb45feae84cb40"],"object":null},{"cells":["ubuntu-20.04","us-west-2","ami-0d113dce59b31b889"],"object":null},{"cells":["amazon-2","ap-northeast-1","ami-0c8314f66ad119184"],"object":null},{"cells":["amazon-2","ap-northeast-2","ami-0bde38bdb2f8f93d8"],"object":null},{"cells":["amazon-2","ap-south-1","ami-0faf81c8dfac5f689"],"object":null},{"cells":["amazon-2","ap-southeast-1","ami-0e1eb33e49df3010a"],"object":null},{"cells":["amazon-2","ap-northeast-2","ami-0bde38bdb2f8f93d8"],"object":null},{"cells":["amazon-2","ca-central-1","ami-00cb6811a62ad4c41"],"object":null},{"cells":["amazon-2","eu-central-1","ami-09c26841321b3fcd6"],"object":null},{"cells":["amazon-2","eu-west-1","ami-0412a962d8c9d06db"],"object":null},{"cells":["amazon-2","eu-west-2","ami-0c02411386619ac9e"],"object":null},{"cells":["amazon-2","eu-west-3","ami-0fd6d38607dba3d1d"],"object":null},{"cells":["amazon-2","sa-east-1","ami-0962b6943266ed666"],"object":null},{"cells":["amazon-2","us-east-1","ami-0c8e9685202d2f054"],"object":null},{"cells":["amazon-2","us-east-2","ami-085b7748147d02c89"],"object":null},{"cells":["amazon-2","us-west-1","ami-0aeb399d1172ac1f2"],"object":null},{"cells":["amazon-2","us-west-2","ami-00fef67d63ca399b0"],"object":null}]}^Csignal: interrupt

First of all, the header isn't JSON and will break consumers, and then probably don't want the Table output as JSON

I'd probably want an array of AMIs, like

[
  {
    "amiID": "ami-0b4a11b337f543a7a",
     "name":  "capa-ami-amazon-2-1.19.9-00-1616561545",
     "creationDate": "2021-03-24T05:01:45.000Z"
     "kubernetesVersion": "v1.19.9"
  },
...
]

Given that the API call is super slow and expensive, it's probably quicker to fetch all AMIs owned by the account, and sort in memory.

The output also needs deduping, with duplicate AMIs shown.
Finally, for a given Kubernetes version, we may build an AMI more than once, say for example to address a kernel CVE. In this case, I want to know which is the more recent AMI. Displaying the full name of the AMI as well as the date of registration will be helpful here.

I would remove the big

------------------------------------
KUBERNETES VERSION:  v1.20.5:
------------------------------------

header, given that there is a flag that allows the user to filter on the version anyway.

Instead, give the user a deduped, sorted list, sorted by:

Kubernetes version (descending)
For each Kubernetes version, sort by region, show only latest AMI for that region.

@randomvariable
Copy link
Member

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: randomvariable

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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 9, 2021
@k8s-ci-robot k8s-ci-robot merged commit 81850ee into kubernetes-sigs:master Apr 9, 2021
@randomvariable randomvariable deleted the listamis branch April 9, 2021 19:41
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. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add command to clusterawsadm to list AMIs
4 participants