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 commands to get index of booted, pending and previous deployments #3144

Closed
wants to merge 1 commit into from

Conversation

p5
Copy link
Contributor

@p5 p5 commented Jan 22, 2024

Closes #3142

Right now, it's difficult to pin the current deployment without needing to look into the output of some other tooling (like rpm-ostree) to get the index of each deployment. This index also is not consistent - the current deployment could be 0 when you first boot the system then 1 shortly after.

This change makes it easy to get the index of the current or future deployment so it can be piped into other commands (such as ostree admin pin).

(Please note: I have not yet built or tested this PR - I am working on figuring out how to compile it)

Huge thanks to Eric for authoring this patch for me!

TODO before merge:

  • Squash all commits into one
  • Get confirmation for flag descriptions & man pages
  • Confirm the new functionality works locally

Co-authored-by: Eric Curtin [email protected]

Copy link

openshift-ci bot commented Jan 22, 2024

Hi @p5. Thanks for your PR.

I'm waiting for a ostreedev member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@p5 p5 force-pushed the get-current-deployment-index branch 2 times, most recently from 278b1b3 to 15f4dba Compare January 22, 2024 22:31
@p5 p5 requested a review from ericcurtin January 22, 2024 22:35
@ericcurtin
Copy link
Collaborator

Will need equivalent man page updates too.

You can also collapse those 3 else if's into ingel return statements if you write a function that takes two parameters.

I'm in bed now but I can write the function signature in the morning to point you in the right direction.

@ericcurtin
Copy link
Collaborator

Noticed your comment about how to build... I use this:

https://github.com/ericcurtin/staging/blob/master/build.sh

@p5
Copy link
Contributor Author

p5 commented Jan 23, 2024

Will need equivalent man page updates too.

You can also collapse those 3 else if's into ingel return statements if you write a function that takes two parameters.

I believe I have done this:

I will mark this as draft for now as there's a high chance I have messed something up and want to test this out locally. TomorrowLater today (It's 1:30am)...
I will also squash these commits once all changes have been checked over.

But please let me know if the refactoring is not what you intended.

@p5 p5 marked this pull request as draft January 23, 2024 01:19
@p5
Copy link
Contributor Author

p5 commented Jan 23, 2024

Ah, just found you already upload built binaries during CI, so that makes testing these changes locally so much easier!
I believe everything is working as expected!

Command outputs:

☁  bin  ./ostree admin status -b    
1
☁  bin  ./ostree admin status -p
0
☁  bin  ./ostree admin status -r
2

RPM Ostree Status:

State: idle
AutomaticUpdates: stage; rpm-ostreed-automatic.timer: last run 15h ago
Deployments:
  ostree-image-signed:registry:ghcr.io/rsturla/eternal-linux/lumina:39-nvidia (index: 0)
                   Digest: sha256:a3f55eb777e88c71a692e655c838fd8e6b48186f8422d2630b96bea85a09e71a
                  Version: 39.20240121.0 (2024-01-22T02:11:23Z)
               BaseCommit: 345d49ead85e7f6b14ae171861f8e66c65c3bad8a79a9e8c90980c0d139e3c0d
                   Commit: a7647d086bf0263fa0a56497d4a418fd3b6a29c6219fe30a88a279449f7a8528
                           ├─ 1password (2023-12-30T00:40:06Z)
                           ├─ fedora (2023-11-01T00:12:39Z)
                           ├─ fedora-cisco-openh264 (2023-03-14T10:57:01Z)
                           ├─ fedora-cisco-openh264-debuginfo (2023-03-14T10:57:01Z)
                           ├─ google-chrome (2024-01-18T15:42:25Z)
                           ├─ updates (2024-01-22T01:06:29Z)
                           └─ updates-archive (2024-01-22T01:30:46Z)
                   Staged: yes
                StateRoot: fedora
          LayeredPackages: 1password google-chrome-stable

