Skip to content

Commit

Permalink
refactor: use static routes instead of one per port (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulobressan authored Jan 30, 2024
1 parent ebc002e commit 60fbd3c
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 531 deletions.
8 changes: 4 additions & 4 deletions bootstrap/crds/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ resource "kubernetes_manifest" "customresourcedefinition_ogmiosports_demeter_run
"type" = "string"
},
{
"jsonPath" = ".status.endpoint_key_url"
"name" = "Endpoint Key URL"
"jsonPath" = ".status.authenticatedEndpointUrl"
"name" = "Authenticated Endpoint URL"
"type" = "string"
},
{
Expand Down Expand Up @@ -78,7 +78,7 @@ resource "kubernetes_manifest" "customresourcedefinition_ogmiosports_demeter_run
"authToken" = {
"type" = "string"
}
"endpointKeyUrl" = {
"authenticatedEndpointUrl" = {
"type" = "string"
}
"endpointUrl" = {
Expand All @@ -87,7 +87,7 @@ resource "kubernetes_manifest" "customresourcedefinition_ogmiosports_demeter_run
}
"required" = [
"authToken",
"endpointKeyUrl",
"authenticatedEndpointUrl",
"endpointUrl",
]
"type" = "object"
Expand Down
13 changes: 6 additions & 7 deletions operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ This operator allow demeter to run and expose ogmios

## Environment

| Key | Value |
| ------------- | ------------- |
| ADDR | 0.0.0.0:5000 |
| DNS_ZONE | demeter.run |
| NAMESPACE | ftr-ogmios-v1 |
| INGRESS_CLASS | ogmios-v1 |
| API_KEY_SALT | ogmios-salt |
| Key | Value |
| ------------- | ------------ |
| ADDR | 0.0.0.0:5000 |
| DNS_ZONE | demeter.run |
| INGRESS_CLASS | ogmios-v1 |
| API_KEY_SALT | ogmios-salt |

## Commands

Expand Down
4 changes: 0 additions & 4 deletions operator/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,16 @@ pub fn get_config() -> &'static Config {
#[derive(Debug, Clone)]
pub struct Config {
pub dns_zone: String,
pub namespace: String,
pub ingress_class: String,
pub api_key_salt: String,
pub http_port: String,
}

impl Config {
pub fn from_env() -> Self {
Self {
dns_zone: env::var("DNS_ZONE").unwrap_or("demeter.run".into()),
namespace: env::var("NAMESPACE").unwrap_or("ftr-ogmios-v1".into()),
ingress_class: env::var("INGRESS_CLASS").unwrap_or("ogmios-v1".into()),
api_key_salt: env::var("API_KEY_SALT").unwrap_or("ogmios-salt".into()),
http_port: "1337".into(),
}
}
}
19 changes: 8 additions & 11 deletions operator/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ use std::{sync::Arc, time::Duration};
use tracing::{error, info, instrument};

use crate::{
auth::handle_auth,
gateway::{handle_http_route, handle_http_route_key, handle_reference_grant},
patch_resource_status, Error, Metrics, Network, Result, State,
auth::handle_auth, build_hostname, patch_resource_status, Error, Metrics, Network, Result,
State,
};

pub static OGMIOS_PORT_FINALIZER: &str = "ogmiosports.demeter.run";
Expand All @@ -29,7 +28,7 @@ pub static OGMIOS_PORT_FINALIZER: &str = "ogmiosports.demeter.run";
{"name": "Network", "jsonPath": ".spec.network", "type": "string"},
{"name": "Version", "jsonPath": ".spec.version", "type": "number"},
{"name": "Endpoint URL", "jsonPath": ".status.endpointUrl", "type": "string"},
{"name": "Endpoint Key URL", "jsonPath": ".status.endpoint_key_url", "type": "string"},
{"name": "Authenticated Endpoint URL", "jsonPath": ".status.authenticatedEndpointUrl", "type": "string"},
{"name": "Auth Token", "jsonPath": ".status.authToken", "type": "string"}
"#)]
#[serde(rename_all = "camelCase")]
Expand All @@ -42,7 +41,7 @@ pub struct OgmiosPortSpec {
#[serde(rename_all = "camelCase")]
pub struct OgmiosPortStatus {
pub endpoint_url: String,
pub endpoint_key_url: String,
pub authenticated_endpoint_url: String,
pub auth_token: String,
}

Expand All @@ -57,15 +56,13 @@ impl Context {
}

async fn reconcile(crd: Arc<OgmiosPort>, ctx: Arc<Context>) -> Result<Action> {
handle_reference_grant(&ctx.client, &crd).await?;

let key = handle_auth(&ctx.client, &crd).await?;
let hostname = handle_http_route(&ctx.client, &crd).await?;
let hostname_key = handle_http_route_key(&ctx.client, &crd, &key).await?;

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

let status = OgmiosPortStatus {
endpoint_url: format!("https://{hostname}"),
endpoint_key_url: format!("https://{hostname_key}"),
endpoint_url: format!("https://{hostname}",),
authenticated_endpoint_url: format!("https://{hostname_key}"),
auth_token: key,
};

Expand Down
Loading

0 comments on commit 60fbd3c

Please sign in to comment.