refactor(host_network): extract NetworkManager as a reusable component #183
No reviewers
Labels
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: NationTech/harmony#183
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "refactor-network-manager"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The NetworkManager logic was implemented directly into the
HaClusterTopology, which wasn't directly its concern and prevented us from being able to reuse that NetworkManaager implementations in the future for a different Topology.NetworkManagertraitOpenShiftNmStateNetworkManagerforNetworkManagerOverall LGTM, a few considerations here and there but nothing major.
@ -378,6 +118,7 @@ impl HAClusterTopology {bootstrap_host: dummy_host,control_plane: vec![],workers: vec![],network_manager: OnceLock::new(),Why OnceLock instead of Oncecell or something else? I'm not familiar with it. I guess it takes a read lock when accessed after initialization?
In pure Rust, the main difference is that
OnceLockis the multi-threaded version ofOnceCell. Considering our initialization process is synchronous in that case, I preferred to use this option rather thantokio::OnceCell(which is particularly useful for async initialization process).But I can switch to
OnceCellfromtokioinstead if you prefer. No strong opinions here for me.@ -548,3 +289,1 @@async fn configure_host_network(&self, config: &HostNetworkConfig) -> Result<(), SwitchError> {self.configure_bond(config).await?;self.configure_port_channel(config).awaitasync fn configure_port_channel(&self, config: &HostNetworkConfig) -> Result<(), SwitchError> {Why is this function and logic in ha_cluster instead of network manager?
it's actually the
impl Switch for HAClusterTopology@ -186,0 +190,4 @@}#[derive(Debug, Clone, new)]pub struct NetworkError {I really don't like the boilerplate added by having multiple error types for each bit of business logic.
I know passing strings around has its limitations but there's a middle ground for sure.
We should be evaluating these options sooner rather than later :
See this comment, which I largely agree with https://www.reddit.com/r/rust/comments/1bb7dco/comment/ku7io8o/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
Agree with using stuff like
thiserrorin general, especially for the core.The tricky is thing is that here, it is not part of the core of Harmony strictly speaking. The
Switchand theNetworkManagerare extra capabilities that we offer to enrich topologies. Also,SwitchandNetworkManagerare 2 different capabilities. So they will surely evolve separately and change for different reasons. Which means it's tricky to have a singleErrorthat represent both. It's not designed as such right now but a future refactoring to make it an Enum with different options would make sense to allow user to inspect the error and react accordingly.@ -0,0 +29,4 @@#[async_trait]impl NetworkManager for OpenShiftNmStateNetworkManager {async fn ensure_network_manager_installed(&self) -> Result<(), NetworkError> {I guess this is required because the operator from the catalog does not work?
@ -0,0 +36,4 @@.await?;debug!("Creating NMState namespace...");self.k8s_client.apply_url(url::Url::parse("https://github.com/nmstate/kubernetes-nmstate/releases/download/v0.84.0/namespace.yamlurl::parse can fail at runtime, would hurl! work here?
I wanted to use
hurl!at first but it creates an enum that match either an URL or a local folder. The url would have been nice, but I'm not sure what to do if it's a local folder. So it made the code more complicated and less elegant in the end.We can definitely revisit the
apply_urlfunction if we really want to support both URLs and folders.Very nice demo gif !