Skip to content

Commit

Permalink
chore: Extract redirect information from consumer (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalezzfelipe authored Apr 9, 2024
1 parent 5b3cc6e commit 91345e4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion operator/src/crdgen.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use operator::controller;
use kube::CustomResourceExt;
use operator::controller;

fn main() {
print!(
Expand Down
6 changes: 3 additions & 3 deletions proxy/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ impl AuthBackgroundService {
let namespace = crd.metadata.namespace.as_ref().unwrap().clone();
let port_name = crd.name_any();

let hash_key = format!("{}.{}.{}", network, version, key);
let consumer = Consumer::new(namespace, port_name, tier, key);
let consumer =
Consumer::new(namespace, port_name, tier, key.clone(), network, version);

consumers.insert(hash_key, consumer);
consumers.insert(key, consumer);
}
}

Expand Down
18 changes: 14 additions & 4 deletions proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ impl State {
Self::default()
}

pub async fn get_consumer(&self, network: &str, version: &str, key: &str) -> Option<Consumer> {
pub async fn get_consumer(&self, key: &str) -> Option<Consumer> {
let consumers = self.consumers.read().await.clone();
let hash_key = format!("{}.{}.{}", network, version, key);
consumers.get(&hash_key).cloned()
consumers.get(key).cloned()
}
}

Expand All @@ -92,14 +91,25 @@ pub struct Consumer {
port_name: String,
tier: String,
key: String,
network: String,
version: String,
}
impl Consumer {
pub fn new(namespace: String, port_name: String, tier: String, key: String) -> Self {
pub fn new(
namespace: String,
port_name: String,
tier: String,
key: String,
network: String,
version: String,
) -> Self {
Self {
namespace,
port_name,
tier,
key,
network,
version,
}
}
}
Expand Down
15 changes: 5 additions & 10 deletions proxy/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl ProxyApp {
pub fn new(config: Arc<Config>, state: Arc<State>) -> Self {
ProxyApp {
client_connector: TransportConnector::new(None),
host_regex: Regex::new(r"(dmtr_[\w\d-]+)\.([\w]+)-([\w\d]+).+").unwrap(),
host_regex: Regex::new(r"(dmtr_[\w\d-]+)\..+").unwrap(),
config,
state,
}
Expand Down Expand Up @@ -197,17 +197,12 @@ impl ServerApp for ProxyApp {

let token = captures.get(1)?.as_str().to_string();

let network = captures.get(2)?.as_str().to_string();
let version = captures.get(3)?.as_str().to_string();
let namespace = self.config.proxy_namespace.clone();

let consumer = self.state.get_consumer(&network, &version, &token).await?;

let consumer = self.state.get_consumer(&token).await?;
let instance = format!(
"node-{network}-{version}.{}:{}",
self.config.node_dns, self.config.node_port
"node-{}-{}.{}:{}",
consumer.network, consumer.version, self.config.node_dns, self.config.node_port
);

let namespace = self.config.proxy_namespace.clone();
let context = Context::new(&consumer, &instance, &namespace);

let lookup_result = lookup_host(&instance).await;
Expand Down

0 comments on commit 91345e4

Please sign in to comment.