tembo_stacks/apps/
types.rs1use k8s_openapi::api::core::v1::ResourceRequirements;
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4use tembo_controller::{
5 apis::postgres_parameters::PgConfig,
6 app_service::types::{AppService, EnvVar},
7 extensions::types::{Extension, TrunkInstall},
8};
9use utoipa::ToSchema;
10
11#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, JsonSchema)]
12pub struct App {
13 pub name: AppType,
14 #[serde(rename = "appServices")]
15 pub app_services: Option<Vec<AppService>>,
16 pub trunk_installs: Option<Vec<TrunkInstall>>,
17 pub extensions: Option<Vec<Extension>>,
18 pub postgres_config: Option<Vec<PgConfig>>,
19}
20
21pub struct MergedConfigs {
22 pub extensions: Option<Vec<Extension>>,
23 pub trunk_installs: Option<Vec<TrunkInstall>>,
24 pub app_services: Option<Vec<AppService>>,
25 pub pg_configs: Option<Vec<PgConfig>>,
26}
27
28#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, JsonSchema)]
29pub enum AppType {
30 #[serde(rename = "restapi")]
31 RestAPI(Option<AppConfig>),
32 #[serde(rename = "http")]
33 HTTP(Option<AppConfig>),
34 #[serde(rename = "mq-api")]
35 MQ(Option<AppConfig>),
36 #[serde(rename = "embeddings")]
37 Embeddings(Option<AppConfig>),
38 #[serde(rename = "pganalyze")]
39 PgAnalyze(Option<AppConfig>),
40 #[serde(rename = "sqlrunner")]
41 SqlRunner(Option<AppConfig>),
42 #[serde(rename = "custom")]
43 Custom(AppService),
44}
45
46#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, JsonSchema)]
49pub struct AppConfig {
50 pub env: Option<Vec<EnvVar>>,
51 pub resources: Option<ResourceRequirements>,
52}
53
54impl TryFrom<AppService> for AppType {
55 type Error = &'static str;
56 fn try_from(app_service: AppService) -> Result<Self, Self::Error> {
57 let mut env: Option<Vec<EnvVar>> = None;
58 if let Some(app_env) = app_service.env.as_ref() {
59 env = Some(app_env.clone());
60 }
61
62 let resources = app_service.resources.clone();
63
64 let app_config = Some(AppConfig {
65 env,
66 resources: Some(resources),
67 });
68
69 match app_service.name.as_str() {
70 "restapi" => Ok(AppType::RestAPI(app_config)),
71 "http" => Ok(AppType::HTTP(app_config)),
72 "mq-api" => Ok(AppType::MQ(app_config)),
73 "embeddings" => Ok(AppType::Embeddings(app_config)),
74 "pganalyze" => Ok(AppType::PgAnalyze(app_config)),
75 "sqlrunner" => Ok(AppType::SqlRunner(app_config)),
76 _ => {
77 Ok(AppType::Custom(app_service))
79 }
80 }
81 }
82}