Skip to content

Commit

Permalink
chore: Change endpoint to include major version (#30)
Browse files Browse the repository at this point in the history
* chore: Change endpoint to include major version

* Remove unused imports
  • Loading branch information
gonzalezzfelipe authored Mar 4, 2024
1 parent 19ebac1 commit 33735dc
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 8 deletions.
6 changes: 5 additions & 1 deletion bootstrap/crds/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ resource "kubernetes_manifest" "customresourcedefinition_kupoports_demeter_run"
"properties" = {
"spec" = {
"properties" = {
"kupoVersion" = {
"nullable" = true
"type" = "string"
}
"network" = {
"enum" = [
"mainnet",
Expand Down Expand Up @@ -92,6 +96,7 @@ resource "kubernetes_manifest" "customresourcedefinition_kupoports_demeter_run"
"type" = "string"
}
"authenticatedEndpointUrl" = {
"nullable" = true
"type" = "string"
}
"endpointUrl" = {
Expand All @@ -100,7 +105,6 @@ resource "kubernetes_manifest" "customresourcedefinition_kupoports_demeter_run"
}
"required" = [
"authToken",
"authenticatedEndpointUrl",
"endpointUrl",
]
"type" = "object"
Expand Down
2 changes: 1 addition & 1 deletion operator/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion operator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ext-cardano-kupo"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
default-run = "controller"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
6 changes: 5 additions & 1 deletion operator/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ pub struct Config {
pub dcu_per_request_preprod: f64,
pub dcu_per_request_preview: f64,
pub dcu_per_request_sanchonet: f64,

pub default_kupo_version: String,
}

impl Config {
pub fn from_env() -> Self {
Self {
dns_zone: env::var("DNS_ZONE").unwrap_or("demeter.run".into()),
ingress_class: env::var("INGRESS_CLASS").unwrap_or("kupo-v1".into()),
ingress_class: env::var("INGRESS_CLASS").unwrap_or("kupo-m1".into()),
api_key_salt: env::var("API_KEY_SALT").unwrap_or("kupo-salt".into()),

metrics_delay: Duration::from_secs(
Expand All @@ -54,6 +56,8 @@ impl Config {
.expect("DCU_PER_REQUEST_SANCHONET must be set")
.parse::<f64>()
.expect("DCU_PER_REQUEST_SANCHONET must be a number"),

default_kupo_version: env::var("DEFAULT_KUPO_VERSION").unwrap_or("2".into()),
}
}
}
3 changes: 2 additions & 1 deletion operator/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub struct KupoPortSpec {
pub prune_utxo: bool,
// throughput should be 0, 1, 2
pub throughput_tier: String,
pub kupo_version: Option<String>,
}

#[derive(Deserialize, Serialize, Clone, Default, Debug, JsonSchema)]
Expand All @@ -62,7 +63,7 @@ pub struct KupoPortStatus {
async fn reconcile(crd: Arc<KupoPort>, ctx: Arc<Context>) -> Result<Action> {
let key = handle_auth(&ctx.client, &crd).await?;

let (hostname, hostname_key) = build_hostname(&crd.spec.network, &key);
let (hostname, hostname_key) = build_hostname(&crd.spec.network, &key, &crd.spec.kupo_version);

let status = KupoPortStatus {
endpoint_url: format!("https://{hostname}",),
Expand Down
47 changes: 44 additions & 3 deletions operator/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,54 @@ pub async fn patch_resource_status(
Ok(())
}

pub fn build_hostname(network: &Network, key: &str) -> (String, String) {
pub fn build_hostname(
network: &Network,
key: &str,
kupo_version: &Option<String>,
) -> (String, String) {
let config = get_config();
let ingress_class = &config.ingress_class;
let dns_zone = &config.dns_zone;
let version = kupo_version
.clone()
.unwrap_or(config.default_kupo_version.to_string());

let hostname = format!("{network}.{ingress_class}.{dns_zone}");
let hostname_key = format!("{key}.{network}.{ingress_class}.{dns_zone}");
let hostname = format!("{network}-v{version}.{ingress_class}.{dns_zone}");
let hostname_key = format!("{key}.{network}-v{version}.{ingress_class}.{dns_zone}");

(hostname, hostname_key)
}

#[cfg(test)]
mod tests {
use std::env;

use super::*;

#[test]
fn test_build_hostname() {
env::set_var("METRICS_DELAY", "30");
env::set_var("PROMETHEUS_URL", "prometheus_url");
env::set_var("DCU_PER_REQUEST_MAINNET", "3");
env::set_var("DCU_PER_REQUEST_PREPROD", "3");
env::set_var("DCU_PER_REQUEST_PREVIEW", "3");
env::set_var("DCU_PER_REQUEST_SANCHONET", "3");

let network = Network::Preprod;
let key = "fake_key";

let (hostname, hostname_key) = build_hostname(&network, &key, &None);
assert_eq!(hostname, String::from("preprod-v2.kupo-m1.demeter.run"));
assert_eq!(
hostname_key,
String::from("fake_key.preprod-v2.kupo-m1.demeter.run")
);

let (hostname, hostname_key) = build_hostname(&network, &key, &Some("3".to_owned()));
assert_eq!(hostname, String::from("preprod-v3.kupo-m1.demeter.run"));
assert_eq!(
hostname_key,
String::from("fake_key.preprod-v3.kupo-m1.demeter.run")
);
}
}

0 comments on commit 33735dc

Please sign in to comment.