● ostree-image-signed:registry:ghcr.io/rsturla/eternal-linux/lumina:39-nvidia (index: 1)
                   Digest: sha256:815aa0b03438ca450484a8ef2e3c63ec4b0fae41a36836c80e6e8837524e0fe6
                  Version: 39.20240121.0 (2024-01-21T13:26:40Z)
               BaseCommit: b07f32f84ed89fa31bf3765be9f880edf316298e4a626518d87910679e4a230e
                   Commit: a31e463b9501a09a431a1f25c455fb5299d45d5e92486eb54ef1db411458e904
                           ├─ 1password (2023-12-30T00:40:06Z)
                           ├─ fedora (2023-11-01T00:12:39Z)
                           ├─ fedora-cisco-openh264 (2023-03-14T10:57:01Z)
                           ├─ fedora-cisco-openh264-debuginfo (2023-03-14T10:57:01Z)
                           ├─ google-chrome (2024-01-18T15:42:25Z)
                           ├─ updates (2024-01-21T03:22:03Z)
                           └─ updates-archive (2024-01-21T03:46:07Z)
                StateRoot: fedora
          LayeredPackages: 1password google-chrome-stable

  ostree-image-signed:registry:ghcr.io/rsturla/eternal-linux/lumina:39-nvidia (index: 2)
                   Digest: sha256:8ea385f222b1fdaf8aeebd30ade54c33db457e20b2539c4320b6eeae82815472
                  Version: 39.20240120.0 (2024-01-21T01:48:06Z)
               BaseCommit: 01c6ea8c5e991f74c001c55b4360a4355ff044faafe2f4229b7a5c2859217934
                   Commit: e926c5f3a8eea670eb5ec2d983431de8fe201cabf6c89fef9b817584dda110e9
                           ├─ 1password (2023-12-30T00:40:06Z)
                           ├─ fedora (2023-11-01T00:12:39Z)
                           ├─ fedora-cisco-openh264 (2023-03-14T10:57:01Z)
                           ├─ fedora-cisco-openh264-debuginfo (2023-03-14T10:57:01Z)
                           ├─ google-chrome (2024-01-18T15:42:25Z)
                           ├─ updates (2024-01-20T03:14:28Z)
                           └─ updates-archive (2024-01-20T03:39:19Z)
                StateRoot: fedora
          LayeredPackages: 1password google-chrome-stable

  ostree-image-signed:registry:ghcr.io/rsturla/eternal-linux/lumina:39-nvidia (index: 3)
                   Digest: sha256:0eb71fc0fedc315224dcc0facbab0889a1002582a4f92fa8c399163f6e0e2bf2
                  Version: 39.20240118.0 (2024-01-18T13:31:30Z)
               BaseCommit: e9e6740ab9998898792320d0ff773c03f38e232ccf2bf64314422260a293c420
                   Commit: c959c74c35711466eed42789a9c1d297caa0c9bc2840bd94e254e6e5e70bec75
                           ├─ 1password (2023-12-30T00:40:06Z)
                           ├─ fedora (2023-11-01T00:12:39Z)
                           ├─ fedora-cisco-openh264 (2023-03-14T10:57:01Z)
                           ├─ fedora-cisco-openh264-debuginfo (2023-03-14T10:57:01Z)
                           ├─ google-chrome (2024-01-16T18:03:56Z)
                           ├─ rpmfusion-free (2023-11-04T16:49:08Z)
                           ├─ rpmfusion-free-updates (2024-01-12T08:11:53Z)
                           ├─ rpmfusion-nonfree (2023-11-04T17:26:32Z)
                           ├─ rpmfusion-nonfree-updates (2024-01-12T08:27:46Z)
                           ├─ updates (2024-01-18T01:40:54Z)
                           └─ updates-archive (2024-01-18T02:04:23Z)
                StateRoot: fedora
          LayeredPackages: 1password google-chrome-stable
                   Pinned: yes

Man page:

OSTREE ADMIN STATUS(1)                                                                                     ostree admin status                                                                                    OSTREE ADMIN STATUS(1)

NAME
       ostree-admin-status - List deployments

SYNOPSIS

       ostree admin status

DESCRIPTION
       Lists the deployments available to be booted into. Includes osname, the checksum followed by the deploy serial, and the refspec. An asterisk indicates the current booted deployment.

OPTIONS
       --sysroot="PATH"
           Create a new OSTree sysroot at PATH

       -V, --verify
           Print the commit verification status

       -S, --skip-signatures
           Skip signatures in output

       -D, --is-default
           Output the string default if the default deployment is the booted one, not-default if we are booted in a non-default deployment (e.g. the user interactively chose a different entry in the bootloader menu, or the
           bootloader rolled back automatically, etc.). If we are not in a booted OSTree system, an error is returned.

       -b, --booted-index
           Print the index of the booted deployment. If we are not in a booted OSTree system, an error is returned.

       -p, --pending-index
           Print the index of the pending deployment. If we are not in a booted OSTree system, an error is returned.

       -r, --rollback-index
           Print the index of the rollback deployment. If we are not in a booted OSTree system, an error is returned.

       -v, --verbose
           Print debug information during command processing

       --version
           Print version information and exit

