Compare commits

..

5 Commits

Author SHA1 Message Date
ec90b3d9e3 chore(ha cluster): minor refactoring and fixes in okd hacluster
All checks were successful
Run Check Script / check (pull_request) Successful in 1m41s
2026-01-16 15:19:19 -05:00
9a1aad62c9 Merge pull request 'fix: kubeconfig falls back to .kube if KUBECONFIG env variable is not set' (#205) from fix/kubeconfig into master
All checks were successful
Run Check Script / check (push) Successful in 1m9s
Compile and package harmony_composer / package_harmony_composer (push) Successful in 7m49s
Reviewed-on: #205
2026-01-07 21:05:49 +00:00
0f9a53c8f6 cargo fmt
All checks were successful
Run Check Script / check (pull_request) Successful in 1m4s
2026-01-07 15:57:56 -05:00
b21829470d Merge pull request 'fix: modified nats box to use image tag non root for use in openshift environment' (#204) from fix/nats_non_root into master
All checks were successful
Run Check Script / check (push) Successful in 1m5s
Compile and package harmony_composer / package_harmony_composer (push) Successful in 7m36s
Reviewed-on: #204
2026-01-07 20:52:42 +00:00
4dcaf55dc5 fix: kubeconfig falls back to .kube if KUBECONFIG env variable is not set
Some checks failed
Run Check Script / check (pull_request) Failing after 2s
2026-01-07 15:47:08 -05:00
6 changed files with 54 additions and 34 deletions

20
Cargo.lock generated
View File

@@ -1754,6 +1754,24 @@ dependencies = [
"url",
]
[[package]]
name = "example-ha-cluster"
version = "0.1.0"
dependencies = [
"brocade",
"cidr",
"env_logger",
"harmony",
"harmony_macros",
"harmony_secret",
"harmony_tui",
"harmony_types",
"log",
"serde",
"tokio",
"url",
]
[[package]]
name = "example-kube-rs"
version = "0.1.0"
@@ -1942,9 +1960,9 @@ dependencies = [
"cidr",
"env_logger",
"harmony",
"harmony_cli",
"harmony_macros",
"harmony_secret",
"harmony_tui",
"harmony_types",
"log",
"serde",

View File

@@ -3,13 +3,12 @@ use std::{
sync::{Arc, OnceLock},
};
use brocade::BrocadeOptions;
use cidr::Ipv4Cidr;
use harmony::{
config::secret::SshKeyPair,
data::{FileContent, FilePath},
hardware::{HostCategory, Location, PhysicalHost, SwitchGroup},
infra::{brocade::BrocadeSwitchClient, opnsense::OPNSenseManagementInterface},
infra::{brocade::UnmanagedSwitch, opnsense::OPNSenseManagementInterface},
inventory::Inventory,
modules::{
http::StaticFilesHttpScore,
@@ -23,10 +22,11 @@ use harmony::{
topology::{LogicalHost, UnmanagedRouter},
};
use harmony_macros::{ip, mac_address};
use harmony_secret::{Secret, SecretManager};
use harmony_secret::SecretManager;
use harmony_types::net::Url;
use serde::{Deserialize, Serialize};
/// This example can be run this way
/// KUBECONFIG=~/path/to/ncd/kubeconfig HARMONY_USE_LOCAL_K3D=false HARMONY_SECRET_STORE=file HARMONY_SECRET_NAMESPACE=ncd0 cargo run
#[tokio::main]
async fn main() {
let firewall = harmony::topology::LogicalHost {
@@ -34,24 +34,7 @@ async fn main() {
name: String::from("fw0"),
};
let switch_auth = SecretManager::get_or_prompt::<BrocadeSwitchAuth>()
.await
.expect("Failed to get credentials");
let switches: Vec<IpAddr> = vec![ip!("192.168.33.101")];
let brocade_options = BrocadeOptions {
dry_run: *harmony::config::DRY_RUN,
..Default::default()
};
let switch_client = BrocadeSwitchClient::init(
&switches,
&switch_auth.username,
&switch_auth.password,
brocade_options,
)
.await
.expect("Failed to connect to switch");
let switch_client = UnmanagedSwitch {};
let switch_client = Arc::new(switch_client);
let opnsense = Arc::new(
@@ -191,9 +174,3 @@ async fn main() {
.await
.unwrap();
}
#[derive(Secret, Serialize, Deserialize, Debug)]
pub struct BrocadeSwitchAuth {
pub username: String,
pub password: String,
}

View File

@@ -1006,8 +1006,28 @@ impl K8sAnywhereConfig {
}
fn from_env() -> Self {
fn get_kube_config_path() -> Option<std::path::PathBuf> {
// 1. Check for the KUBECONFIG environment variable first (standard practice)
if let Ok(val) = std::env::var("KUBECONFIG") {
if !val.is_empty() {
return Some(std::path::PathBuf::from(val));
}
}
// 2. Use the standard library to find the home directory
// As of recent Rust versions, this is the preferred cross-platform method.
let mut path = std::env::home_dir()?;
// 3. Construct the path to .kube/config
// .push() handles OS-specific separators (\ for Windows, / for Unix)
path.push(".kube");
path.push("config");
Some(path)
}
Self {
kubeconfig: std::env::var("KUBECONFIG").ok().map(|v| v.to_string()),
kubeconfig: get_kube_config_path().map(|s| s.to_string_lossy().into_owned()),
use_system_kubeconfig: std::env::var("HARMONY_USE_SYSTEM_KUBECONFIG")
.map_or_else(|_| false, |v| v.parse().ok().unwrap_or(false)),
autoinstall: std::env::var("HARMONY_AUTOINSTALL")

View File

@@ -21,7 +21,9 @@ use serde::Serialize;
// -------------------------------------------------------------------------------------------------
#[derive(Debug, Clone, Serialize, new)]
pub struct OKDSetup01InventoryScore {}
pub struct OKDSetup01InventoryScore {
discovery_strategy: HarmonyDiscoveryStrategy,
}
impl Score<HAClusterTopology> for OKDSetup01InventoryScore {
fn create_interpret(&self) -> Box<dyn Interpret<HAClusterTopology>> {
@@ -77,6 +79,8 @@ impl Interpret<HAClusterTopology> for OKDSetup01InventoryInterpret {
info!("Setting up base DNS config for OKD");
let cluster_domain = &topology.domain_name;
let load_balancer_ip = &topology.load_balancer.get_ip();
// TODO reactivate automatic dns config when migration from unbound to dnsmasq is done
// For now we output the instruction for the user to do it manually
inquire::Confirm::new(&format!(
"Set hostnames manually in your opnsense dnsmasq config :
*.apps.{cluster_domain} -> {load_balancer_ip}
@@ -88,7 +92,6 @@ When you can dig them, confirm to continue.
))
.prompt()
.expect("Prompt error");
// TODO reactivate automatic dns config when migration from unbound to dnsmasq is done
// OKDDnsScore::new(topology)
// .interpret(inventory, topology)
// .await?;
@@ -105,7 +108,7 @@ When you can dig them, confirm to continue.
DiscoverHostForRoleScore {
role: HostRole::Bootstrap,
number_desired_hosts: 1,
discovery_strategy: HarmonyDiscoveryStrategy::MDNS,
discovery_strategy: self.score.discovery_strategy.clone(),
}
.interpret(inventory, topology)
.await?;

View File

@@ -76,6 +76,8 @@ impl OKDSetup02BootstrapInterpret {
}
}
/// Runs the openshift-install commands locally to prepare ignition files
/// Uploads the ignition files to the statis http server
async fn prepare_ignition_files(
&self,
inventory: &Inventory,

View File

@@ -67,7 +67,7 @@ impl OKDInstallationPipeline {
discovery_strategy: HarmonyDiscoveryStrategy,
) -> Vec<Box<dyn Score<HAClusterTopology>>> {
vec![
Box::new(OKDSetup01InventoryScore::new()),
Box::new(OKDSetup01InventoryScore::new(discovery_strategy.clone())),
Box::new(OKDSetup02BootstrapScore::new()),
Box::new(OKDSetup03ControlPlaneScore {
discovery_strategy: discovery_strategy.clone(),