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 support for vendor override files #344

Merged
merged 1 commit into from
Sep 5, 2024

Conversation

jmt-lab
Copy link
Contributor

@jmt-lab jmt-lab commented Aug 7, 2024

Description of changes:

  • Introduces concept of vendor override files. Users can now define a vendor.toml or multiple toml files in a vendor.d/ directory that specify overrides for vendors.
  • Twoliter will now utilized the vendor overrides and maintains its digest check on the actual images match

Testing done:

  • Tested use of vendor.toml override and ensured twoliter fetch passed and fetched the correct image
  • Tested error on if the digests are different
  • Tested use of vendor.d/ folder

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

twoliter/src/lock.rs Outdated Show resolved Hide resolved
@cbgbt
Copy link
Contributor

cbgbt commented Aug 20, 2024

Would it be possible to add integration tests that show how vendor overrides interact with a workspace? I think that would help clarify the behavior and, of course, protect us from regressions.

Copy link
Contributor

@cbgbt cbgbt left a comment

Choose a reason for hiding this comment

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

Nice work so far! There has been some offline conversation around modifying how the override interacts with different scenarios.

Apart from that, I have some suggestions for the implementation.

twoliter/src/lock_image.rs Outdated Show resolved Hide resolved
twoliter/src/lock_image.rs Outdated Show resolved Hide resolved
twoliter/src/lock_image.rs Outdated Show resolved Hide resolved
twoliter/src/lock.rs Outdated Show resolved Hide resolved
twoliter/src/lock.rs Outdated Show resolved Hide resolved
@jmt-lab jmt-lab force-pushed the vendor-overrides branch 3 times, most recently from c1cdc99 to 701a87e Compare August 22, 2024 17:38
Copy link
Contributor

@cbgbt cbgbt left a comment

Choose a reason for hiding this comment

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

Nice work! The refactor really makes things much cleaner, thanks for doing that! I think as overall feedback, I'd like to see some test cases showing the expected behavior of the overrides.

Comment on lines 48 to 55
/// Any overrides, these are read from a separate override file
#[serde(skip)]
pub overrides: BTreeMap<String, BTreeMap<String, Override>>,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

#[serde(skip)] here introduces an invariant that the programmer now has to keep track of: If I want to use overrides, I need to ensure that codepaths which populate this B Tree have been run first.

I'd prefer if we could instead use the type system enforce these invariants. Maybe we could instead create a parent Workspace structure which refers to both the ser/de Lock and also separately parses or holds the overrides?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually think this should move to Project which kind of acts as our parent Workspace structure.

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense to me!

Comment on lines 8 to 10
use tracing::{debug, instrument, trace};
#[derive(Debug)]
Copy link
Contributor

Choose a reason for hiding this comment

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

I would have expected cargo fmt to add whitespace here.

fn eq(&self, other: &Self) -> bool {
self.schema_version == other.schema_version
&& self.sdk == other.sdk
&& self.kit == other.kit
Copy link
Contributor

Choose a reason for hiding this comment

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

We may wish to do a set comparison here.

}

#[instrument(level = "trace", skip(project))]
async fn load_overrides(
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this drops the concept of the override.d style directory that we had mentioned.

Just commenting to confirm. I'm ok with incrementally adding that if we need it!

"failed to find vendor for kit with name '{}' and vendor '{}'",
image.name, image.vendor
))?;
let override_ = self
Copy link
Contributor

Choose a reason for hiding this comment

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

I never knew that Rust reserved the override keyword :)

Comment on lines +206 to +189
while !remaining.is_empty() {
let working_set: Vec<_> = take(&mut remaining);
for image in working_set.iter() {
debug!(%image, "Resolving kit '{}'", image.name);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not needed for this PR since we aren't actually changing this, but I think it's more common in rust to use VecDeque for breadth-first traversal.

e.g. you can do:

while let Some(image) = remaining.pop_front() {
    /// etc etc
    for dep in metadata.kits {
        remaining.push_back();
    }
}

I'd be happy with just cutting an issue to simplify this later.

twoliter/src/lock/mod.rs Outdated Show resolved Hide resolved
twoliter/src/lock/image.rs Outdated Show resolved Hide resolved
twoliter/src/lock/image.rs Outdated Show resolved Hide resolved
twoliter/src/lock/image.rs Outdated Show resolved Hide resolved
twoliter/src/lock/image.rs Show resolved Hide resolved
twoliter/src/lock/image.rs Show resolved Hide resolved
@jmt-lab jmt-lab force-pushed the vendor-overrides branch 2 times, most recently from 1dccdf5 to 84669db Compare September 5, 2024 18:02
twoliter/src/lock/image.rs Outdated Show resolved Hide resolved
twoliter/src/project.rs Outdated Show resolved Hide resolved
twoliter/src/lock/mod.rs Show resolved Hide resolved
Copy link
Contributor

@cbgbt cbgbt left a comment

Choose a reason for hiding this comment

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

Nice work, @jmt-lab!

As a followup on the ask for integration testing -- @jmt-lab hit some road blocks with Docker misbehaving while interacting with a secure registry on localhost (and also seemingly making nonsense of the image digest...).

I have seen his integration tests pass for crane and otherwise seen how they fail due to docker "strangeness."

We'll cut an issue to followup on cleaning up the integration tests, since twoliter overrides blocks other important work in Twoliter.

@jmt-lab mind linking a remote branch with the current progress, even if the code is hack quality?

.await?;
}

self.synchronize_metadata(project).await
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@jmt-lab
Copy link
Contributor Author

jmt-lab commented Sep 5, 2024

It's currently living in my fork at: https://github.com/jmt-lab/twoliter/tree/integ-save

@jmt-lab jmt-lab merged commit 5f265b4 into bottlerocket-os:develop Sep 5, 2024
1 check passed
@jmt-lab jmt-lab deleted the vendor-overrides branch September 5, 2024 22:43
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.

4 participants