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

Fixes #38072 - add host bootc_images endpoint #11257

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ianballou
Copy link
Member

What are the changes introduced in this pull request?

Adds a new /hosts/bootc_images endpoint that returns an overview of all bootc images that hosts are using.

The return data looks like the following:

{
  "total": 499,
  "bootc_images": [
    [
      "quay.io/centos-bootc/centos-bootc:stream10",
      [
        {
          "bootc_booted_digest": "sha256:54256a998f0c62e16f3927c82b570f90bd8449a52e03daabd5fd16d6419fd572",
          "host_count": 1
        }
      ]
    ]
  ]
}

This data will power a page that shows a list of image paths and each image mode host that is using that image path. Since each host could use the same image but a different digest, each image path holds any number of digests with the count of hosts that are using that digest. More digests per image path means more drift from the latest container content under that container tag.

Considerations taken when implementing this change?

Choosing where this goes was difficult -- it's related to hosts so I decided to stick it under the hosts endpoint. I use facts as a similar paradigm: host facts and bootc images are both aggregate information from hosts that are available at a single API endpoint.

What are the testing steps for this pull request?

  1. Make a bunch of different bootc hosts. You can use the following script to create one clone:
#!/bin/bash

uuid=$(uuidgen)
short=$(hostname -s)
domain=manicotto.example.com
echo "{\"dmi.system.uuid\": \"${uuid}\"}" > /etc/rhsm/facts/uuid.facts
hostnamectl set-hostname ${short}.${uuid%%-*}.${domain}
subscription-manager clean
subscription-manager register --activationkey "Default Library Key" --org "Default_Organization"
  1. Query the endpoint, test with and without paging
curl "https://`hostname`/api/hosts/bootc_images?per_page=5&page=7" -uadmin:pass
  1. Ensure that empty conditions work, check page sizes that don't make sense, etc.

@ianballou
Copy link
Member Author

Rubocop errors are unrelated & on master.

@ianballou ianballou force-pushed the 38072-bootc-overview-api branch from dd43f60 to 7bbefa8 Compare December 16, 2024 16:21
@sjha4
Copy link
Member

sjha4 commented Dec 16, 2024

Does it make sense to add filtering params to this API endpoint? Like filter for hosts or digest etc?

@ianballou
Copy link
Member Author

ianballou commented Dec 16, 2024

Does it make sense to add filtering params to this API endpoint? Like filter for hosts or digest etc?

I think it makes sense, it would enable there to be a search bar in the UI.

Question is, which params should we support? Perhaps:

  • Host name
  • Container image path
  • Container image digest

@ianballou
Copy link
Member Author

I'm thinking I might need to make some changes to how the returned data is structured to better suit UI development. Seems like more keys might be expected. I'd also like to follow the general standard we have where results is the top-level key.

"name" before the image path might be one key I should add.

@ianballou
Copy link
Member Author

I've added full support for scoped_search searching via the Host::Managed model. My only regret is that I have to load up the host IDs first and then create the content facets query, but I don't see a good way yet to combine the two queries into one.
The performance with 6579 hosts still seems fine.

@ianballou ianballou force-pushed the 38072-bootc-overview-api branch from 29a8e15 to 723f2e8 Compare December 17, 2024 22:11
content_facets = ::Katello::Host::ContentFacet.where(host_id: ::Host::Managed.joins(:content_facet).search_for(host_search).pluck(:id))
aggregate_bootc_data = content_facets.where.not(bootc_booted_image: nil, bootc_booted_digest: nil).
select(:bootc_booted_image, :bootc_booted_digest, 'COUNT(hosts.id) as host_count').
joins(:host).group(:bootc_booted_image, :bootc_booted_digest).order(:bootc_booted_image)
Copy link
Member

Choose a reason for hiding this comment

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

This order would need to be parameterized based on API param.

@ianballou ianballou force-pushed the 38072-bootc-overview-api branch 2 times, most recently from 573a441 to c1b3695 Compare December 23, 2024 16:38
@ianballou
Copy link
Member Author

Sorting support is in!

Copy link
Member

@sjha4 sjha4 left a comment

Choose a reason for hiding this comment

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

APJ..Code looks good..Everything works well in testing..👍

@ianballou ianballou force-pushed the 38072-bootc-overview-api branch from c1b3695 to 81a551d Compare December 23, 2024 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants