Skip to content

Conversation

jlebon
Copy link
Member

@jlebon jlebon commented Aug 8, 2025

This is trivial to do since the underlying container-encapsulate we do already supports this.

What becomes really interesting about this though is that in a container build flow where one is using build-chunked-oci with the FROM: ./out.ociarchive trick, it then becomes possible to dynamically (i.e. from within the build process itself) choose whether to add a label, or determine what value a label should have, which is a common frustration in container image building.

Copy link

openshift-ci bot commented Aug 8, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a --label option to the build-chunked-oci command, allowing users to add custom labels to the generated OCI image. The implementation is straightforward and includes a test case to verify the new functionality. My review includes a suggestion to improve the efficiency of argument construction for the labels, making it more consistent with existing code patterns.

.bootc
.then_some(["--label", "containers.bootc=1"].as_slice())
.unwrap_or_default();
let label_args = self.labels.into_iter().map(|v| format!("--label={v}"));

Choose a reason for hiding this comment

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

medium

This implementation works, but it can be made more efficient and consistent with other argument handling in this file. It allocates a new String for each label, which is unnecessary. Using iter().flat_map(...) avoids these allocations by creating an iterator of string slices (&str), which is more performant and aligns with patterns used elsewhere in this function for constructing command arguments.

Suggested change
let label_args = self.labels.into_iter().map(|v| format!("--label={v}"));
let label_args = self.labels.iter().flat_map(|v| ["--label", v.as_str()]);

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good suggestion. I copied this from another entry point that also takes labels but we should switch over both.

@jlebon
Copy link
Member Author

jlebon commented Aug 8, 2025

I didn't test this yet (though CI should sanity-check it). It's an aside that would help something I'm working on but is not necessary. Though I just realized now it could also be used to clean up the FCOS Containerfile at least, where the second phase is full of label-setting (though the containers.bootc=1 one at least is not necessary). But there is also value in having those surfaced in the Containerfile proper when it's just static.

jlebon added a commit to jlebon/coreos-assembler that referenced this pull request Aug 8, 2025
This is for coreos/fedora-coreos-tracker#1996.
I initially wanted to just add another `LABEL` to our Containerfile
and hook that up to another build arg, but the problem is that our
Containerfile is shared with RHCOS/SCOS and there's no way to make
`LABEL` directives conditional.

I opened coreos/rpm-ostree#5454 which will fix
this but for now to not block on this, let's just slap it on from the
cosa side. Once it's folded back into the build process proper, then we
can rever this. But the label not existing shouldn't really affect the
majority of developers anyway.
jlebon added a commit to coreos/coreos-assembler that referenced this pull request Aug 12, 2025
This is for coreos/fedora-coreos-tracker#1996.
I initially wanted to just add another `LABEL` to our Containerfile
and hook that up to another build arg, but the problem is that our
Containerfile is shared with RHCOS/SCOS and there's no way to make
`LABEL` directives conditional.

I opened coreos/rpm-ostree#5454 which will fix
this but for now to not block on this, let's just slap it on from the
cosa side. Once it's folded back into the build process proper, then we
can rever this. But the label not existing shouldn't really affect the
majority of developers anyway.
This is trivial to do since the underlying `container-encapsulate` we do
already supports this.

What becomes really interesting about this though is that in a container
build flow where one is using `build-chunked-oci` with the
`FROM: ./out.ociarchive` trick, it then becomes possible to
_dynamically_ (i.e. from within the build process itself) choose whether
to add a label, or determine what value a label should have, which is a
common frustration in container image building.
@jlebon jlebon marked this pull request as ready for review September 7, 2025 14:47
@jlebon
Copy link
Member Author

jlebon commented Sep 7, 2025

Ok yup, works fine! Just rebased to retrigger CI.

@jlebon jlebon enabled auto-merge (rebase) September 7, 2025 14:50
Copy link

openshift-ci bot commented Sep 7, 2025

@jlebon: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/fcos-e2e b8f8710 link true /test fcos-e2e

Full PR test history. Your PR dashboard.

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-sigs/prow repository. I understand the commands that are listed here.

@jlebon jlebon merged commit 49bce35 into coreos:main Sep 7, 2025
18 of 20 checks passed
@jlebon jlebon deleted the pr/label-oci branch September 7, 2025 16:03
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