mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-30 23:08:40 +08:00
unifying kubernetes and file provider configs
This commit is contained in:
@@ -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::structs::{Configuration, InnerMap, ServiceMapping, UpstreamsDashMap};
|
||||||
use crate::utils::tools::{clone_dashmap_into, compare_dashmaps, print_upstreams};
|
use crate::utils::tools::{clone_dashmap_into, compare_dashmaps, print_upstreams};
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
@@ -14,9 +14,6 @@ use std::time::Duration;
|
|||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
use tokio::io::AsyncReadExt;
|
use tokio::io::AsyncReadExt;
|
||||||
|
|
||||||
// static KUBERNETES_SERVICE_HOST: &str = "IP_ADDRESS";
|
|
||||||
// static TOKEN: &str = "TOKEN";
|
|
||||||
|
|
||||||
#[derive(Debug, serde::Deserialize)]
|
#[derive(Debug, serde::Deserialize)]
|
||||||
struct Endpoints {
|
struct Endpoints {
|
||||||
subsets: Option<Vec<Subset>>,
|
subsets: Option<Vec<Subset>>,
|
||||||
@@ -35,12 +32,10 @@ struct Address {
|
|||||||
|
|
||||||
#[derive(Debug, serde::Deserialize)]
|
#[derive(Debug, serde::Deserialize)]
|
||||||
struct Port {
|
struct Port {
|
||||||
// name: String,
|
|
||||||
port: u16,
|
port: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start(mut toreturn: Sender<Configuration>, config: Arc<Configuration>) {
|
pub async fn start(mut toreturn: Sender<Configuration>, config: Arc<Configuration>) {
|
||||||
println!("{:?}", config);
|
|
||||||
let upstreams = UpstreamsDashMap::new();
|
let upstreams = UpstreamsDashMap::new();
|
||||||
let prev_upstreams = UpstreamsDashMap::new();
|
let prev_upstreams = UpstreamsDashMap::new();
|
||||||
loop {
|
loop {
|
||||||
@@ -62,22 +57,21 @@ pub async fn start(mut toreturn: Sender<Configuration>, config: Arc<Configuratio
|
|||||||
if let Some(svc) = kuber.services {
|
if let Some(svc) = kuber.services {
|
||||||
for i in svc {
|
for i in svc {
|
||||||
let header_list = DashMap::new();
|
let header_list = DashMap::new();
|
||||||
|
|
||||||
let mut hl = Vec::new();
|
let mut hl = Vec::new();
|
||||||
if let Some(headers) = &i.headers {
|
build_headers(&i.headers, config.as_ref(), &mut hl);
|
||||||
for header in headers {
|
if hl.len() > 0 {
|
||||||
if let Some((key, val)) = header.split_once(':') {
|
header_list.insert(i.path.clone().unwrap_or("/".to_string()), hl);
|
||||||
hl.push((key.trim().to_string(), val.trim().to_string()));
|
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 url = format!("https://{}/api/v1/namespaces/staging/endpoints/{}", server, i.hostname);
|
||||||
let list = get_by_http(&*url, &*token, &i).await;
|
let list = get_by_http(&*url, &*token, &i).await;
|
||||||
if let Some(list) = list {
|
if let Some(list) = list {
|
||||||
match upstreams.get(&i.upstream.clone()) {
|
match upstreams.get(&i.upstream.clone()) {
|
||||||
Some(foo) => {
|
Some(upstr) => {
|
||||||
for (k, v) in list {
|
for (k, v) in list {
|
||||||
foo.value().insert(k, v);
|
upstr.value().insert(k, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
|||||||
@@ -109,15 +109,8 @@ async fn populate_file_upstreams(config: &mut Configuration, parsed: &Config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut server_list = Vec::new();
|
let mut server_list = Vec::new();
|
||||||
let mut hl = Vec::new();
|
let mut hl: Vec<(String, String)> = Vec::new();
|
||||||
|
build_headers(&path_config.headers, config, &mut hl);
|
||||||
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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
header_list.insert(path.clone(), hl);
|
header_list.insert(path.clone(), hl);
|
||||||
|
|
||||||
for server in &path_config.servers {
|
for server in &path_config.servers {
|
||||||
@@ -224,3 +217,20 @@ fn log_builder(conf: &AppConfig) {
|
|||||||
}
|
}
|
||||||
env_logger::builder().init();
|
env_logger::builder().init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn build_headers(path_config: &Option<Vec<String>>, 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ impl GetHost for LB {
|
|||||||
let host_entry = self.headers.get(peer)?;
|
let host_entry = self.headers.get(peer)?;
|
||||||
let mut current_path = path.to_string();
|
let mut current_path = path.to_string();
|
||||||
let mut best_match: Option<Vec<(String, String)>> = None;
|
let mut best_match: Option<Vec<(String, String)>> = None;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if let Some(entry) = host_entry.get(¤t_path) {
|
if let Some(entry) = host_entry.get(¤t_path) {
|
||||||
if !entry.value().is_empty() {
|
if !entry.value().is_empty() {
|
||||||
|
|||||||
@@ -215,6 +215,7 @@ impl ProxyHttp for LB {
|
|||||||
let path = session.req_header().uri.path();
|
let path = session.req_header().uri.path();
|
||||||
let host_header = host;
|
let host_header = host;
|
||||||
let split_header = host_header.split_once(':');
|
let split_header = host_header.split_once(':');
|
||||||
|
|
||||||
match split_header {
|
match split_header {
|
||||||
Some(sh) => {
|
Some(sh) => {
|
||||||
let yoyo = self.get_header(sh.0, path);
|
let yoyo = self.get_header(sh.0, path);
|
||||||
|
|||||||
Reference in New Issue
Block a user