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

admin/pin: Add commands to pin booted, pending and rollbacks deployments #3146

Conversation

ericcurtin
Copy link
Collaborator

@ericcurtin ericcurtin commented Jan 24, 2024

Add new commands to pin 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 pin the current or future deployment.

Co-authored-by: Robert Sturla robertsturla@outlook.com
Signed-off-by: Eric Curtin ecurtin@redhat.com

@ericcurtin
Copy link
Collaborator Author

Linked to #3144 , must complete man pages.

@ericcurtin ericcurtin force-pushed the ot-admin-builtin-pin-booted-pending-rollback branch from 8c17329 to 48a03c7 Compare January 24, 2024 16:39
Copy link
Member

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

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

I'm OK with this, but how about extending our syntax to accept an integer or booted|pending|rollback? IOW it'd just be

ostree admin pin rollback

@ericcurtin
Copy link
Collaborator Author

@cgwalters ok, I'll just change it to a string comparison, it will be 95% the same code

@ericcurtin ericcurtin force-pushed the ot-admin-builtin-pin-booted-pending-rollback branch from 48a03c7 to 6b4415a Compare January 26, 2024 19:10
@ericcurtin
Copy link
Collaborator Author

This one is ready for review

@ericcurtin ericcurtin force-pushed the ot-admin-builtin-pin-booted-pending-rollback branch from 6b4415a to 9db5d13 Compare January 26, 2024 20:17
Comment on lines 45 to 46
for (gint i = 0; i < deployments->len; ++i)
if (deployments->pdata[i] == target_deployment)
Copy link
Member

Choose a reason for hiding this comment

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

BTW our style generally prefers braces { in these types of cases, really braceless is only for a simple if, but this is irrelevant per above

Copy link
Collaborator Author

@ericcurtin ericcurtin Jan 26, 2024

Choose a reason for hiding this comment

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

Add { } to both for and if I assume?

Copy link
Member

Choose a reason for hiding this comment

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

The sort of vague unspecified rule I follow is that if you have any conditional/looping instructions that nest, then use braces at least on the outer one.

So

for (...) {
  if (something)
    return i;
}

is OK too. The rationale behind this is the same as that for -Wmisleading-indentation.

return glnx_throw (error, "Invalid index: %s", deploy_index_str);
if (errno == ERANGE)
{
if (!g_strcmp0 (deploy_index_str, "booted"))
Copy link
Member

Choose a reason for hiding this comment

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

Hmm I'd say we should check the string values first, and then only fall back to trying to parse as an integer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure...

src/ostree/ot-admin-builtin-pin.c Outdated Show resolved Hide resolved
deploy_index = get_deployment_index_for_type (sysroot, OSTREE_DEPLOYMENT_PENDING);
else if (!g_strcmp0 (deploy_index_str, "rollback"))
deploy_index = get_deployment_index_for_type (sysroot, OSTREE_DEPLOYMENT_ROLLBACK);

Copy link
Member

Choose a reason for hiding this comment

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

Feels like we should do something to explicitly handle the notfound aka -1 case here? Like:

if (deploy_index < 0)
  return glnx_throw (error, "Deployment type not found: %s", deploy_index_str);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's already handled inside ot_admin_get_indexed_deployment function, so I didn't worry about handling it again, but we can handle it here also if needs be.

Copy link
Member

Choose a reason for hiding this comment

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

That will tell the user error: Invalid index -1 which seems much less friendly than error: Deployment type not found: rollback right?

@ericcurtin ericcurtin force-pushed the ot-admin-builtin-pin-booted-pending-rollback branch 2 times, most recently from dc683c1 to c969a3b Compare January 29, 2024 11:42
@ericcurtin
Copy link
Collaborator Author

Tested and ready for review again

Add new commands to pin 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 pin the current or future deployment.

Co-authored-by: Robert Sturla <robertsturla@outlook.com>
Signed-off-by: Eric Curtin <ecurtin@redhat.com>
@ericcurtin ericcurtin force-pushed the ot-admin-builtin-pin-booted-pending-rollback branch from c969a3b to cda5103 Compare January 29, 2024 11:44
@ericcurtin
Copy link
Collaborator Author

Looks like an unrelated build failure maybe 🤷

@cgwalters
Copy link
Member

For some reason iso-live-login.uefi-secure is flaky.
/override continuous-integration/jenkins/pr-merge

Copy link

openshift-ci bot commented Jan 29, 2024

@cgwalters: Overrode contexts on behalf of cgwalters: continuous-integration/jenkins/pr-merge

In response to this:

For some reason iso-live-login.uefi-secure is flaky.
/override continuous-integration/jenkins/pr-merge

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.

@cgwalters cgwalters merged commit 75941b7 into ostreedev:main Jan 29, 2024
24 checks passed
@ericcurtin ericcurtin deleted the ot-admin-builtin-pin-booted-pending-rollback branch January 29, 2024 17:26
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