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

netdog: Support versioning in net.toml #2281

Merged
merged 1 commit into from Jul 29, 2022

Conversation

zmrow
Copy link
Contributor

@zmrow zmrow commented Jul 15, 2022

Issue number:
Implements #2214

Description of changes:

This change adds the ability to handle additional versions of `net.toml`
as the project continues to add features to network configuration.  A
top level `NetConfig` type has been removed in favor of a few traits.
Each new version of config is expected to implement these traits, the
most important of which converts the network configuration into
`WickedInterface` structs which are suitable for serializing directly to
file.

As part of this change, the `net_config` module has been lightly
refactored and split into submodules to make the pieces easier to use
among new versions.

Testing done:

  • All unit tests continue to pass
  • Build and boot an aws-k8s-1.21 variant and ensure the network config is correct
  • Build and boot a metal-dev variant and ensure the network config is correct via a given net.toml

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.

@zmrow zmrow added the area/metal Bare metal support label Jul 15, 2022
@zmrow zmrow self-assigned this Jul 15, 2022
#[derive(Debug, Eq, PartialEq, Hash, Deserialize)]
#[serde(try_from = "&str")]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Deserialize)]
#[serde(try_from = "String")]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we now deserialize the majority of the network config to a toml::Value first (to handle the versions), this is stored as a String inside of the toml::Value, hence the change from &str to String.

}
}

// =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
Copy link
Contributor Author

@zmrow zmrow Jul 15, 2022

Choose a reason for hiding this comment

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

Nothing has really changed about the below code. This code was moved here into v1.rs since we use the NetConfigV1 struct for the simple configuration we get from the kernel command line.

This change adds the ability to handle additional versions of `net.toml`
as the project continues to add features to network configuration.  A
top level `NetConfig` type has been removed in favor of a few traits.
Each new version of config is expected to implement these traits, the
most important of which converts the network configuration into
`WickedInterface` structs which are suitable for serializing directly to
file.

As part of this change, the `net_config` module has been lightly
refactored and split into submodules to make the pieces easier to use
among new versions.
@zmrow zmrow force-pushed the netconfig-versioning-netcfg branch from 95efd35 to 1a32d2c Compare July 20, 2022 20:20
@zmrow
Copy link
Contributor Author

zmrow commented Jul 20, 2022

The above force push:

  • changes the return type of deserialize_config from impl Interfaces to Box<dyn Interfaces> because we'll be returning different Interface implementors (netconfigv1, v2, etc). Rust considers them different types which means we need to use a Box rather than impl trait.
  • Adds a small validate_config() function to simplify the match statement when deserializing config
  • Implements the Validate and Interfaces traits for Box<T>

@zmrow zmrow merged commit 33e42d5 into bottlerocket-os:develop Jul 29, 2022
@zmrow zmrow deleted the netconfig-versioning-netcfg branch July 29, 2022 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/metal Bare metal support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants