-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Refactoring, added e2e tests, change os image to lts, added new…
…er microk8s versions
- Loading branch information
1 parent
2588eb5
commit 54cdc99
Showing
262 changed files
with
2,823 additions
and
1,689 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
Cargo.lock | ||
**/*.rs.bk | ||
**/*.iml | ||
|
||
.vscode | ||
makoon.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
[workspace] | ||
resolver = "2" | ||
|
||
members = [ | ||
"proxmox", | ||
"makoon" | ||
"core", | ||
"web", | ||
"proxmox-client", | ||
"helm-client", | ||
"ssh-client" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
pipeline { | ||
agent { | ||
docker { image 'rust:1.73.0-bullseye' } | ||
} | ||
stages { | ||
stage('Checkout') { | ||
steps { | ||
sh 'rm -rf makoon' | ||
sh 'git clone -b integration_tests --depth 1 https://github.com/dsieradzki/makoon' | ||
} | ||
} | ||
stage('Test') { | ||
steps { | ||
dir('makoon') { | ||
withCredentials([usernamePassword(credentialsId: 'proxmox', usernameVariable: 'PROXMOX_USER', passwordVariable: 'PROXMOX_PASSWORD')]) { | ||
sh 'mkdir web/src-web/dist/ -p && touch web/src-web/dist/dummy' | ||
sh 'cargo test --features e2e -- --nocapture' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "core" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
proxmox-client = { path = "../proxmox-client" } | ||
helm-client = { path = "../helm-client" } | ||
ssh-client = { path = "../ssh-client" } | ||
openssl = "0.10" | ||
pem = "3.0" | ||
ssh-keys = "0.1" | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" | ||
typeshare = "1.0" | ||
chrono = { version = "0.4", features = ["serde"] } | ||
log = "0.4" | ||
env_logger = "0.10" | ||
uuid = { version = "1.4", features = ["v4", "fast-rng"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
makoon/src/operator/dispatcher/mod.rs → core/src/dispatcher/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
pub use dispatcher::*; | ||
|
||
mod dispatcher; | ||
mod utils; | ||
mod usecase; | ||
pub use usecase::HELM_CMD; | ||
pub use usecase::install_helm_app; | ||
mod utils; | ||
pub use usecase::install_cluster_resource; | ||
pub use usecase::install_helm_app; | ||
pub use usecase::HELM_CMD; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
use std::collections::HashMap; | ||
use std::sync::Arc; | ||
use log::info; | ||
|
||
use proxmox_client::model::AccessData; | ||
use proxmox_client::Client; | ||
use crate::dispatcher::usecase::common; | ||
use crate::model::{Cluster, ClusterNode, ClusterNodeType, LogEntry}; | ||
use crate::Repository; | ||
|
||
|
||
pub(crate) fn execute( | ||
proxmox_client: Arc<Client>, | ||
repo: Arc<Repository>, | ||
access: AccessData, | ||
cluster_name: String, | ||
node_name: String, | ||
) -> Result<(), String> { | ||
info!("Request to add node to the cluster has been received"); | ||
let proxmox_client = proxmox_client.operations(access); | ||
|
||
repo.save_log(LogEntry::info( | ||
&cluster_name, | ||
"Start creating node".to_string(), | ||
))?; | ||
|
||
let cluster = repo | ||
.get_cluster(&cluster_name)? | ||
.ok_or("Cannot find cluster")?; | ||
let master_node = cluster | ||
.nodes | ||
.iter() | ||
.find(|i| i.node_type == ClusterNodeType::Master && i.name != node_name) | ||
.cloned() | ||
.ok_or("Cannot find any master node".to_string())?; | ||
|
||
let exising_cluster_hosts = cluster | ||
.nodes | ||
.iter() | ||
.filter(|i| i.name != node_name) | ||
.map(|i| { | ||
( | ||
format!("{}-{}", cluster.cluster_name, i.name), | ||
i.ip_address.clone(), | ||
) | ||
}) | ||
.collect::<HashMap<String, String>>(); | ||
|
||
let existing_nodes = common::vm::get_existing_vms(&proxmox_client, &cluster)? | ||
.into_iter() | ||
.filter(|i| i.name != node_name) | ||
.collect(); | ||
|
||
let node_to_add = cluster | ||
.nodes | ||
.iter() | ||
.find(|i| i.name == node_name) | ||
.ok_or("Cannot find node to create")?; | ||
|
||
common::vm::create(&proxmox_client, repo.clone(), &cluster, node_to_add)?; | ||
|
||
proxmox_client | ||
.start_vm(&cluster.node, node_to_add.vm_id) | ||
.map_err(|e| format!("Cannot start VM [{}]: {}", node_to_add.vm_id, e))?; | ||
repo.save_log(LogEntry::info( | ||
&cluster.cluster_name, | ||
format!("Starting VM [{}]", node_to_add.vm_id), | ||
))?; | ||
|
||
common::vm::wait_for_start(&proxmox_client, &cluster, &node_to_add) | ||
.map_err(|e| format!("Cannot start VM [{}]: {}", node_to_add.vm_id, e))?; | ||
repo.save_log(LogEntry::info( | ||
&cluster.cluster_name, | ||
format!("VM [{}] has been started", node_to_add.vm_id), | ||
))?; | ||
|
||
common::vm::restart_vm_if_necessary(&proxmox_client, repo.clone(), &cluster, node_to_add)?; | ||
|
||
setup_vm(repo.clone(), &cluster, node_to_add, exising_cluster_hosts)?; | ||
|
||
add_new_node_host_to_existing_cluster(repo.clone(), &cluster, existing_nodes)?; | ||
|
||
common::cluster::install_kubernetes(repo.clone(), &cluster, node_to_add)?; | ||
|
||
common::cluster::wait_for_ready_kubernetes(repo.clone(), &cluster, node_to_add)?; | ||
|
||
common::cluster::join_node_to_cluster(repo.clone(), &cluster, &master_node, node_to_add)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn add_new_node_host_to_existing_cluster( | ||
repo: Arc<Repository>, | ||
cluster: &Cluster, | ||
existing_nodes: Vec<ClusterNode>, | ||
) -> Result<(), String> { | ||
let hosts = cluster | ||
.nodes | ||
.iter() | ||
.map(|i| { | ||
( | ||
format!("{}-{}", cluster.cluster_name, i.name), | ||
i.ip_address.clone(), | ||
) | ||
}) | ||
.collect::<HashMap<String, String>>(); | ||
|
||
for node in existing_nodes.iter() { | ||
repo.save_log(LogEntry::info( | ||
&cluster.cluster_name, | ||
format!("Add new node hostname to exising VM [{}]", node.vm_id), | ||
))?; | ||
common::vm::setup_vm(cluster, node, &hosts)?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn setup_vm( | ||
repo: Arc<Repository>, | ||
cluster: &Cluster, | ||
node: &ClusterNode, | ||
current_cluster_hosts: HashMap<String, String>, | ||
) -> Result<(), String> { | ||
let mut hosts = cluster | ||
.nodes | ||
.iter() | ||
.map(|i| { | ||
( | ||
format!("{}-{}", cluster.cluster_name, i.name), | ||
i.ip_address.clone(), | ||
) | ||
}) | ||
.collect::<HashMap<String, String>>(); | ||
|
||
hosts.extend(current_cluster_hosts); | ||
|
||
repo.save_log(LogEntry::info( | ||
&cluster.cluster_name, | ||
format!("Configure VM [{}]", node.vm_id), | ||
))?; | ||
common::vm::setup_vm(cluster, node, &hosts)?; | ||
Ok(()) | ||
} |
8 changes: 5 additions & 3 deletions
8
...or/dispatcher/usecase/change_resources.rs → ...rc/dispatcher/usecase/change_resources.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.