mz_cloud_resources/crd/
console.rs1use std::collections::BTreeMap;
11
12use k8s_openapi::{
13 api::core::v1::ResourceRequirements, apimachinery::pkg::apis::meta::v1::Condition,
14};
15use kube::CustomResource;
16use schemars::JsonSchema;
17use serde::{Deserialize, Serialize};
18
19use crate::crd::{ManagedResource, MaterializeCertSpec, new_resource_id};
20use mz_server_core::listeners::AuthenticatorKind;
21
22pub mod v1alpha1 {
23 use super::*;
24
25 #[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize, JsonSchema)]
26 #[serde(rename_all = "camelCase")]
27 pub enum HttpConnectionScheme {
28 #[default]
29 Http,
30 Https,
31 }
32
33 #[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize, JsonSchema)]
34 #[serde(rename_all = "camelCase")]
35 pub struct BalancerdRef {
36 pub service_name: String,
38 pub namespace: String,
40 pub scheme: HttpConnectionScheme,
42 }
43
44 #[derive(
45 CustomResource, Clone, Debug, Default, PartialEq, Deserialize, Serialize, JsonSchema,
46 )]
47 #[serde(rename_all = "camelCase")]
48 #[kube(
49 namespaced,
50 group = "materialize.cloud",
51 version = "v1alpha1",
52 kind = "Console",
53 singular = "console",
54 plural = "consoles",
55 status = "ConsoleStatus",
56 printcolumn = r#"{"name": "ImageRef", "type": "string", "description": "Reference to the Docker image.", "jsonPath": ".spec.consoleImageRef", "priority": 1}"#,
57 printcolumn = r#"{"name": "Ready", "type": "string", "description": "Whether the deployment is ready", "jsonPath": ".status.conditions[?(@.type==\"Ready\")].status", "priority": 1}"#
58 )]
59 pub struct ConsoleSpec {
60 pub console_image_ref: String,
62 pub resource_requirements: Option<ResourceRequirements>,
64 pub replicas: Option<i32>,
66 pub external_certificate_spec: Option<MaterializeCertSpec>,
70 pub pod_annotations: Option<BTreeMap<String, String>>,
72 pub pod_labels: Option<BTreeMap<String, String>>,
74
75 pub balancerd: BalancerdRef,
77 #[serde(default)]
79 pub authenticator_kind: AuthenticatorKind,
80
81 pub resource_id: Option<String>,
83 }
84
85 impl Console {
86 pub fn name_prefixed(&self, suffix: &str) -> String {
87 format!("mz{}-{}", self.resource_id(), suffix)
88 }
89
90 pub fn resource_id(&self) -> &str {
91 &self.status.as_ref().unwrap().resource_id
92 }
93
94 pub fn deployment_name(&self) -> String {
95 self.name_prefixed("console")
96 }
97
98 pub fn replicas(&self) -> i32 {
99 self.spec.replicas.unwrap_or(2)
100 }
101
102 pub fn app_name(&self) -> String {
103 "console".to_owned()
104 }
105
106 pub fn service_name(&self) -> String {
107 self.name_prefixed("console")
108 }
109
110 pub fn configmap_name(&self) -> String {
111 self.name_prefixed("console")
112 }
113
114 pub fn external_certificate_name(&self) -> String {
115 self.name_prefixed("console-external")
116 }
117
118 pub fn external_certificate_secret_name(&self) -> String {
119 self.name_prefixed("console-external-tls")
120 }
121
122 pub fn status(&self) -> ConsoleStatus {
123 self.status.clone().unwrap_or_else(|| ConsoleStatus {
124 resource_id: self
125 .spec
126 .resource_id
127 .clone()
128 .unwrap_or_else(new_resource_id),
129 conditions: vec![],
130 })
131 }
132 }
133
134 #[derive(Clone, Debug, Default, Deserialize, Serialize, JsonSchema, PartialEq)]
135 #[serde(rename_all = "camelCase")]
136 pub struct ConsoleStatus {
137 pub resource_id: String,
139
140 pub conditions: Vec<Condition>,
141 }
142
143 impl ManagedResource for Console {
144 fn default_labels(&self) -> BTreeMap<String, String> {
145 BTreeMap::from_iter([
146 (
147 "materialize.cloud/mz-resource-id".to_owned(),
148 self.resource_id().to_owned(),
149 ),
150 ("materialize.cloud/app".to_owned(), "console".to_owned()),
151 ])
152 }
153 }
154}