Skip to content

Commit 1eb8f15

Browse files
chore: Handle secrets on spec (#47)
1 parent ba679c0 commit 1eb8f15

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

bootstrap/crds/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,18 @@ resource "kubernetes_manifest" "customresourcedefinition_dbsyncports_demeter_run
5353
"network" = {
5454
"type" = "string"
5555
}
56+
"password" = {
57+
"nullable" = true
58+
"type" = "string"
59+
}
5660
"throughputTier" = {
5761
"nullable" = true
5862
"type" = "string"
5963
}
64+
"username" = {
65+
"nullable" = true
66+
"type" = "string"
67+
}
6068
}
6169
"required" = [
6270
"network",

operator/src/controller.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,27 @@ pub static DB_SYNC_PORT_FINALIZER: &str = "dbsyncports.demeter.run";
4242
pub struct DbSyncPortSpec {
4343
pub network: String,
4444
pub throughput_tier: Option<String>,
45+
pub username: Option<String>,
46+
pub password: Option<String>,
4547
}
4648
#[derive(Deserialize, Serialize, Clone, Debug, JsonSchema)]
4749
pub struct DbSyncPortStatus {
4850
pub username: String,
4951
pub password: String,
5052
}
5153
impl DbSyncPortStatus {
52-
pub async fn try_new(name: &str, ns: &str) -> Result<Self, Error> {
53-
let username = gen_username_hash(&format!("{name}.{ns}")).await?;
54-
let password = Alphanumeric.sample_string(&mut rand::thread_rng(), 16);
54+
pub async fn try_new(port: &DbSyncPort) -> Result<Self, Error> {
55+
let ns = port.namespace().unwrap();
56+
let name = port.name_any();
57+
58+
let username = match &port.spec.username {
59+
Some(username) => username.clone(),
60+
None => gen_username_hash(&format!("{name}.{ns}")).await?,
61+
};
62+
let password = match &port.spec.password {
63+
Some(password) => password.clone(),
64+
None => Alphanumeric.sample_string(&mut rand::thread_rng(), 16),
65+
};
5566

5667
Ok(Self { username, password })
5768
}
@@ -71,7 +82,7 @@ impl DbSyncPort {
7182
let status = self
7283
.status
7384
.clone()
74-
.unwrap_or(DbSyncPortStatus::try_new(&name, &ns).await?);
85+
.unwrap_or(DbSyncPortStatus::try_new(self).await?);
7586

7687
if self.status.is_none() {
7788
let payload = json!({ "status": status });

0 commit comments

Comments
 (0)