diff --git a/src/utils/kuber.rs b/src/utils/kuber.rs index 62e3442..4716652 100644 --- a/src/utils/kuber.rs +++ b/src/utils/kuber.rs @@ -1,4 +1,4 @@ -// use crate::utils::dnsclient::DnsClientPool; +use crate::utils::parceyaml::build_headers; use crate::utils::structs::{Configuration, InnerMap, ServiceMapping, UpstreamsDashMap}; use crate::utils::tools::{clone_dashmap_into, compare_dashmaps, print_upstreams}; use dashmap::DashMap; @@ -14,9 +14,6 @@ use std::time::Duration; use tokio::fs::File; use tokio::io::AsyncReadExt; -// static KUBERNETES_SERVICE_HOST: &str = "IP_ADDRESS"; -// static TOKEN: &str = "TOKEN"; - #[derive(Debug, serde::Deserialize)] struct Endpoints { subsets: Option>, @@ -35,12 +32,10 @@ struct Address { #[derive(Debug, serde::Deserialize)] struct Port { - // name: String, port: u16, } pub async fn start(mut toreturn: Sender, config: Arc) { - println!("{:?}", config); let upstreams = UpstreamsDashMap::new(); let prev_upstreams = UpstreamsDashMap::new(); loop { @@ -62,22 +57,21 @@ pub async fn start(mut toreturn: Sender, config: Arc 0 { + header_list.insert(i.path.clone().unwrap_or("/".to_string()), hl); + config.headers.insert(i.hostname.clone(), header_list); } - header_list.insert(path.clone(), hl); + let url = format!("https://{}/api/v1/namespaces/staging/endpoints/{}", server, i.hostname); let list = get_by_http(&*url, &*token, &i).await; if let Some(list) = list { match upstreams.get(&i.upstream.clone()) { - Some(foo) => { + Some(upstr) => { for (k, v) in list { - foo.value().insert(k, v); + upstr.value().insert(k, v); } } None => { diff --git a/src/utils/parceyaml.rs b/src/utils/parceyaml.rs index 43938d5..2a3d7a0 100644 --- a/src/utils/parceyaml.rs +++ b/src/utils/parceyaml.rs @@ -109,15 +109,8 @@ async fn populate_file_upstreams(config: &mut Configuration, parsed: &Config) { } let mut server_list = Vec::new(); - let mut hl = Vec::new(); - - if let Some(headers) = &path_config.headers { - for header in headers { - if let Some((key, val)) = header.split_once(':') { - hl.push((key.trim().to_string(), val.trim().to_string())); - } - } - } + let mut hl: Vec<(String, String)> = Vec::new(); + build_headers(&path_config.headers, config, &mut hl); header_list.insert(path.clone(), hl); for server in &path_config.servers { @@ -224,3 +217,20 @@ fn log_builder(conf: &AppConfig) { } env_logger::builder().init(); } + +pub fn build_headers(path_config: &Option>, config: &Configuration, hl: &mut Vec<(String, String)>) { + if let Some(headers) = &path_config { + for header in headers { + if let Some((key, val)) = header.split_once(':') { + hl.push((key.trim().to_string(), val.trim().to_string())); + } + } + if let Some(push) = config.headers.get("GLOBAL_HEADERS") { + for k in push.iter() { + for x in k.value() { + hl.push(x.to_owned()); + } + } + } + } +} diff --git a/src/web/gethosts.rs b/src/web/gethosts.rs index af12ace..25449f0 100644 --- a/src/web/gethosts.rs +++ b/src/web/gethosts.rs @@ -52,7 +52,6 @@ impl GetHost for LB { let host_entry = self.headers.get(peer)?; let mut current_path = path.to_string(); let mut best_match: Option> = None; - loop { if let Some(entry) = host_entry.get(¤t_path) { if !entry.value().is_empty() { diff --git a/src/web/proxyhttp.rs b/src/web/proxyhttp.rs index 2fe440e..0cd9165 100644 --- a/src/web/proxyhttp.rs +++ b/src/web/proxyhttp.rs @@ -215,6 +215,7 @@ impl ProxyHttp for LB { let path = session.req_header().uri.path(); let host_header = host; let split_header = host_header.split_once(':'); + match split_header { Some(sh) => { let yoyo = self.get_header(sh.0, path);