EXAMPLE
       $ ostree admin status

                   * gnome-ostree 67e382b11d213a402a5313e61cbc69dfd5ab93cb07.0
                       origin refspec: gnome-ostree/buildmain/x86_64-runtime
                     gnome-ostree ce19c41036cc45e49b0cecf6b157523c2105c4de1c.0
                       origin refspec: gnome-ostree/buildmain/x86_64-runtime

Now I've confirmed it seems to work, the only remaining things are to find out how you intended the refactoring to look and for me to squash all commits.

@ericcurtin
Copy link
Collaborator

ericcurtin commented Jan 23, 2024

After you build locally, you can test from the git repo using commands like:

LD_LIBRARY_PATH=.libs ./.libs/ostree admin status -r

I pulled the branch down, de-duplicated the code further, made some other styling changes to be consistent with the rest of the project (we don't do camelCase for example for variable names, although types have it).

I squashed the commits. Fixed up the commit message (we put "status: " for example in the commit message when we change this part). The angular brackets were missing in the Co-authored-by for example, if we push this, we should be pretty good:

ericcurtin@f892522

@ericcurtin
Copy link
Collaborator

Also had to remove changes accidentally made to libglnx, that may have been my mistake, unsure...

@p5 p5 force-pushed the get-current-deployment-index branch from 7b60e5f to 5242e56 Compare January 23, 2024 09:47
Add new commands to output the current, staged and previous deployment for use in automation and scripting.
Right now, it's difficult to pin the current deployment without needing to look into the output of some other tooling (like rpm-ostree) to get the index of each deployment.  This index also is not consistent - the current deployment could be 0 when you first boot the system then 1 shortly after.
This change makes it easy to get the index of the current or future deployment so it can be piped into other commands (such as ostree admin pin).

Huge thanks to Eric for authoring this patch for me!

Co-authored-by: Eric Curtin <[email protected]>
Signed-off-by: Robert Sturla <[email protected]>
@p5 p5 force-pushed the get-current-deployment-index branch from 5242e56 to 22d5602 Compare January 23, 2024 09:48
@p5
Copy link
Contributor Author

p5 commented Jan 23, 2024

I squashed the commits. Fixed up the commit message (we put "status: " for example in the commit message when we change this part). The angular brackets were missing in the Co-authored-by for example, if we push this, we should be pretty good:
ericcurtin@f892522

All changes have been made.

I'm not sure where "changes accidentally made to libglnx" could be found in your commit, so if I have missed something, please let me know.

And sorry it's taken so many revisions to get something that's in a good enough state. I'm not familiar at all with C so it was very much trial and error to get something that seemed right and CI didn't shout at.

@ericcurtin
Copy link
Collaborator

ericcurtin commented Jan 23, 2024

I squashed the commits. Fixed up the commit message (we put "status: " for example in the commit message when we change this part). The angular brackets were missing in the Co-authored-by for example, if we push this, we should be pretty good:
ericcurtin@f892522

All changes have been made.

I'm not sure where "changes accidentally made to libglnx" could be found in your commit, so if I have missed something, please let me know.

And sorry it's taken so many revisions to get something that's in a good enough state. I'm not familiar at all with C so it was very much trial and error to get something that seemed right and CI didn't shout at.

Well you did a pretty amazing job at it for someone that doesn't know C! 😄 This LGTM, once Draft is removed I think we can merge unless another ostree maintainer wants to look at this also in the next 24 hours.

@p5 p5 marked this pull request as ready for review January 23, 2024 10:14
@ericcurtin
Copy link
Collaborator

As an aside, I'm looking for someone in the community with cycles and an Apple Silicon device to look at this:

ericcurtin/fedora-asahi-ostree-desktops#1

if you know of someone that wants to look at this let me know.

It's hard for me to justify looking at it, as my Apple Silicon device is my daily driver and it blocks my Automotive work when I start flashing and rebooting it to test Asahi Kinoite/Silverblue.

@ericcurtin
Copy link
Collaborator

/ok-to-test

@jlebon
Copy link
Member

jlebon commented Jan 23, 2024

Not strongly against, though these options seem somewhat obscure. I think probably what we want instead is e.g. ostree admin pin --booted.

That said, note you can also do something like rpm-ostree status --json | jq '.deployments | map(.booted) | index(true)' if you want a one-liner way to get the booted deployment index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Alias to pin current deployment
3 participants