Compare commits
1 Commits
d06bd4dac6
...
a585bd0283
| Author | SHA1 | Date | |
|---|---|---|---|
| a585bd0283 |
@@ -1,136 +0,0 @@
|
|||||||
// TODO
|
|
||||||
// Write OKDRouteScore : This is the real one which will apply the k8s resource and expose all
|
|
||||||
// relevant option to Harmony's various use cases
|
|
||||||
//
|
|
||||||
// Write OKDTlsPassthroughScore : This one will use an OKDRouteScore under the hood and simply fill
|
|
||||||
// in all settings to make this route a TlsPassthrough
|
|
||||||
//
|
|
||||||
// These scores are meant to be used by an OKD based topology to provide Capabilities like
|
|
||||||
// TlsRouter
|
|
||||||
//
|
|
||||||
// The first use case to serve here is the postgresql multisite setup, so exposing only the
|
|
||||||
// settings relevant to this use case is enough at first, following YAGNI.
|
|
||||||
//
|
|
||||||
// These scores are not intended to be used directly by a user, unless the user knows that he will
|
|
||||||
// always be dealing only with okd/openshift compatible topologies and is ready to manage the
|
|
||||||
// additional maintenance burden that comes with a lower level functionnality.
|
|
||||||
|
|
||||||
use k8s_openapi::apimachinery::pkg::util::intstr::IntOrString;
|
|
||||||
use kube::api::ObjectMeta;
|
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
use crate::modules::k8s::resource::K8sResourceScore;
|
|
||||||
use crate::modules::okd::crd::route::{
|
|
||||||
Route, RoutePort, RouteSpec, RouteTargetReference, TLSConfig,
|
|
||||||
};
|
|
||||||
use crate::score::Score;
|
|
||||||
use crate::topology::{K8sclient, Topology};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize)]
|
|
||||||
struct OKDRoutePort {
|
|
||||||
#[serde(rename = "targetPort")]
|
|
||||||
target_port: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize)]
|
|
||||||
struct OKDTLSConfig {
|
|
||||||
#[serde(rename = "termination")]
|
|
||||||
termination: String,
|
|
||||||
#[serde(rename = "insecureEdgeTerminationPolicy")]
|
|
||||||
insecure_edge_termination_policy: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub struct OKDRouteScore {
|
|
||||||
pub name: String,
|
|
||||||
pub namespace: String,
|
|
||||||
pub spec: RouteSpec,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl OKDRouteScore {
|
|
||||||
pub fn new(name: &str, namespace: &str, spec: RouteSpec) -> Self {
|
|
||||||
Self {
|
|
||||||
name: name.to_string(),
|
|
||||||
namespace: namespace.to_string(),
|
|
||||||
spec,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Topology + K8sclient> Score<T> for OKDRouteScore {
|
|
||||||
fn create_interpret(&self) -> Box<dyn crate::interpret::Interpret<T>> {
|
|
||||||
let route = Route {
|
|
||||||
metadata: ObjectMeta {
|
|
||||||
name: Some(self.name.clone()),
|
|
||||||
namespace: Some(self.namespace.clone()),
|
|
||||||
..ObjectMeta::default()
|
|
||||||
},
|
|
||||||
spec: self.spec.clone(),
|
|
||||||
status: None,
|
|
||||||
};
|
|
||||||
K8sResourceScore::single(route, Some(self.namespace.clone())).create_interpret()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name(&self) -> String {
|
|
||||||
format!("OKDRouteScore({})", self.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
pub struct OKDTlsPassthroughScore {
|
|
||||||
pub name: String,
|
|
||||||
pub namespace: String,
|
|
||||||
pub backend: String,
|
|
||||||
pub hostname: String,
|
|
||||||
pub target_port: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl OKDTlsPassthroughScore {
|
|
||||||
pub fn new(
|
|
||||||
name: &str,
|
|
||||||
namespace: &str,
|
|
||||||
backend: &str,
|
|
||||||
hostname: &str,
|
|
||||||
target_port: &str,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
name: name.to_string(),
|
|
||||||
namespace: namespace.to_string(),
|
|
||||||
backend: backend.to_string(),
|
|
||||||
hostname: hostname.to_string(),
|
|
||||||
target_port: target_port.to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Topology + K8sclient> Score<T> for OKDTlsPassthroughScore {
|
|
||||||
fn create_interpret(&self) -> Box<dyn crate::interpret::Interpret<T>> {
|
|
||||||
let passthrough_spec = RouteSpec {
|
|
||||||
host: Some(self.hostname.clone()),
|
|
||||||
wildcard_policy: Some("None".to_string()),
|
|
||||||
to: RouteTargetReference {
|
|
||||||
kind: "Service".to_string(),
|
|
||||||
name: self.backend.clone(),
|
|
||||||
weight: Some(100),
|
|
||||||
},
|
|
||||||
port: Some(RoutePort {
|
|
||||||
target_port: IntOrString::String(self.target_port.clone()),
|
|
||||||
}),
|
|
||||||
tls: Some(TLSConfig {
|
|
||||||
termination: "passthrough".to_string(),
|
|
||||||
insecure_edge_termination_policy: Some("None".to_string()),
|
|
||||||
..Default::default()
|
|
||||||
}),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
let route_score = OKDRouteScore::new(&self.name, &self.namespace, passthrough_spec);
|
|
||||||
route_score.create_interpret()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn name(&self) -> String {
|
|
||||||
format!(
|
|
||||||
"OKDTlsPassthroughScore({}:{}/{} → {})",
|
|
||||||
self.backend, self.target_port, self.namespace, self.hostname
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user