Skip to content

Commit

Permalink
feat: added secondary route with key on host
Browse files Browse the repository at this point in the history
* chore: adjusted handlers

* feat: added plugin to accept dmtr key on hostname

* feat: added secondary route with key on hostname
  • Loading branch information
paulobressan authored Jan 11, 2024
1 parent c0cb210 commit ebc002e
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 202 deletions.
15 changes: 13 additions & 2 deletions bootstrap/crds/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ resource "kubernetes_manifest" "customresourcedefinition_ogmiosports_demeter_run
"name" = "Endpoint URL"
"type" = "string"
},
{
"jsonPath" = ".status.endpoint_key_url"
"name" = "Endpoint Key URL"
"type" = "string"
},
{
"jsonPath" = ".status.authToken"
"name" = "Auth Token"
Expand Down Expand Up @@ -71,14 +76,20 @@ resource "kubernetes_manifest" "customresourcedefinition_ogmiosports_demeter_run
"nullable" = true
"properties" = {
"authToken" = {
"nullable" = true
"type" = "string"
}
"endpointKeyUrl" = {
"type" = "string"
}
"endpointUrl" = {
"nullable" = true
"type" = "string"
}
}
"required" = [
"authToken",
"endpointKeyUrl",
"endpointUrl",
]
"type" = "object"
}
}
Expand Down
44 changes: 30 additions & 14 deletions operator/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use futures::StreamExt;
use kube::{
api::ListParams,
runtime::{controller::Action, watcher::Config as WatcherConfig, Controller},
Api, Client, CustomResource, ResourceExt,
Api, Client, CustomResource, CustomResourceExt, ResourceExt,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand All @@ -11,9 +11,8 @@ use tracing::{error, info, instrument};

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

pub static OGMIOS_PORT_FINALIZER: &str = "ogmiosports.demeter.run";
Expand All @@ -30,6 +29,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": "Auth Token", "jsonPath": ".status.authToken", "type": "string"}
"#)]
#[serde(rename_all = "camelCase")]
Expand All @@ -41,10 +41,9 @@ pub struct OgmiosPortSpec {
#[derive(Deserialize, Serialize, Clone, Default, Debug, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct OgmiosPortStatus {
#[serde(skip_serializing_if = "Option::is_none")]
pub endpoint_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub auth_token: Option<String>,
pub endpoint_url: String,
pub endpoint_key_url: String,
pub auth_token: String,
}

struct Context {
Expand All @@ -58,14 +57,31 @@ impl Context {
}

async fn reconcile(crd: Arc<OgmiosPort>, ctx: Arc<Context>) -> Result<Action> {
let client = ctx.client.clone();
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 status = OgmiosPortStatus {
endpoint_url: format!("https://{hostname}"),
endpoint_key_url: format!("https://{hostname_key}"),
auth_token: key,
};

let namespace = crd.namespace().unwrap();
let ogmios_port = OgmiosPort::api_resource();

patch_resource_status(
ctx.client.clone(),
&namespace,
ogmios_port,
&crd.name_any(),
serde_json::to_value(status)?,
)
.await?;

let private_dns_service_name =
build_private_dns_service_name(&crd.spec.network, &crd.spec.version);
handle_reference_grant(client.clone(), &namespace, &crd, &private_dns_service_name).await?;
handle_http_route(client.clone(), &namespace, &crd, &private_dns_service_name).await?;
handle_auth(client.clone(), &namespace, &crd).await?;
info!(resource = crd.name_any(), "Reconcile completed");

Ok(Action::await_change())
}
Expand Down
Loading

0 comments on commit ebc002e

Please sign in to comment.